partey_workadventure/front/src/iframe_api.ts

34 lines
824 B
TypeScript
Raw Normal View History

import {ChatEvent} from "./Api/Events/ChatEvent";
interface WorkAdventureApi {
sendChatMessage(message: string, author: string): void;
onChatMessage(callback: (message: string) => void): void;
}
declare global {
// eslint-disable-next-line no-var
var WA: WorkAdventureApi
}
window.WA = {
/**
* Send a message in the chat.
* Only the local user will receive this message.
*/
sendChatMessage(message: string, author: string) {
window.parent.postMessage({
'type': 'chat',
'data': {
'message': message,
'author': author
} as ChatEvent
}, '*');
},
/**
* Listen to messages sent by the local user, in the chat.
*/
onChatMessage(callback: (message: string) => void): void {
}
}