inf3cti0n95 / Rocket.Chat.RealTime.API.RxJS

Abstraction for Utilizing Rocket.Chat's Realtime API Methods with RxJS
MIT License
38 stars 23 forks source link

obj is undefined error showing on login subscribe #21

Closed iruthaya closed 6 years ago

iruthaya commented 6 years ago

I am using the Rocket.Chat.RealTime.API.RxJS to integrating with my existing ionic (3.7) mobile application. my application requirement is Rocket.chat direct message only.

Server Setup Information:

Version of Rocket.Chat Server: 0.59.1
Operating System: Ubuntu 14.04.5 LTS
Deployment Method: Docker

My sample Code


import { Component } from '@angular/core';
import { IonicPage, LoadingController, ToastController, MenuController, Platform } from 'ionic-angular';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { LoginServices } from '../../services/loginservices';
import { Storage } from '@ionic/storage';
import { Events } from 'ionic-angular';
import { Network } from '@ionic-native/network';
import { RealTimeAPI } from "rocket.chat.realtime.api.rxjs";

@IonicPage()
@Component({
  selector: 'page-login',
  templateUrl: 'login.html',
})
export class LoginPage {

  loginData = { UserName: '', Password: '', RememberMe: false };
  data: any;
  loginForm: FormGroup;
  isConnectionExists: boolean = true;
  constructor(public authService: LoginServices, public loadingCtrl: LoadingController, private toastCtrl: ToastController, public fb: FormBuilder, public menuCtrl: MenuController, public storage: Storage, public events: Events, public platform: Platform, public network: Network) {

  }

  doLogin() {

    if (this.loginForm.dirty && this.loginForm.valid) {

        this.showLoader();

        const realTimeAPI =  new RealTimeAPI("ws://mydomain:3001/websocket");
        realTimeAPI.keepAlive(); 
        const auth = realTimeAPI.login(loginData.UserName, loginData.Password);
        auth.subscribe(
          (data) => console.log(data),
          (err) => console.log(err),
          () => console.log('completed'));

    }
  }

}

Screenshot of my console

image

Please any one help me on this.

inf3cti0n95 commented 6 years ago

@iruthaya The Screenshot is hard to read, can you Copy the Log and post it.

iruthaya commented 6 years ago

i'm forget to call realTimeAPI.connectToServer() before calling realTimeAPI.keepAlive(). After adding this function it's working perfect..