bfcdd31ed2
The generation was broken due to the refactoring in several classes (some of them where not properly exported). Also, trying to generate the NPM package on every build now (to detect issues).
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
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<string>();
|
|
|
|
export class WorkadventureChatCommands extends IframeApiContribution<WorkadventureChatCommands> {
|
|
callbacks = [
|
|
apiCallback({
|
|
callback: (event: UserInputChatEvent) => {
|
|
chatStream.next(event.message);
|
|
},
|
|
type: "userInputChat",
|
|
typeChecker: isUserInputChatEvent,
|
|
}),
|
|
];
|
|
|
|
sendChatMessage(message: string, author: string) {
|
|
sendToWorkadventure({
|
|
type: "chat",
|
|
data: {
|
|
message: message,
|
|
author: author,
|
|
},
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Listen to messages sent by the local user, in the chat.
|
|
*/
|
|
onChatMessage(callback: (message: string) => void) {
|
|
chatStream.subscribe(callback);
|
|
}
|
|
}
|
|
|
|
export default new WorkadventureChatCommands();
|