|
1 | 1 | import WebSocket from 'isomorphic-ws';
|
2 | 2 | import HttpStatusCode from './statusCodes';
|
3 | 3 | // import { MessageStore } from './messageStore';
|
4 |
| -import crypto from 'crypto'; |
5 | 4 | import EventEmitter from 'events';
|
6 | 5 | import { AllowedType, DataMapping, JsonObject, Serialize } from './utils';
|
7 | 6 | import { SoxtendServer } from '.';
|
8 |
| -import { GROUPS_BY_CONNECTION_ID, SERVERS_HAVING_GROUP } from './constants'; |
9 | 7 | import { nanoid } from 'nanoid';
|
10 | 8 | export type ClientResponse = {
|
11 | 9 | _id: number;
|
@@ -83,37 +81,27 @@ export class Socket<DataSentOverWire extends AllowedType = 'string'> extends Eve
|
83 | 81 |
|
84 | 82 | public async joinGroup(groupId: string) {
|
85 | 83 | this.server.socketGroupStore.add(this, groupId);
|
86 |
| - return Promise.all([ |
87 |
| - this.server.distributor.addListItem(`${GROUPS_BY_CONNECTION_ID}${this.id}`, groupId), |
88 |
| - this.server.distributor.addListItem(`${SERVERS_HAVING_GROUP}${groupId}`, this.server.id), |
89 |
| - ]); |
90 | 84 | }
|
91 | 85 |
|
92 | 86 | async joinGroups(groupdIds: Iterable<string>) {
|
93 | 87 | for (let groupId of groupdIds) {
|
94 | 88 | this.server.socketGroupStore.add(this, groupId);
|
95 |
| - this.server.distributor.addListItem(`${SERVERS_HAVING_GROUP}${groupId}`, this.server.id); |
96 | 89 | }
|
97 |
| - this.server.distributor.addListItems(`${GROUPS_BY_CONNECTION_ID}${this.id}`, groupdIds); |
98 | 90 | }
|
99 | 91 | async leaveGroup(groupId: string) {
|
100 | 92 | this.server.socketGroupStore.remove(this, groupId);
|
101 |
| - |
102 |
| - return this.server.distributor.removeListItem(`${GROUPS_BY_CONNECTION_ID}${this.id}`, groupId); |
103 | 93 | }
|
104 | 94 | async leaveAllGroups() {
|
105 |
| - const groups = await this.server.distributor.getListItems(`${GROUPS_BY_CONNECTION_ID}${this.id}`); |
| 95 | + const groups = this.server.socketGroupStore.myGroups.get(this.id); |
| 96 | + if (!groups) return; |
106 | 97 | return this.leaveGroups(groups);
|
107 | 98 | }
|
108 |
| - async leaveGroups(groups: string[]) { |
109 |
| - if (!groups.length) return; |
| 99 | + async leaveGroups(groups: Set<string | number>) { |
110 | 100 | for (let group of groups) {
|
111 | 101 | this.server.socketGroupStore.remove(this, group);
|
112 | 102 | }
|
113 |
| - |
114 |
| - return Promise.all([this.server.distributor.removeListItems(`${GROUPS_BY_CONNECTION_ID}${this.id}`, groups)]); |
115 | 103 | }
|
116 |
| - async getAllGroups(socketId?: string) { |
117 |
| - return this.server.distributor.getListItems(`${GROUPS_BY_CONNECTION_ID}${socketId || this.id}`); |
| 104 | + async getAllGroups() { |
| 105 | + return this.server.socketGroupStore.myGroups.get(this.id); |
118 | 106 | }
|
119 | 107 | }
|
0 commit comments