finish mailbox
This commit is contained in:
@@ -115,7 +115,6 @@ export function sendMessage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function requestMailbox() {
|
export function requestMailbox() {
|
||||||
deleteMailbox();
|
|
||||||
UDN.requestMailbox();
|
UDN.requestMailbox();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,20 +29,13 @@ export class Mailbox implements Subscriber {
|
|||||||
return this.expiryDate < today;
|
return this.expiryDate < today;
|
||||||
}
|
}
|
||||||
|
|
||||||
// init
|
// manage
|
||||||
constructor(ws: WS) {
|
constructor(ws: WS) {
|
||||||
this.ws = ws;
|
|
||||||
this.sendId();
|
|
||||||
}
|
|
||||||
|
|
||||||
sendId(): void {
|
|
||||||
if (!this.ws) return;
|
|
||||||
|
|
||||||
sendWebSocketMessage(
|
sendWebSocketMessage(
|
||||||
{
|
{
|
||||||
assignedMailboxId: this.id,
|
assignedMailboxId: this.id,
|
||||||
},
|
},
|
||||||
this.ws
|
ws
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,6 +50,12 @@ export class Mailbox implements Subscriber {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete(): void {
|
||||||
|
subscriptionMap.deleteSubscriber(this);
|
||||||
|
if (!this.ws) return;
|
||||||
|
sendWebSocketMessage({ deletedMailbox: this.id }, this.ws);
|
||||||
|
}
|
||||||
|
|
||||||
// storage
|
// storage
|
||||||
messages = new Set<string>();
|
messages = new Set<string>();
|
||||||
|
|
||||||
|
|||||||
@@ -24,11 +24,12 @@ export interface WebSocketMessage {
|
|||||||
deletingMailbox?: string;
|
deletingMailbox?: string;
|
||||||
assignedMailboxId?: string; // sent by server
|
assignedMailboxId?: string; // sent by server
|
||||||
connectedMailboxId?: string; // sent by server
|
connectedMailboxId?: string; // sent by server
|
||||||
|
deletedMailbox?: string; // sent by server
|
||||||
|
|
||||||
// subscribing to channel
|
// subscribing to channel
|
||||||
subscribeChannel?: string;
|
subscribeChannel?: string;
|
||||||
unsubscribeChannel?: string;
|
unsubscribeChannel?: string;
|
||||||
subscribed?: boolean; // sent by server to confirm subscription
|
subscribed?: boolean; // sent by server
|
||||||
|
|
||||||
//sending message
|
//sending message
|
||||||
messageChannel?: string;
|
messageChannel?: string;
|
||||||
@@ -195,7 +196,6 @@ export function processMessage(
|
|||||||
const mailbox = mailboxes.get(deletingMailbox);
|
const mailbox = mailboxes.get(deletingMailbox);
|
||||||
if (!mailbox) return;
|
if (!mailbox) return;
|
||||||
removeMailbox(mailbox);
|
removeMailbox(mailbox);
|
||||||
ws.close();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// OTHER SERVER
|
// OTHER SERVER
|
||||||
@@ -215,7 +215,7 @@ export function removeExpiredMailboxes() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function removeMailbox(mailbox: Mailbox) {
|
export function removeMailbox(mailbox: Mailbox) {
|
||||||
subscriptionMap.deleteSubscriber(mailbox);
|
mailbox.delete();
|
||||||
mailboxes.delete(mailbox.id);
|
mailboxes.delete(mailbox.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user