@netless/forge-rtm 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/RTM_2_1.d.ts +29 -0
- package/dist/RTM_2_1.d.ts.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/rtm-provider.esm.js +232 -0
- package/dist/rtm-provider.esm.js.map +7 -0
- package/dist/rtm-provider.js +265 -0
- package/dist/rtm-provider.js.map +7 -0
- package/package.json +34 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { SocketProvider, SocketProviderEvent } from "@netless/forge-room";
|
|
2
|
+
import EventEmitter from "eventemitter3";
|
|
3
|
+
import { RTMClient } from "agora-rtm";
|
|
4
|
+
export type ChunkedUpdateMessageType = {
|
|
5
|
+
buf: Uint8Array;
|
|
6
|
+
index: number;
|
|
7
|
+
length: number;
|
|
8
|
+
session: string;
|
|
9
|
+
};
|
|
10
|
+
export declare class RTMProvider_2_1 extends EventEmitter<SocketProviderEvent> implements SocketProvider {
|
|
11
|
+
private rtmClient;
|
|
12
|
+
private roomId;
|
|
13
|
+
private userId;
|
|
14
|
+
private reconnectTimeout;
|
|
15
|
+
private chunkedMessages;
|
|
16
|
+
private cachedMessages;
|
|
17
|
+
private intervalId;
|
|
18
|
+
constructor(rtmClient: RTMClient);
|
|
19
|
+
private roomChannel;
|
|
20
|
+
private userChannel;
|
|
21
|
+
initialize(roomId: string, userId: string): Promise<void>;
|
|
22
|
+
private handleRtmMessage;
|
|
23
|
+
private handleStatus;
|
|
24
|
+
private handlePresence;
|
|
25
|
+
private receiveChunkMessage;
|
|
26
|
+
publish(buf: Uint8Array, customType: string, target?: string): void;
|
|
27
|
+
userList(): Promise<Set<string>>;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=RTM_2_1.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RTM_2_1.d.ts","sourceRoot":"","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|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
// src/RTM_2_1.ts
|
|
2
|
+
import { log } from "@netless/forge-room";
|
|
3
|
+
import EventEmitter from "eventemitter3";
|
|
4
|
+
import { v4 as uuidv4 } from "uuid";
|
|
5
|
+
var cyrb53 = (str, seed = 0) => {
|
|
6
|
+
let h1 = 3735928559 ^ seed, h2 = 1103547991 ^ seed;
|
|
7
|
+
for (let i = 0, ch; i < str.length; i++) {
|
|
8
|
+
ch = str.charCodeAt(i);
|
|
9
|
+
h1 = Math.imul(h1 ^ ch, 2654435761);
|
|
10
|
+
h2 = Math.imul(h2 ^ ch, 1597334677);
|
|
11
|
+
}
|
|
12
|
+
h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507);
|
|
13
|
+
h1 ^= Math.imul(h2 ^ h2 >>> 13, 3266489909);
|
|
14
|
+
h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507);
|
|
15
|
+
h2 ^= Math.imul(h1 ^ h1 >>> 13, 3266489909);
|
|
16
|
+
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
|
|
17
|
+
};
|
|
18
|
+
var ChunkedUpdateMessage = class _ChunkedUpdateMessage {
|
|
19
|
+
static fromObject(obj, target, customType) {
|
|
20
|
+
const msg = new _ChunkedUpdateMessage();
|
|
21
|
+
msg.target = target;
|
|
22
|
+
msg.customType = customType;
|
|
23
|
+
const encoder = new TextEncoder();
|
|
24
|
+
const sessionBuf = encoder.encode(obj.session);
|
|
25
|
+
msg.header = new DataView(new Uint8Array(10).buffer);
|
|
26
|
+
msg.header.setUint32(0, obj.buf.length, false);
|
|
27
|
+
msg.header.setUint32(4, sessionBuf.length, false);
|
|
28
|
+
msg.header.setUint8(8, obj.index);
|
|
29
|
+
msg.header.setUint8(9, obj.length);
|
|
30
|
+
msg.buffer = new Uint8Array(
|
|
31
|
+
obj.buf.length + sessionBuf.length + msg.header.buffer.byteLength
|
|
32
|
+
);
|
|
33
|
+
let len = 0;
|
|
34
|
+
msg.buffer.set(new Uint8Array(msg.header.buffer), len);
|
|
35
|
+
len += msg.header.buffer.byteLength;
|
|
36
|
+
msg.buffer.set(obj.buf, len);
|
|
37
|
+
len += obj.buf.length;
|
|
38
|
+
msg.buffer.set(sessionBuf, len);
|
|
39
|
+
return msg;
|
|
40
|
+
}
|
|
41
|
+
static fromBuffer(buf, target, customType) {
|
|
42
|
+
const msg = new _ChunkedUpdateMessage();
|
|
43
|
+
msg.header = new DataView(buf.slice(0, 10).buffer);
|
|
44
|
+
msg.buffer = buf.slice(10);
|
|
45
|
+
msg.target = target;
|
|
46
|
+
msg.customType = customType;
|
|
47
|
+
return msg;
|
|
48
|
+
}
|
|
49
|
+
target;
|
|
50
|
+
customType;
|
|
51
|
+
buffer;
|
|
52
|
+
header;
|
|
53
|
+
get buf() {
|
|
54
|
+
const len = this.header.getInt32(0);
|
|
55
|
+
return this.buffer.slice(0, len);
|
|
56
|
+
}
|
|
57
|
+
get index() {
|
|
58
|
+
return this.header.getUint8(8);
|
|
59
|
+
}
|
|
60
|
+
get length() {
|
|
61
|
+
return this.header.getUint8(9);
|
|
62
|
+
}
|
|
63
|
+
get session() {
|
|
64
|
+
const start = this.header.getInt32(0);
|
|
65
|
+
const sessionBuf = this.buffer.slice(start, start + this.header.getInt32(4));
|
|
66
|
+
const textDecoder = new TextDecoder();
|
|
67
|
+
return textDecoder.decode(sessionBuf);
|
|
68
|
+
}
|
|
69
|
+
constructor() {
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var RTMProvider_2_1 = class extends EventEmitter {
|
|
73
|
+
rtmClient;
|
|
74
|
+
roomId;
|
|
75
|
+
userId;
|
|
76
|
+
reconnectTimeout = null;
|
|
77
|
+
chunkedMessages = /* @__PURE__ */ new Map();
|
|
78
|
+
cachedMessages = [];
|
|
79
|
+
intervalId = null;
|
|
80
|
+
constructor(rtmClient) {
|
|
81
|
+
super();
|
|
82
|
+
this.rtmClient = rtmClient;
|
|
83
|
+
}
|
|
84
|
+
roomChannel() {
|
|
85
|
+
return `r_${this.roomId}`;
|
|
86
|
+
}
|
|
87
|
+
userChannel(userId) {
|
|
88
|
+
if (userId.length > 16) {
|
|
89
|
+
userId = `${cyrb53(userId)}`;
|
|
90
|
+
}
|
|
91
|
+
return `${this.roomChannel()}_u_${userId}`;
|
|
92
|
+
}
|
|
93
|
+
async initialize(roomId, userId) {
|
|
94
|
+
window.clearInterval(this.intervalId);
|
|
95
|
+
this.roomId = roomId;
|
|
96
|
+
this.userId = userId;
|
|
97
|
+
this.rtmClient.addEventListener("message", this.handleRtmMessage);
|
|
98
|
+
this.rtmClient.addEventListener("presence", this.handlePresence);
|
|
99
|
+
this.rtmClient.addEventListener("status", this.handleStatus);
|
|
100
|
+
try {
|
|
101
|
+
await this.rtmClient.subscribe(this.roomChannel());
|
|
102
|
+
await this.rtmClient.subscribe(this.userChannel(this.userId));
|
|
103
|
+
} catch (error) {
|
|
104
|
+
this.emit("error", `rtm subscribe fail, ${error}`);
|
|
105
|
+
log(`rtm subscribe fail`, {
|
|
106
|
+
error: error.toString()
|
|
107
|
+
}, "error");
|
|
108
|
+
}
|
|
109
|
+
this.intervalId = setInterval(() => {
|
|
110
|
+
const msg = this.cachedMessages.shift();
|
|
111
|
+
if (msg) {
|
|
112
|
+
const channel = msg.target ? this.userChannel(msg.target) : this.roomChannel();
|
|
113
|
+
this.rtmClient.publish(channel, msg.buffer, { customType: msg.customType }).catch((error) => {
|
|
114
|
+
log(`rtm publish failed`, {
|
|
115
|
+
channel,
|
|
116
|
+
code: error.code
|
|
117
|
+
}, "warning");
|
|
118
|
+
this.emit("error", `rtm publish fail, ${error}`);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}, 32);
|
|
122
|
+
}
|
|
123
|
+
handleRtmMessage = (evt) => {
|
|
124
|
+
this.receiveChunkMessage(ChunkedUpdateMessage.fromBuffer(evt.message, "", evt.customType), evt.publisher);
|
|
125
|
+
};
|
|
126
|
+
handleStatus = (connectionStatus) => {
|
|
127
|
+
log(`rtm status update`, {
|
|
128
|
+
state: connectionStatus.state,
|
|
129
|
+
reason: connectionStatus.reason
|
|
130
|
+
});
|
|
131
|
+
if (connectionStatus.state === "RECONNECTING" && this.reconnectTimeout === null) {
|
|
132
|
+
this.reconnectTimeout = window.setTimeout(() => {
|
|
133
|
+
this.emit("error", `reconnecting timeout`);
|
|
134
|
+
this.emit("connectionStatusChange", "DISCONNECTED");
|
|
135
|
+
}, 30 * 1e3);
|
|
136
|
+
} else if (connectionStatus.state === "CONNECTED") {
|
|
137
|
+
window.clearTimeout(this.reconnectTimeout);
|
|
138
|
+
this.emit("connectionStatusChange", "CONNECTED");
|
|
139
|
+
} else if (connectionStatus.state === "FAILED") {
|
|
140
|
+
window.clearTimeout(this.reconnectTimeout);
|
|
141
|
+
this.emit("error", `rtm connection failed, ${connectionStatus.reason}`);
|
|
142
|
+
this.emit("connectionStatusChange", "DISCONNECTED");
|
|
143
|
+
} else if (connectionStatus.state === "CONNECTING") {
|
|
144
|
+
this.emit("connectionStatusChange", "CONNECTING");
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
handlePresence = (evt) => {
|
|
148
|
+
if (evt.channelName === this.roomChannel()) {
|
|
149
|
+
if (evt.eventType === "REMOTE_JOIN") {
|
|
150
|
+
this.emit("userJoin", evt.publisher);
|
|
151
|
+
} else if (evt.eventType === "REMOTE_LEAVE") {
|
|
152
|
+
this.emit("userLeave", evt.publisher);
|
|
153
|
+
} else if (evt.eventType === "REMOTE_TIMEOUT") {
|
|
154
|
+
this.emit("userLeave", evt.publisher);
|
|
155
|
+
} else if (evt.eventType === "INTERVAL") {
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
receiveChunkMessage(msg, publisher) {
|
|
160
|
+
if (msg.length === 1) {
|
|
161
|
+
this.emit("message", msg.buf, publisher, msg.customType);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const chunks = this.chunkedMessages.get(msg.session) || [];
|
|
165
|
+
chunks.push(msg);
|
|
166
|
+
if (chunks.length === msg.length) {
|
|
167
|
+
const buffer = chunks.sort((a, b) => a.index - b.index).reduce((result, next) => {
|
|
168
|
+
const buf = next.buf;
|
|
169
|
+
const output = new Uint8Array(result.length + buf.length);
|
|
170
|
+
output.set(result, 0);
|
|
171
|
+
output.set(buf, result.length);
|
|
172
|
+
return output;
|
|
173
|
+
}, new Uint8Array());
|
|
174
|
+
this.emit("message", buffer, publisher, msg.customType);
|
|
175
|
+
this.chunkedMessages.delete(msg.session);
|
|
176
|
+
} else {
|
|
177
|
+
this.chunkedMessages.set(msg.session, chunks);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
publish(buf, customType, target = "") {
|
|
181
|
+
const session = uuidv4();
|
|
182
|
+
const size = buf.length * Uint8Array.BYTES_PER_ELEMENT / 1024;
|
|
183
|
+
if (size < 16) {
|
|
184
|
+
this.cachedMessages.push(ChunkedUpdateMessage.fromObject({
|
|
185
|
+
buf,
|
|
186
|
+
length: 1,
|
|
187
|
+
index: 0,
|
|
188
|
+
session
|
|
189
|
+
}, target, customType));
|
|
190
|
+
} else {
|
|
191
|
+
const chunkSize = 16 * 1024 / Uint8Array.BYTES_PER_ELEMENT;
|
|
192
|
+
let len = Math.ceil(size / 16);
|
|
193
|
+
let index = 0;
|
|
194
|
+
while (index < len) {
|
|
195
|
+
this.cachedMessages.push(ChunkedUpdateMessage.fromObject({
|
|
196
|
+
buf: buf.slice(index * chunkSize, (index + 1) * chunkSize),
|
|
197
|
+
length: len,
|
|
198
|
+
index,
|
|
199
|
+
session
|
|
200
|
+
}, target, customType));
|
|
201
|
+
index += 1;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
async userList() {
|
|
206
|
+
const output = /* @__PURE__ */ new Set();
|
|
207
|
+
const result = await this.rtmClient.presence.whoNow(this.roomChannel(), "MESSAGE", {
|
|
208
|
+
includedState: false
|
|
209
|
+
});
|
|
210
|
+
var nextPage = result.nextPage;
|
|
211
|
+
result.occupants.forEach((userInfo) => {
|
|
212
|
+
const { userId } = userInfo;
|
|
213
|
+
output.add(userId);
|
|
214
|
+
});
|
|
215
|
+
while (nextPage) {
|
|
216
|
+
const result2 = await this.rtmClient.presence.whoNow(this.roomChannel(), "MESSAGE", {
|
|
217
|
+
includedState: false,
|
|
218
|
+
page: nextPage
|
|
219
|
+
});
|
|
220
|
+
nextPage = result2.nextPage;
|
|
221
|
+
result2.occupants.forEach((userInfo) => {
|
|
222
|
+
const { userId } = userInfo;
|
|
223
|
+
output.add(userId);
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
return output;
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
export {
|
|
230
|
+
RTMProvider_2_1
|
|
231
|
+
};
|
|
232
|
+
//# sourceMappingURL=rtm-provider.esm.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/RTM_2_1.ts"],
|
|
4
|
+
"sourcesContent": ["import { SocketProvider, SocketProviderEvent, log } from \"@netless/forge-room\";\nimport EventEmitter from \"eventemitter3\";\nimport {v4 as uuidv4} from \"uuid\";\n\nimport {RTMClient, RTMEvents} from \"agora-rtm\";\n\nconst cyrb53 = (str: string, seed = 0) => {\n let h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed;\n for(let i = 0, ch; i < str.length; i++) {\n ch = str.charCodeAt(i);\n h1 = Math.imul(h1 ^ ch, 2654435761);\n h2 = Math.imul(h2 ^ ch, 1597334677);\n }\n h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507);\n h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909);\n h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507);\n h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909);\n\n return 4294967296 * (2097151 & h2) + (h1 >>> 0);\n};\n\nexport type ChunkedUpdateMessageType = {\n buf: Uint8Array;\n index: number;\n length: number;\n session: string;\n}\n\nclass ChunkedUpdateMessage {\n\n static fromObject(obj: ChunkedUpdateMessageType, target: string, customType: string): ChunkedUpdateMessage {\n const msg = new ChunkedUpdateMessage();\n msg.target = target;\n msg.customType = customType;\n\n const encoder = new TextEncoder();\n const sessionBuf = encoder.encode(obj.session);\n\n // header \u6309\u987A\u5E8F\u6307\u793A buf, session, target, customType \u90E8\u5206\u7684 uint8 \u957F\u5EA6\n msg.header = new DataView(new Uint8Array(10).buffer);\n\n msg.header.setUint32(0, obj.buf.length, false);\n msg.header.setUint32(4, sessionBuf.length, false);\n msg.header.setUint8(8, obj.index);\n msg.header.setUint8(9, obj.length);\n\n msg.buffer = new Uint8Array(\n obj.buf.length + sessionBuf.length + msg.header.buffer.byteLength\n );\n\n let len = 0;\n msg.buffer.set(new Uint8Array(msg.header.buffer), len);\n len += msg.header.buffer.byteLength;\n msg.buffer.set(obj.buf, len);\n len += obj.buf.length;\n msg.buffer.set(sessionBuf, len);\n\n return msg;\n }\n\n static fromBuffer(buf: Uint8Array, target: string, customType: string) {\n const msg = new ChunkedUpdateMessage();\n\n msg.header = new DataView(buf.slice(0, 10).buffer);\n msg.buffer = buf.slice(10);\n msg.target = target;\n msg.customType = customType;\n\n return msg;\n }\n\n public target!: string;\n public customType!: string;\n public buffer!: Uint8Array;\n private header!: DataView;\n\n public get buf(): Uint8Array {\n const len = this.header.getInt32(0);\n return this.buffer.slice(0, len);\n }\n\n public get index(): number {\n return this.header.getUint8(8);\n }\n\n public get length(): number {\n return this.header.getUint8(9);\n }\n\n public get session(): string {\n const start = this.header.getInt32(0);\n const sessionBuf = this.buffer.slice(start, start + this.header.getInt32(4));\n const textDecoder = new TextDecoder();\n return textDecoder.decode(sessionBuf);\n }\n\n private constructor() {}\n}\n\nexport class RTMProvider_2_1 extends EventEmitter<SocketProviderEvent> implements SocketProvider {\n\n private rtmClient!: RTMClient;\n private roomId!: string;\n private userId!: string;\n\n private reconnectTimeout: any = null;\n private chunkedMessages: Map<string, ChunkedUpdateMessage[]> = new Map();\n private cachedMessages: ChunkedUpdateMessage[] = [];\n\n private intervalId: any = null;\n\n public constructor(rtmClient: RTMClient) {\n super();\n this.rtmClient = rtmClient;\n }\n\n private roomChannel(): string {\n return `r_${this.roomId}`;\n }\n\n private userChannel(userId: string): string {\n if (userId.length > 16) {\n userId = `${cyrb53(userId)}`;\n }\n return `${this.roomChannel()}_u_${userId}`;\n }\n\n public async initialize(roomId: string, userId: string): Promise<void> {\n window.clearInterval(this.intervalId);\n this.roomId = roomId;\n this.userId = userId;\n this.rtmClient.addEventListener(\"message\", this.handleRtmMessage);\n this.rtmClient.addEventListener(\"presence\", this.handlePresence);\n // @ts-ignore\n this.rtmClient.addEventListener(\"status\", this.handleStatus);\n try {\n await this.rtmClient.subscribe(this.roomChannel());\n await this.rtmClient.subscribe(this.userChannel(this.userId));\n } catch(error: any) {\n this.emit(\"error\", `rtm subscribe fail, ${error}`);\n log(`rtm subscribe fail`, {\n error: error.toString(),\n }, \"error\");\n }\n this.intervalId = setInterval(() => {\n const msg = this.cachedMessages.shift();\n if (msg) {\n const channel = msg.target ? this.userChannel(msg.target) : this.roomChannel();\n this.rtmClient.publish(channel, msg.buffer, { customType: msg.customType }).catch(error => {\n log(`rtm publish failed`, {\n channel,\n code: error.code\n }, \"warning\");\n this.emit(\"error\", `rtm publish fail, ${error}`);\n });\n }\n }, 32);\n }\n\n private handleRtmMessage = (evt: RTMEvents.MessageEvent) => {\n this.receiveChunkMessage(ChunkedUpdateMessage.fromBuffer(evt.message as Uint8Array, \"\", evt.customType), evt.publisher);\n };\n\n private handleStatus = (connectionStatus: RTMEvents.RTMConnectionStatusChangeEvent) => {\n log(`rtm status update`, {\n state: connectionStatus.state,\n reason: connectionStatus.reason\n });\n if (connectionStatus.state === \"RECONNECTING\" && this.reconnectTimeout === null) {\n this.reconnectTimeout = window.setTimeout(() => {\n this.emit(\"error\", `reconnecting timeout`);\n this.emit(\"connectionStatusChange\", \"DISCONNECTED\");\n }, 30 * 1000);\n } else if (connectionStatus.state === \"CONNECTED\") {\n window.clearTimeout(this.reconnectTimeout);\n this.emit(\"connectionStatusChange\", \"CONNECTED\");\n } else if (connectionStatus.state === \"FAILED\") {\n window.clearTimeout(this.reconnectTimeout);\n this.emit(\"error\", `rtm connection failed, ${connectionStatus.reason}`);\n this.emit(\"connectionStatusChange\", \"DISCONNECTED\");\n } else if (connectionStatus.state === \"CONNECTING\") {\n this.emit(\"connectionStatusChange\", \"CONNECTING\");\n }\n }\n\n private handlePresence = (evt: RTMEvents.PresenceEvent) => {\n if (evt.channelName === this.roomChannel()) {\n if (evt.eventType === \"REMOTE_JOIN\") {\n this.emit(\"userJoin\", evt.publisher);\n } else if (evt.eventType === \"REMOTE_LEAVE\") {\n this.emit(\"userLeave\", evt.publisher);\n } else if (evt.eventType === \"REMOTE_TIMEOUT\") {\n this.emit(\"userLeave\", evt.publisher);\n } else if (evt.eventType === \"INTERVAL\") {\n // evt.interval.join.users\n }\n }\n };\n\n private receiveChunkMessage(msg: ChunkedUpdateMessage, publisher: string) {\n if (msg.length === 1) {\n this.emit(\"message\", msg.buf, publisher, msg.customType);\n return;\n }\n const chunks = this.chunkedMessages.get(msg.session) || [];\n chunks.push(msg);\n if (chunks.length === msg.length) {\n const buffer = chunks.sort((a, b) => a.index - b.index)\n .reduce((result, next) => {\n const buf = next.buf;\n const output = new Uint8Array(result.length + buf.length);\n output.set(result, 0);\n output.set(buf, result.length);\n return output;\n }, new Uint8Array());\n this.emit(\"message\", buffer, publisher, msg.customType);\n this.chunkedMessages.delete(msg.session);\n } else {\n this.chunkedMessages.set(msg.session, chunks);\n }\n }\n\n public publish(buf: Uint8Array, customType: string, target: string = \"\") {\n const session = uuidv4();\n // \u6D88\u606F\u5305\u4F53\u79EF, \u5355\u4F4D kb\n const size = buf.length * Uint8Array.BYTES_PER_ELEMENT / 1024;\n if (size < 16) {\n this.cachedMessages.push(ChunkedUpdateMessage.fromObject({\n buf: buf,\n length: 1,\n index: 0,\n session\n }, target, customType));\n } else {\n const chunkSize = 16 * 1024 / Uint8Array.BYTES_PER_ELEMENT;\n let len = Math.ceil(size / 16);\n let index = 0;\n while (index < len) {\n this.cachedMessages.push(ChunkedUpdateMessage.fromObject({\n buf: buf.slice(index * chunkSize, (index + 1) * chunkSize),\n length: len,\n index: index,\n session,\n }, target, customType));\n index += 1;\n }\n }\n }\n\n public async userList(): Promise<Set<string>> {\n const output = new Set<string>();\n const result = await this.rtmClient.presence.whoNow(this.roomChannel(), \"MESSAGE\", {\n includedState: false,\n });\n var nextPage: string | null = result.nextPage;\n result.occupants.forEach((userInfo) => {\n const { userId } = userInfo;\n output.add(userId);\n });\n while (nextPage) {\n const result = await this.rtmClient.presence.whoNow(this.roomChannel(), \"MESSAGE\", {\n includedState: false,\n page: nextPage,\n });\n nextPage = result.nextPage;\n result.occupants.forEach((userInfo) => {\n const { userId } = userInfo;\n output.add(userId);\n });\n }\n return output;\n }\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAA8C,WAAW;AACzD,OAAO,kBAAkB;AACzB,SAAQ,MAAM,cAAa;AAI3B,IAAM,SAAS,CAAC,KAAa,OAAO,MAAM;AACtC,MAAI,KAAK,aAAa,MAAM,KAAK,aAAa;AAC9C,WAAQ,IAAI,GAAG,IAAI,IAAI,IAAI,QAAQ,KAAK;AACpC,SAAK,IAAI,WAAW,CAAC;AACrB,SAAK,KAAK,KAAK,KAAK,IAAI,UAAU;AAClC,SAAK,KAAK,KAAK,KAAK,IAAI,UAAU;AAAA,EACtC;AACA,OAAM,KAAK,KAAK,KAAM,OAAO,IAAK,UAAU;AAC5C,QAAM,KAAK,KAAK,KAAM,OAAO,IAAK,UAAU;AAC5C,OAAM,KAAK,KAAK,KAAM,OAAO,IAAK,UAAU;AAC5C,QAAM,KAAK,KAAK,KAAM,OAAO,IAAK,UAAU;AAE5C,SAAO,cAAc,UAAU,OAAO,OAAO;AACjD;AASA,IAAM,uBAAN,MAAM,sBAAqB;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AO;AAAA,EACX;AACJ;",
|
|
6
|
+
"names": ["result"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
RTMProvider_2_1: () => RTMProvider_2_1
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(src_exports);
|
|
36
|
+
|
|
37
|
+
// src/RTM_2_1.ts
|
|
38
|
+
var import_forge_room = require("@netless/forge-room");
|
|
39
|
+
var import_eventemitter3 = __toESM(require("eventemitter3"), 1);
|
|
40
|
+
var import_uuid = require("uuid");
|
|
41
|
+
var cyrb53 = (str, seed = 0) => {
|
|
42
|
+
let h1 = 3735928559 ^ seed, h2 = 1103547991 ^ seed;
|
|
43
|
+
for (let i = 0, ch; i < str.length; i++) {
|
|
44
|
+
ch = str.charCodeAt(i);
|
|
45
|
+
h1 = Math.imul(h1 ^ ch, 2654435761);
|
|
46
|
+
h2 = Math.imul(h2 ^ ch, 1597334677);
|
|
47
|
+
}
|
|
48
|
+
h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507);
|
|
49
|
+
h1 ^= Math.imul(h2 ^ h2 >>> 13, 3266489909);
|
|
50
|
+
h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507);
|
|
51
|
+
h2 ^= Math.imul(h1 ^ h1 >>> 13, 3266489909);
|
|
52
|
+
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
|
|
53
|
+
};
|
|
54
|
+
var ChunkedUpdateMessage = class _ChunkedUpdateMessage {
|
|
55
|
+
static fromObject(obj, target, customType) {
|
|
56
|
+
const msg = new _ChunkedUpdateMessage();
|
|
57
|
+
msg.target = target;
|
|
58
|
+
msg.customType = customType;
|
|
59
|
+
const encoder = new TextEncoder();
|
|
60
|
+
const sessionBuf = encoder.encode(obj.session);
|
|
61
|
+
msg.header = new DataView(new Uint8Array(10).buffer);
|
|
62
|
+
msg.header.setUint32(0, obj.buf.length, false);
|
|
63
|
+
msg.header.setUint32(4, sessionBuf.length, false);
|
|
64
|
+
msg.header.setUint8(8, obj.index);
|
|
65
|
+
msg.header.setUint8(9, obj.length);
|
|
66
|
+
msg.buffer = new Uint8Array(
|
|
67
|
+
obj.buf.length + sessionBuf.length + msg.header.buffer.byteLength
|
|
68
|
+
);
|
|
69
|
+
let len = 0;
|
|
70
|
+
msg.buffer.set(new Uint8Array(msg.header.buffer), len);
|
|
71
|
+
len += msg.header.buffer.byteLength;
|
|
72
|
+
msg.buffer.set(obj.buf, len);
|
|
73
|
+
len += obj.buf.length;
|
|
74
|
+
msg.buffer.set(sessionBuf, len);
|
|
75
|
+
return msg;
|
|
76
|
+
}
|
|
77
|
+
static fromBuffer(buf, target, customType) {
|
|
78
|
+
const msg = new _ChunkedUpdateMessage();
|
|
79
|
+
msg.header = new DataView(buf.slice(0, 10).buffer);
|
|
80
|
+
msg.buffer = buf.slice(10);
|
|
81
|
+
msg.target = target;
|
|
82
|
+
msg.customType = customType;
|
|
83
|
+
return msg;
|
|
84
|
+
}
|
|
85
|
+
target;
|
|
86
|
+
customType;
|
|
87
|
+
buffer;
|
|
88
|
+
header;
|
|
89
|
+
get buf() {
|
|
90
|
+
const len = this.header.getInt32(0);
|
|
91
|
+
return this.buffer.slice(0, len);
|
|
92
|
+
}
|
|
93
|
+
get index() {
|
|
94
|
+
return this.header.getUint8(8);
|
|
95
|
+
}
|
|
96
|
+
get length() {
|
|
97
|
+
return this.header.getUint8(9);
|
|
98
|
+
}
|
|
99
|
+
get session() {
|
|
100
|
+
const start = this.header.getInt32(0);
|
|
101
|
+
const sessionBuf = this.buffer.slice(start, start + this.header.getInt32(4));
|
|
102
|
+
const textDecoder = new TextDecoder();
|
|
103
|
+
return textDecoder.decode(sessionBuf);
|
|
104
|
+
}
|
|
105
|
+
constructor() {
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
var RTMProvider_2_1 = class extends import_eventemitter3.default {
|
|
109
|
+
rtmClient;
|
|
110
|
+
roomId;
|
|
111
|
+
userId;
|
|
112
|
+
reconnectTimeout = null;
|
|
113
|
+
chunkedMessages = /* @__PURE__ */ new Map();
|
|
114
|
+
cachedMessages = [];
|
|
115
|
+
intervalId = null;
|
|
116
|
+
constructor(rtmClient) {
|
|
117
|
+
super();
|
|
118
|
+
this.rtmClient = rtmClient;
|
|
119
|
+
}
|
|
120
|
+
roomChannel() {
|
|
121
|
+
return `r_${this.roomId}`;
|
|
122
|
+
}
|
|
123
|
+
userChannel(userId) {
|
|
124
|
+
if (userId.length > 16) {
|
|
125
|
+
userId = `${cyrb53(userId)}`;
|
|
126
|
+
}
|
|
127
|
+
return `${this.roomChannel()}_u_${userId}`;
|
|
128
|
+
}
|
|
129
|
+
async initialize(roomId, userId) {
|
|
130
|
+
window.clearInterval(this.intervalId);
|
|
131
|
+
this.roomId = roomId;
|
|
132
|
+
this.userId = userId;
|
|
133
|
+
this.rtmClient.addEventListener("message", this.handleRtmMessage);
|
|
134
|
+
this.rtmClient.addEventListener("presence", this.handlePresence);
|
|
135
|
+
this.rtmClient.addEventListener("status", this.handleStatus);
|
|
136
|
+
try {
|
|
137
|
+
await this.rtmClient.subscribe(this.roomChannel());
|
|
138
|
+
await this.rtmClient.subscribe(this.userChannel(this.userId));
|
|
139
|
+
} catch (error) {
|
|
140
|
+
this.emit("error", `rtm subscribe fail, ${error}`);
|
|
141
|
+
(0, import_forge_room.log)(`rtm subscribe fail`, {
|
|
142
|
+
error: error.toString()
|
|
143
|
+
}, "error");
|
|
144
|
+
}
|
|
145
|
+
this.intervalId = setInterval(() => {
|
|
146
|
+
const msg = this.cachedMessages.shift();
|
|
147
|
+
if (msg) {
|
|
148
|
+
const channel = msg.target ? this.userChannel(msg.target) : this.roomChannel();
|
|
149
|
+
this.rtmClient.publish(channel, msg.buffer, { customType: msg.customType }).catch((error) => {
|
|
150
|
+
(0, import_forge_room.log)(`rtm publish failed`, {
|
|
151
|
+
channel,
|
|
152
|
+
code: error.code
|
|
153
|
+
}, "warning");
|
|
154
|
+
this.emit("error", `rtm publish fail, ${error}`);
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}, 32);
|
|
158
|
+
}
|
|
159
|
+
handleRtmMessage = (evt) => {
|
|
160
|
+
this.receiveChunkMessage(ChunkedUpdateMessage.fromBuffer(evt.message, "", evt.customType), evt.publisher);
|
|
161
|
+
};
|
|
162
|
+
handleStatus = (connectionStatus) => {
|
|
163
|
+
(0, import_forge_room.log)(`rtm status update`, {
|
|
164
|
+
state: connectionStatus.state,
|
|
165
|
+
reason: connectionStatus.reason
|
|
166
|
+
});
|
|
167
|
+
if (connectionStatus.state === "RECONNECTING" && this.reconnectTimeout === null) {
|
|
168
|
+
this.reconnectTimeout = window.setTimeout(() => {
|
|
169
|
+
this.emit("error", `reconnecting timeout`);
|
|
170
|
+
this.emit("connectionStatusChange", "DISCONNECTED");
|
|
171
|
+
}, 30 * 1e3);
|
|
172
|
+
} else if (connectionStatus.state === "CONNECTED") {
|
|
173
|
+
window.clearTimeout(this.reconnectTimeout);
|
|
174
|
+
this.emit("connectionStatusChange", "CONNECTED");
|
|
175
|
+
} else if (connectionStatus.state === "FAILED") {
|
|
176
|
+
window.clearTimeout(this.reconnectTimeout);
|
|
177
|
+
this.emit("error", `rtm connection failed, ${connectionStatus.reason}`);
|
|
178
|
+
this.emit("connectionStatusChange", "DISCONNECTED");
|
|
179
|
+
} else if (connectionStatus.state === "CONNECTING") {
|
|
180
|
+
this.emit("connectionStatusChange", "CONNECTING");
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
handlePresence = (evt) => {
|
|
184
|
+
if (evt.channelName === this.roomChannel()) {
|
|
185
|
+
if (evt.eventType === "REMOTE_JOIN") {
|
|
186
|
+
this.emit("userJoin", evt.publisher);
|
|
187
|
+
} else if (evt.eventType === "REMOTE_LEAVE") {
|
|
188
|
+
this.emit("userLeave", evt.publisher);
|
|
189
|
+
} else if (evt.eventType === "REMOTE_TIMEOUT") {
|
|
190
|
+
this.emit("userLeave", evt.publisher);
|
|
191
|
+
} else if (evt.eventType === "INTERVAL") {
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
receiveChunkMessage(msg, publisher) {
|
|
196
|
+
if (msg.length === 1) {
|
|
197
|
+
this.emit("message", msg.buf, publisher, msg.customType);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const chunks = this.chunkedMessages.get(msg.session) || [];
|
|
201
|
+
chunks.push(msg);
|
|
202
|
+
if (chunks.length === msg.length) {
|
|
203
|
+
const buffer = chunks.sort((a, b) => a.index - b.index).reduce((result, next) => {
|
|
204
|
+
const buf = next.buf;
|
|
205
|
+
const output = new Uint8Array(result.length + buf.length);
|
|
206
|
+
output.set(result, 0);
|
|
207
|
+
output.set(buf, result.length);
|
|
208
|
+
return output;
|
|
209
|
+
}, new Uint8Array());
|
|
210
|
+
this.emit("message", buffer, publisher, msg.customType);
|
|
211
|
+
this.chunkedMessages.delete(msg.session);
|
|
212
|
+
} else {
|
|
213
|
+
this.chunkedMessages.set(msg.session, chunks);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
publish(buf, customType, target = "") {
|
|
217
|
+
const session = (0, import_uuid.v4)();
|
|
218
|
+
const size = buf.length * Uint8Array.BYTES_PER_ELEMENT / 1024;
|
|
219
|
+
if (size < 16) {
|
|
220
|
+
this.cachedMessages.push(ChunkedUpdateMessage.fromObject({
|
|
221
|
+
buf,
|
|
222
|
+
length: 1,
|
|
223
|
+
index: 0,
|
|
224
|
+
session
|
|
225
|
+
}, target, customType));
|
|
226
|
+
} else {
|
|
227
|
+
const chunkSize = 16 * 1024 / Uint8Array.BYTES_PER_ELEMENT;
|
|
228
|
+
let len = Math.ceil(size / 16);
|
|
229
|
+
let index = 0;
|
|
230
|
+
while (index < len) {
|
|
231
|
+
this.cachedMessages.push(ChunkedUpdateMessage.fromObject({
|
|
232
|
+
buf: buf.slice(index * chunkSize, (index + 1) * chunkSize),
|
|
233
|
+
length: len,
|
|
234
|
+
index,
|
|
235
|
+
session
|
|
236
|
+
}, target, customType));
|
|
237
|
+
index += 1;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
async userList() {
|
|
242
|
+
const output = /* @__PURE__ */ new Set();
|
|
243
|
+
const result = await this.rtmClient.presence.whoNow(this.roomChannel(), "MESSAGE", {
|
|
244
|
+
includedState: false
|
|
245
|
+
});
|
|
246
|
+
var nextPage = result.nextPage;
|
|
247
|
+
result.occupants.forEach((userInfo) => {
|
|
248
|
+
const { userId } = userInfo;
|
|
249
|
+
output.add(userId);
|
|
250
|
+
});
|
|
251
|
+
while (nextPage) {
|
|
252
|
+
const result2 = await this.rtmClient.presence.whoNow(this.roomChannel(), "MESSAGE", {
|
|
253
|
+
includedState: false,
|
|
254
|
+
page: nextPage
|
|
255
|
+
});
|
|
256
|
+
nextPage = result2.nextPage;
|
|
257
|
+
result2.occupants.forEach((userInfo) => {
|
|
258
|
+
const { userId } = userInfo;
|
|
259
|
+
output.add(userId);
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
return output;
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
//# sourceMappingURL=rtm-provider.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.ts", "../src/RTM_2_1.ts"],
|
|
4
|
+
"sourcesContent": ["export * from \"./RTM_2_1\";\n", "import { SocketProvider, SocketProviderEvent, log } from \"@netless/forge-room\";\nimport EventEmitter from \"eventemitter3\";\nimport {v4 as uuidv4} from \"uuid\";\n\nimport {RTMClient, RTMEvents} from \"agora-rtm\";\n\nconst cyrb53 = (str: string, seed = 0) => {\n let h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed;\n for(let i = 0, ch; i < str.length; i++) {\n ch = str.charCodeAt(i);\n h1 = Math.imul(h1 ^ ch, 2654435761);\n h2 = Math.imul(h2 ^ ch, 1597334677);\n }\n h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507);\n h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909);\n h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507);\n h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909);\n\n return 4294967296 * (2097151 & h2) + (h1 >>> 0);\n};\n\nexport type ChunkedUpdateMessageType = {\n buf: Uint8Array;\n index: number;\n length: number;\n session: string;\n}\n\nclass ChunkedUpdateMessage {\n\n static fromObject(obj: ChunkedUpdateMessageType, target: string, customType: string): ChunkedUpdateMessage {\n const msg = new ChunkedUpdateMessage();\n msg.target = target;\n msg.customType = customType;\n\n const encoder = new TextEncoder();\n const sessionBuf = encoder.encode(obj.session);\n\n // header \u6309\u987A\u5E8F\u6307\u793A buf, session, target, customType \u90E8\u5206\u7684 uint8 \u957F\u5EA6\n msg.header = new DataView(new Uint8Array(10).buffer);\n\n msg.header.setUint32(0, obj.buf.length, false);\n msg.header.setUint32(4, sessionBuf.length, false);\n msg.header.setUint8(8, obj.index);\n msg.header.setUint8(9, obj.length);\n\n msg.buffer = new Uint8Array(\n obj.buf.length + sessionBuf.length + msg.header.buffer.byteLength\n );\n\n let len = 0;\n msg.buffer.set(new Uint8Array(msg.header.buffer), len);\n len += msg.header.buffer.byteLength;\n msg.buffer.set(obj.buf, len);\n len += obj.buf.length;\n msg.buffer.set(sessionBuf, len);\n\n return msg;\n }\n\n static fromBuffer(buf: Uint8Array, target: string, customType: string) {\n const msg = new ChunkedUpdateMessage();\n\n msg.header = new DataView(buf.slice(0, 10).buffer);\n msg.buffer = buf.slice(10);\n msg.target = target;\n msg.customType = customType;\n\n return msg;\n }\n\n public target!: string;\n public customType!: string;\n public buffer!: Uint8Array;\n private header!: DataView;\n\n public get buf(): Uint8Array {\n const len = this.header.getInt32(0);\n return this.buffer.slice(0, len);\n }\n\n public get index(): number {\n return this.header.getUint8(8);\n }\n\n public get length(): number {\n return this.header.getUint8(9);\n }\n\n public get session(): string {\n const start = this.header.getInt32(0);\n const sessionBuf = this.buffer.slice(start, start + this.header.getInt32(4));\n const textDecoder = new TextDecoder();\n return textDecoder.decode(sessionBuf);\n }\n\n private constructor() {}\n}\n\nexport class RTMProvider_2_1 extends EventEmitter<SocketProviderEvent> implements SocketProvider {\n\n private rtmClient!: RTMClient;\n private roomId!: string;\n private userId!: string;\n\n private reconnectTimeout: any = null;\n private chunkedMessages: Map<string, ChunkedUpdateMessage[]> = new Map();\n private cachedMessages: ChunkedUpdateMessage[] = [];\n\n private intervalId: any = null;\n\n public constructor(rtmClient: RTMClient) {\n super();\n this.rtmClient = rtmClient;\n }\n\n private roomChannel(): string {\n return `r_${this.roomId}`;\n }\n\n private userChannel(userId: string): string {\n if (userId.length > 16) {\n userId = `${cyrb53(userId)}`;\n }\n return `${this.roomChannel()}_u_${userId}`;\n }\n\n public async initialize(roomId: string, userId: string): Promise<void> {\n window.clearInterval(this.intervalId);\n this.roomId = roomId;\n this.userId = userId;\n this.rtmClient.addEventListener(\"message\", this.handleRtmMessage);\n this.rtmClient.addEventListener(\"presence\", this.handlePresence);\n // @ts-ignore\n this.rtmClient.addEventListener(\"status\", this.handleStatus);\n try {\n await this.rtmClient.subscribe(this.roomChannel());\n await this.rtmClient.subscribe(this.userChannel(this.userId));\n } catch(error: any) {\n this.emit(\"error\", `rtm subscribe fail, ${error}`);\n log(`rtm subscribe fail`, {\n error: error.toString(),\n }, \"error\");\n }\n this.intervalId = setInterval(() => {\n const msg = this.cachedMessages.shift();\n if (msg) {\n const channel = msg.target ? this.userChannel(msg.target) : this.roomChannel();\n this.rtmClient.publish(channel, msg.buffer, { customType: msg.customType }).catch(error => {\n log(`rtm publish failed`, {\n channel,\n code: error.code\n }, \"warning\");\n this.emit(\"error\", `rtm publish fail, ${error}`);\n });\n }\n }, 32);\n }\n\n private handleRtmMessage = (evt: RTMEvents.MessageEvent) => {\n this.receiveChunkMessage(ChunkedUpdateMessage.fromBuffer(evt.message as Uint8Array, \"\", evt.customType), evt.publisher);\n };\n\n private handleStatus = (connectionStatus: RTMEvents.RTMConnectionStatusChangeEvent) => {\n log(`rtm status update`, {\n state: connectionStatus.state,\n reason: connectionStatus.reason\n });\n if (connectionStatus.state === \"RECONNECTING\" && this.reconnectTimeout === null) {\n this.reconnectTimeout = window.setTimeout(() => {\n this.emit(\"error\", `reconnecting timeout`);\n this.emit(\"connectionStatusChange\", \"DISCONNECTED\");\n }, 30 * 1000);\n } else if (connectionStatus.state === \"CONNECTED\") {\n window.clearTimeout(this.reconnectTimeout);\n this.emit(\"connectionStatusChange\", \"CONNECTED\");\n } else if (connectionStatus.state === \"FAILED\") {\n window.clearTimeout(this.reconnectTimeout);\n this.emit(\"error\", `rtm connection failed, ${connectionStatus.reason}`);\n this.emit(\"connectionStatusChange\", \"DISCONNECTED\");\n } else if (connectionStatus.state === \"CONNECTING\") {\n this.emit(\"connectionStatusChange\", \"CONNECTING\");\n }\n }\n\n private handlePresence = (evt: RTMEvents.PresenceEvent) => {\n if (evt.channelName === this.roomChannel()) {\n if (evt.eventType === \"REMOTE_JOIN\") {\n this.emit(\"userJoin\", evt.publisher);\n } else if (evt.eventType === \"REMOTE_LEAVE\") {\n this.emit(\"userLeave\", evt.publisher);\n } else if (evt.eventType === \"REMOTE_TIMEOUT\") {\n this.emit(\"userLeave\", evt.publisher);\n } else if (evt.eventType === \"INTERVAL\") {\n // evt.interval.join.users\n }\n }\n };\n\n private receiveChunkMessage(msg: ChunkedUpdateMessage, publisher: string) {\n if (msg.length === 1) {\n this.emit(\"message\", msg.buf, publisher, msg.customType);\n return;\n }\n const chunks = this.chunkedMessages.get(msg.session) || [];\n chunks.push(msg);\n if (chunks.length === msg.length) {\n const buffer = chunks.sort((a, b) => a.index - b.index)\n .reduce((result, next) => {\n const buf = next.buf;\n const output = new Uint8Array(result.length + buf.length);\n output.set(result, 0);\n output.set(buf, result.length);\n return output;\n }, new Uint8Array());\n this.emit(\"message\", buffer, publisher, msg.customType);\n this.chunkedMessages.delete(msg.session);\n } else {\n this.chunkedMessages.set(msg.session, chunks);\n }\n }\n\n public publish(buf: Uint8Array, customType: string, target: string = \"\") {\n const session = uuidv4();\n // \u6D88\u606F\u5305\u4F53\u79EF, \u5355\u4F4D kb\n const size = buf.length * Uint8Array.BYTES_PER_ELEMENT / 1024;\n if (size < 16) {\n this.cachedMessages.push(ChunkedUpdateMessage.fromObject({\n buf: buf,\n length: 1,\n index: 0,\n session\n }, target, customType));\n } else {\n const chunkSize = 16 * 1024 / Uint8Array.BYTES_PER_ELEMENT;\n let len = Math.ceil(size / 16);\n let index = 0;\n while (index < len) {\n this.cachedMessages.push(ChunkedUpdateMessage.fromObject({\n buf: buf.slice(index * chunkSize, (index + 1) * chunkSize),\n length: len,\n index: index,\n session,\n }, target, customType));\n index += 1;\n }\n }\n }\n\n public async userList(): Promise<Set<string>> {\n const output = new Set<string>();\n const result = await this.rtmClient.presence.whoNow(this.roomChannel(), \"MESSAGE\", {\n includedState: false,\n });\n var nextPage: string | null = result.nextPage;\n result.occupants.forEach((userInfo) => {\n const { userId } = userInfo;\n output.add(userId);\n });\n while (nextPage) {\n const result = await this.rtmClient.presence.whoNow(this.roomChannel(), \"MESSAGE\", {\n includedState: false,\n page: nextPage,\n });\n nextPage = result.nextPage;\n result.occupants.forEach((userInfo) => {\n const { userId } = userInfo;\n output.add(userId);\n });\n }\n return output;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,wBAAyD;AACzD,2BAAyB;AACzB,kBAA2B;AAI3B,IAAM,SAAS,CAAC,KAAa,OAAO,MAAM;AACtC,MAAI,KAAK,aAAa,MAAM,KAAK,aAAa;AAC9C,WAAQ,IAAI,GAAG,IAAI,IAAI,IAAI,QAAQ,KAAK;AACpC,SAAK,IAAI,WAAW,CAAC;AACrB,SAAK,KAAK,KAAK,KAAK,IAAI,UAAU;AAClC,SAAK,KAAK,KAAK,KAAK,IAAI,UAAU;AAAA,EACtC;AACA,OAAM,KAAK,KAAK,KAAM,OAAO,IAAK,UAAU;AAC5C,QAAM,KAAK,KAAK,KAAM,OAAO,IAAK,UAAU;AAC5C,OAAM,KAAK,KAAK,KAAM,OAAO,IAAK,U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iBAAWA,QAAO;AAClB,MAAAA,QAAO,UAAU,QAAQ,CAAC,aAAa;AACnC,cAAM,EAAG,OAAO,IAAI;AACpB,eAAO,IAAI,MAAM;AAAA,MACrB,CAAC;AAAA,IACL;AACA,WAAO;AAAA,EACX;AACJ;",
|
|
6
|
+
"names": ["EventEmitter", "uuidv4", "result"]
|
|
7
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@netless/forge-rtm",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/rtm-provider.js",
|
|
6
|
+
"module": "dist/rtm-provider.esm.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"dev": "onChange 'src/**/*' -- npm run build",
|
|
11
|
+
"build": "tsc --emitDeclarationOnly && node build.mjs"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
},
|
|
15
|
+
"peerDependencies": {
|
|
16
|
+
"js-base64": "^3.7.7",
|
|
17
|
+
"eventemitter3": "^5.0.1",
|
|
18
|
+
"uuid": "^9.0.1",
|
|
19
|
+
"@netless/forge-room": "workspace:*"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [],
|
|
22
|
+
"author": "",
|
|
23
|
+
"license": "ISC",
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"agora-rtm": "^2.1.9",
|
|
26
|
+
"@hyrious/esbuild-plugin-commonjs": "^0.2.4",
|
|
27
|
+
"@types/uuid": "^9.0.8",
|
|
28
|
+
"dts-bundle-generator": "^9.5.1"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist",
|
|
32
|
+
"package.json"
|
|
33
|
+
]
|
|
34
|
+
}
|