mean-expert-official / loopback-component-realtime

The LoopBack Component that turns this great framework into a powerful real-time platform
MIT License
30 stars 17 forks source link

WebSockets get disconnected after a few seconds #44

Open bargenson opened 7 years ago

bargenson commented 7 years ago

I'm currently testing the RealTime API and for now it's really nice.

I juste have an issue on which I already spent too much time:

Here is my code:

import { Injectable } from '@angular/core';
import { RealTime } from '../shared/sdk/services/core/real.time';
import { Todo } from '../shared/sdk/models/Todo';
import { FireLoopRef } from '../shared/sdk/models/FireLoopRef';
import { Observable } from 'rxjs/Observable';
import { TodoApi } from '../shared/sdk/services/custom/Todo';

@Injectable()
export class TodoService {

  constructor(
    private realTime: RealTime,
    private todoApi: TodoApi
  ) { }

  createTodo(todo: Todo): Observable<Todo> {
    return this.todoApi.create(todo);
  }

  getTodos(): Observable<Todo> {
    return this.realTime
      .onReady()
      .map(() => this.realTime.FireLoop.ref<Todo>(Todo))
      .switchMap((reference) => reference.on('change'));
  }

  removeTodo(todo: Todo) {
    return this.todoApi.deleteById(todo.id);
  }

}

Is there something wrong in my code, is there something I didn't correctly understand or is there an issue with the RealTime API ?

Thank you !

jonathan-casarrubias commented 7 years ago

@bargenson thanks for reaching out,

Hey so... Do you have the auth enabled within the real-time component?

You can try verifying the following link also, it seems you have authentication issues.

https://github.com/mean-expert-official/fireloop.io/wiki/Authentication