我是使用带有 Loopback 的 nodejs 的新手。我的办公室工作是创建实时聊天应用程序。我的老板建议我使用 fireloop.io,我总是从http://docs.fireloop.io/en/api/阅读文档并成功实现。但问题是创建私人聊天室。我也遵循文档上“使用子引用”的指示,但是在我发送消息后,消息会广播到连接到服务器的所有客户端。我的代码与文档相同:
import { Component } from '@angular/core';
import { RealTime } from './shared/sdk/services';
import { Room, Message, FireLoopRef } from './shared/sdk/models';
@Component(...)
export class AppComponent {
private RoomReference: FireLoopRef<Room>;
private MessageReference: FireLoopRef<Message>;
private room: Room = new Room({ name: 'FireLoop Room' });
private message: Room = new Message({ text: 'Test Message' });
constructor(private realTime: RealTime) {
this.realTime
.onReady()
.subscribe(() =>
this.RoomReference = this.realTime.FireLoop.ref<Room>(Room)
this.RoomReference.upsert(this.room).subscribe((instance: Room) => {
// Create a Child Reference
this.MessageReference = RoomReference.make(instance).child<Message>('messages');
this.MessageReference.on('value').subscribe(
(messages: Array<Message>) => this.logger.info(messages)
);
MessageReference.upsert(this.message).subscribe((res: Message) => console.log(res.text));
}))
);
}
}
对不起我的语言。谢谢