From 6101548d891710d0f617dd6268301c0cdb8541c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Mon, 21 Jun 2021 13:47:07 +0200 Subject: [PATCH] Fixing bug where only one chat listener can be added. --- front/src/Api/iframe/chat.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/front/src/Api/iframe/chat.ts b/front/src/Api/iframe/chat.ts index 0d467c2c..5f73b744 100644 --- a/front/src/Api/iframe/chat.ts +++ b/front/src/Api/iframe/chat.ts @@ -2,13 +2,15 @@ import type { ChatEvent } from '../Events/ChatEvent' import { isUserInputChatEvent, UserInputChatEvent } from '../Events/UserInputChatEvent' import { IframeApiContribution, sendToWorkadventure } from './IframeApiContribution' import { apiCallback } from "./registeredCallbacks"; +import {Subject} from "rxjs"; + +const chatStream = new Subject(); class WorkadventureChatCommands extends IframeApiContribution { - chatMessageCallback?: (event: string) => void callbacks = [apiCallback({ callback: (event: UserInputChatEvent) => { - this.chatMessageCallback?.(event.message) + chatStream.next(event.message); }, type: "userInputChat", typeChecker: isUserInputChatEvent @@ -29,7 +31,7 @@ class WorkadventureChatCommands extends IframeApiContribution void) { - this.chatMessageCallback = callback + chatStream.subscribe(callback); } }