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