implement connection handlers

This commit is contained in:
marlon-erler
2024-07-19 18:17:00 +02:00
parent f1fd6f55f8
commit 9e74d0227a
3 changed files with 93 additions and 34 deletions
+20 -6
View File
@@ -37,13 +37,27 @@ export default class ConnectionModel {
return this.udn.sendMessage(chatMessage.channel, stringifiedBody);
};
handleMessage = (data: Message) => {};
// setup
constructor() {
constructor(configuration: ConnectionModelConfiguration) {
// create frontend
this.udn = new UDNFrontend();
this.udn.onmessage = this.handleMessage;
this.udn.onconnect = this.handleConnectionChange;
this.udn.ondisconnect = this.handleConnectionChange;
// setup handlers
this.udn.onmessage = (data: Message) => {
configuration.messageHandler(data);
};
this.udn.onconnect = () => {
this.handleConnectionChange();
configuration.connectionChangeHandler();
};
this.udn.ondisconnect = () => {
this.handleConnectionChange();
configuration.connectionChangeHandler();
};
}
}
export interface ConnectionModelConfiguration {
connectionChangeHandler: () => void;
messageHandler: (data: Message) => void;
}