add connection status log, move to arrow functions

This commit is contained in:
marlon-erler
2024-07-19 18:02:23 +02:00
parent 1a58b01d62
commit f1fd6f55f8
2 changed files with 27 additions and 22 deletions
+14 -12
View File
@@ -257,30 +257,32 @@
get isConnected() {
return this.udn.ws != void 0 && this.udn.ws.readyState == 1;
}
get url() {
get address() {
return this.udn.ws?.url;
}
// connection
connect(address2) {
connect = (address2) => {
this.udn.connect(address2);
}
disconnect() {
};
disconnect = () => {
this.udn.disconnect();
}
handleDisconnect() {
}
};
handleConnectionChange = () => {
console.log("connection status:", this.isConnected, this.address);
};
// messaging
sendChatMessage(chatMessage) {
sendChatMessage = (chatMessage) => {
const stringifiedBody = stringify(chatMessage);
return this.udn.sendMessage(chatMessage.channel, stringifiedBody);
}
handleMessage(data) {
}
};
handleMessage = (data) => {
};
// setup
constructor() {
this.udn = new UDNFrontend();
this.udn.onmessage = this.handleMessage;
this.udn.ondisconnect = this.handleDisconnect;
this.udn.onconnect = this.handleConnectionChange;
this.udn.ondisconnect = this.handleConnectionChange;
}
};
+13 -10
View File
@@ -14,33 +14,36 @@ export default class ConnectionModel {
return this.udn.ws != undefined && this.udn.ws.readyState == 1;
}
get url(): string | undefined {
get address(): string | undefined {
return this.udn.ws?.url;
}
// connection
connect(address: string): void {
connect = (address: string): void => {
this.udn.connect(address);
}
};
disconnect(): void {
disconnect = (): void => {
this.udn.disconnect();
}
};
handleDisconnect() {}
handleConnectionChange = () => {
console.log("connection status:", this.isConnected, this.address);
};
// messaging
sendChatMessage(chatMessage: ChatMessage): boolean {
sendChatMessage = (chatMessage: ChatMessage): boolean => {
const stringifiedBody = stringify(chatMessage);
return this.udn.sendMessage(chatMessage.channel, stringifiedBody);
}
};
handleMessage(data: Message) {}
handleMessage = (data: Message) => {};
// setup
constructor() {
this.udn = new UDNFrontend();
this.udn.onmessage = this.handleMessage;
this.udn.ondisconnect = this.handleDisconnect;
this.udn.onconnect = this.handleConnectionChange;
this.udn.ondisconnect = this.handleConnectionChange;
}
}