1.0.1
This commit is contained in:
+14
-7
@@ -1,4 +1,6 @@
|
||||
export interface Message {
|
||||
uuid?: string; // to be assigned by
|
||||
|
||||
// connecting to server
|
||||
requestingServerConnection?: boolean;
|
||||
|
||||
@@ -15,21 +17,24 @@ export interface Message {
|
||||
unsubscribeChannel?: string;
|
||||
subscribed?: boolean; // sent by server
|
||||
|
||||
//sending message
|
||||
// sending message
|
||||
messageChannel?: string;
|
||||
messageBody?: string;
|
||||
|
||||
// confirming message
|
||||
confirmingMessageReceived?: boolean;
|
||||
}
|
||||
|
||||
export default class UDNFrontend {
|
||||
ws: WebSocket | undefined;
|
||||
|
||||
// HANDLERS
|
||||
private connectionHandler = () => {};
|
||||
private disconnectionHandler = () => {};
|
||||
private messageHandler = (data: Message) => {};
|
||||
private mailboxHandler = (mailboxId: string) => {};
|
||||
private mailboxConnectionHandler = (mailboxId: string) => {};
|
||||
private mailboxDeleteHandler = (mailboxId: string) => {};
|
||||
private connectionHandler = () => { };
|
||||
private disconnectionHandler = () => { };
|
||||
private messageHandler = (data: Message) => { };
|
||||
private mailboxHandler = (mailboxId: string) => { };
|
||||
private mailboxConnectionHandler = (mailboxId: string) => { };
|
||||
private mailboxDeleteHandler = (mailboxId: string) => { };
|
||||
|
||||
// INIT
|
||||
set onconnect(handler: () => void) {
|
||||
@@ -54,6 +59,7 @@ export default class UDNFrontend {
|
||||
// UTILITY METHODS
|
||||
private send(messageObject: Message): boolean {
|
||||
if (this.ws == undefined) return false;
|
||||
if (this.ws.readyState != 1) return false;
|
||||
|
||||
const messageString = JSON.stringify(messageObject);
|
||||
this.ws.send(messageString);
|
||||
@@ -80,6 +86,7 @@ export default class UDNFrontend {
|
||||
} else if (data.deletedMailbox) {
|
||||
return this.mailboxDeleteHandler(data.deletedMailbox);
|
||||
} else {
|
||||
this.send({ uuid: data.uuid, confirmingMessageReceived: true });
|
||||
this.messageHandler(data);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user