Search code examples
angularwatchspring-websocketstomp

Angular: RxStomp .Watch .Subsribe Method


I can't figure out how to use the watch method in RxStomp.

subscribeToOtherAccount(otherAccount): string {
    const channelId = ChannelService.createChannel(this.username, otherAccount.username);

    this.rxStompService.watch('/channel/chat/' + channelId).subscribe((message: Message) => {
        this.messageService.pushMessage(message);
    })
    return channelId
}

I get this error:

TS2769: No overload matches this call.    Overload 1 of 5, '(observer?: PartialObserver): Subscription', gave the following error. Argument of type '(message: Message) => void' is not assignable to parameter of type 'PartialObserver'. Property 'complete' is missing in type '(message: Message) => void' but required in type 'CompletionObserver'. Overload 2 of 5, '(next?: (value: IMessage) => void, error?: (error: any) => void, complete?: () => void): Subscription', gave the following error. Argument of type '(message: Message) => void' is not assignable to parameter of type '(value: IMessage) => void'. Types of parameters 'message' and 'value' are incompatible. Type 'IMessage' is missing the following properties from type 'Message': channel, sender, content types.d.ts(64, 5): 'complete' is declared here.

Can anyone maybe give me a tip or a link to an Example?


Solution

  •  subscribeToOtherAccount(otherAccount): string {
     const channelId = ChannelService.createChannel(this.username, otherAccount.username);
        this.rxStompService.watch(`/channel/chat/${channelId}`).subscribe(res => {
          const data: Message = JSON.parse(res.body);
          this.messageService.pushMessage(data);
    })
     return channelId;
    }