Refactoring WorkAdventureAPI.
Simplifying a lot what was done (even if the new code is a bit less automated, it allows to list exactly the methods we want to see deprecated and to add a notification message)
This commit is contained in:
parent
97e6ad6700
commit
34dc5a0bc6
13 changed files with 186 additions and 153 deletions
36
front/src/Api/iframe/chat.ts
Normal file
36
front/src/Api/iframe/chat.ts
Normal file
|
@ -0,0 +1,36 @@
|
|||
import type { ChatEvent } from '../Events/ChatEvent'
|
||||
import { isUserInputChatEvent, UserInputChatEvent } from '../Events/UserInputChatEvent'
|
||||
import { apiCallback, IframeApiContribution, sendToWorkadventure } from './IframeApiContribution'
|
||||
|
||||
|
||||
class WorkadventureChatCommands extends IframeApiContribution<WorkadventureChatCommands> {
|
||||
chatMessageCallback?: (event: string) => void
|
||||
|
||||
callbacks = [apiCallback({
|
||||
callback: (event: UserInputChatEvent) => {
|
||||
this.chatMessageCallback?.(event.message)
|
||||
},
|
||||
type: "userInputChat",
|
||||
typeChecker: isUserInputChatEvent
|
||||
})]
|
||||
|
||||
|
||||
sendChatMessage(message: string, author: string) {
|
||||
sendToWorkadventure({
|
||||
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) {
|
||||
this.chatMessageCallback = callback
|
||||
}
|
||||
}
|
||||
|
||||
export default new WorkadventureChatCommands()
|
Loading…
Add table
Add a link
Reference in a new issue