Adding strong checks on messages exchanged using generic-type-guard
This commit is contained in:
parent
83fa23a82d
commit
5178dff108
5 changed files with 39 additions and 14 deletions
|
@ -1,13 +1,18 @@
|
|||
import {ChatEvent} from "./Api/Events/ChatEvent";
|
||||
|
||||
interface WorkAdventureApi {
|
||||
sendChatMessage(message: string, author: string): void;
|
||||
onChatMessage(callback: (message: string) => void): void;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-var
|
||||
declare var WA: WorkAdventureApi;
|
||||
declare global {
|
||||
// eslint-disable-next-line no-var
|
||||
var WA: WorkAdventureApi
|
||||
}
|
||||
|
||||
window.WA = {
|
||||
/**
|
||||
* Sends a message in the chat.
|
||||
* Send a message in the chat.
|
||||
* Only the local user will receive this message.
|
||||
*/
|
||||
sendChatMessage(message: string, author: string) {
|
||||
|
@ -16,7 +21,13 @@ window.WA = {
|
|||
'data': {
|
||||
'message': message,
|
||||
'author': author
|
||||
}
|
||||
} as ChatEvent
|
||||
}, '*');
|
||||
},
|
||||
/**
|
||||
* Listen to messages sent by the local user, in the chat.
|
||||
*/
|
||||
onChatMessage(callback: (message: string) => void): void {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue