@netless/forge-rtm 0.1.10 → 0.1.11
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/ChunkedUpdateMessage.d.ts.map +1 -1
- package/dist/RTM_2_1.d.ts +11 -5
- package/dist/RTM_2_1.d.ts.map +1 -1
- package/dist/RTM_2_2.d.ts +11 -5
- package/dist/RTM_2_2.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/rtm-provider.esm.js +80 -28
- package/dist/rtm-provider.esm.js.map +2 -2
- package/dist/rtm-provider.js +80 -28
- package/dist/rtm-provider.js.map +2 -2
- package/package.json +4 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChunkedUpdateMessage.d.ts","sourceRoot":"","sources":["../src/ChunkedUpdateMessage.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,wBAAwB,GAAG;IACnC,GAAG,EAAE,UAAU,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACnB,CAAA;AAED,qBAAa,oBAAoB;
|
|
1
|
+
{"version":3,"file":"ChunkedUpdateMessage.d.ts","sourceRoot":"","sources":["../src/ChunkedUpdateMessage.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,wBAAwB,GAAG;IACnC,GAAG,EAAE,UAAU,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACnB,CAAA;AAED,qBAAa,oBAAoB;IAE/B,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,wBAAwB,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,oBAAoB;IA8B1G,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;IAW9D,MAAM,EAAG,MAAM,CAAC;IAChB,UAAU,EAAG,MAAM,CAAC;IACpB,MAAM,EAAG,UAAU,CAAC;IAC3B,OAAO,CAAC,MAAM,CAAY;IAE1B,IAAW,GAAG,IAAI,UAAU,CAG3B;IAED,IAAW,KAAK,IAAI,MAAM,CAEzB;IAED,IAAW,MAAM,IAAI,MAAM,CAE1B;IAED,IAAW,OAAO,IAAI,MAAM,CAK3B;IAED,OAAO;CACR"}
|
package/dist/RTM_2_1.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { SocketProvider, SocketProviderEvent } from
|
|
2
|
-
import EventEmitter from
|
|
3
|
-
import type { RTMClient } from
|
|
1
|
+
import { SocketProvider, SocketProviderEvent } from '@netless/forge-room';
|
|
2
|
+
import EventEmitter from 'eventemitter3';
|
|
3
|
+
import type { RTMClient } from 'agora-rtm';
|
|
4
4
|
export declare class RTMProvider_2_1 extends EventEmitter<SocketProviderEvent> implements SocketProvider {
|
|
5
5
|
private rtmClient;
|
|
6
6
|
private roomId;
|
|
@@ -9,16 +9,22 @@ export declare class RTMProvider_2_1 extends EventEmitter<SocketProviderEvent> i
|
|
|
9
9
|
private chunkedMessages;
|
|
10
10
|
private cachedMessages;
|
|
11
11
|
private intervalId;
|
|
12
|
+
private deviation;
|
|
13
|
+
private rtmTimestamp;
|
|
14
|
+
private animationStartTimestamp?;
|
|
15
|
+
private animationId?;
|
|
16
|
+
get calibrationTimestamp(): number;
|
|
12
17
|
constructor(rtmClient: RTMClient);
|
|
13
18
|
private roomChannel;
|
|
14
19
|
private userChannel;
|
|
15
20
|
/**
|
|
16
|
-
|
|
17
|
-
|
|
21
|
+
* 重新订阅频道
|
|
22
|
+
*/
|
|
18
23
|
resubscribe(): Promise<void>;
|
|
19
24
|
initialize(roomId: string, userId: string): Promise<void>;
|
|
20
25
|
dispose(): Promise<void>;
|
|
21
26
|
private handleRtmMessage;
|
|
27
|
+
private calibrateAnimate;
|
|
22
28
|
private handleStatus;
|
|
23
29
|
private handlePresence;
|
|
24
30
|
private receiveChunkMessage;
|
package/dist/RTM_2_1.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RTM_2_1.d.ts","sourceRoot":"","sources":["../src/RTM_2_1.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAO,MAAM,qBAAqB,CAAC;AAC/E,OAAO,YAAY,MAAM,eAAe,CAAC;AAIzC,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"RTM_2_1.d.ts","sourceRoot":"","sources":["../src/RTM_2_1.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAO,MAAM,qBAAqB,CAAC;AAC/E,OAAO,YAAY,MAAM,eAAe,CAAC;AAIzC,OAAO,KAAK,EAAE,SAAS,EAAa,MAAM,WAAW,CAAC;AAItD,qBAAa,eAAgB,SAAQ,YAAY,CAAC,mBAAmB,CAAE,YAAW,cAAc;IAE9F,OAAO,CAAC,SAAS,CAAa;IAC9B,OAAO,CAAC,MAAM,CAAU;IACxB,OAAO,CAAC,MAAM,CAAU;IAExB,OAAO,CAAC,gBAAgB,CAAa;IACrC,OAAO,CAAC,eAAe,CAAkD;IACzE,OAAO,CAAC,cAAc,CAA8B;IAEpD,OAAO,CAAC,UAAU,CAAa;IAE/B,OAAO,CAAC,SAAS,CAAa;IAC9B,OAAO,CAAC,YAAY,CAAa;IACjC,OAAO,CAAC,uBAAuB,CAAC,CAAS;IACzC,OAAO,CAAC,WAAW,CAAC,CAAS;IAC7B,IAAW,oBAAoB,IAAI,MAAM,CAExC;gBAEkB,SAAS,EAAE,SAAS;IAKvC,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,WAAW;IAOnB;;SAEK;IACQ,WAAW;IAYX,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAgCzD,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAUrC,OAAO,CAAC,gBAAgB,CAoBtB;IAEF,OAAO,CAAC,gBAAgB,CAQtB;IAEF,OAAO,CAAC,YAAY,CAqBlB;IAEF,OAAO,CAAC,cAAc,CAYpB;IAEF,OAAO,CAAC,mBAAmB;IAuBpB,OAAO,CAAC,GAAG,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAE,MAAW;IA2B1D,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;CAuB9C"}
|
package/dist/RTM_2_2.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { SocketProvider, SocketProviderEvent } from
|
|
2
|
-
import EventEmitter from
|
|
3
|
-
import type { RTMClient } from
|
|
1
|
+
import { SocketProvider, SocketProviderEvent } from '@netless/forge-room';
|
|
2
|
+
import EventEmitter from 'eventemitter3';
|
|
3
|
+
import type { RTMClient } from 'agora-rtm';
|
|
4
4
|
export declare class RTMProvider_2_2 extends EventEmitter<SocketProviderEvent> implements SocketProvider {
|
|
5
5
|
private rtmClient;
|
|
6
6
|
private roomId;
|
|
@@ -9,16 +9,22 @@ export declare class RTMProvider_2_2 extends EventEmitter<SocketProviderEvent> i
|
|
|
9
9
|
private chunkedMessages;
|
|
10
10
|
private cachedMessages;
|
|
11
11
|
private intervalId;
|
|
12
|
+
private deviation;
|
|
13
|
+
private rtmTimestamp;
|
|
14
|
+
private animationStartTimestamp?;
|
|
15
|
+
private animationId?;
|
|
16
|
+
get calibrationTimestamp(): number;
|
|
12
17
|
constructor(rtmClient: RTMClient);
|
|
13
18
|
private roomChannel;
|
|
14
19
|
private userChannel;
|
|
15
20
|
initialize(roomId: string, userId: string): Promise<void>;
|
|
16
21
|
/**
|
|
17
|
-
|
|
18
|
-
|
|
22
|
+
* 重新订阅频道
|
|
23
|
+
*/
|
|
19
24
|
resubscribe(): Promise<void>;
|
|
20
25
|
dispose(): Promise<void>;
|
|
21
26
|
private handleRtmMessage;
|
|
27
|
+
private calibrateAnimate;
|
|
22
28
|
private handleStatus;
|
|
23
29
|
private handlePresence;
|
|
24
30
|
private receiveChunkMessage;
|
package/dist/RTM_2_2.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RTM_2_2.d.ts","sourceRoot":"","sources":["../src/RTM_2_2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAO,MAAM,qBAAqB,CAAC;AAC/E,OAAO,YAAY,MAAM,eAAe,CAAC;AAIzC,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"RTM_2_2.d.ts","sourceRoot":"","sources":["../src/RTM_2_2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAO,MAAM,qBAAqB,CAAC;AAC/E,OAAO,YAAY,MAAM,eAAe,CAAC;AAIzC,OAAO,KAAK,EAAE,SAAS,EAAa,MAAM,WAAW,CAAC;AAGtD,qBAAa,eAAgB,SAAQ,YAAY,CAAC,mBAAmB,CAAE,YAAW,cAAc;IAE9F,OAAO,CAAC,SAAS,CAAa;IAC9B,OAAO,CAAC,MAAM,CAAU;IACxB,OAAO,CAAC,MAAM,CAAU;IAExB,OAAO,CAAC,gBAAgB,CAAa;IACrC,OAAO,CAAC,eAAe,CAAkD;IACzE,OAAO,CAAC,cAAc,CAA8B;IAEpD,OAAO,CAAC,UAAU,CAAa;IAE/B,OAAO,CAAC,SAAS,CAAa;IAC9B,OAAO,CAAC,YAAY,CAAa;IACjC,OAAO,CAAC,uBAAuB,CAAC,CAAS;IACzC,OAAO,CAAC,WAAW,CAAC,CAAS;IAC7B,IAAW,oBAAoB,IAAI,MAAM,CAExC;gBACkB,SAAS,EAAE,SAAS;IAKvC,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,WAAW;IAON,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAkCtE;;SAEK;IACQ,WAAW;IAYX,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAUrC,OAAO,CAAC,gBAAgB,CAmBtB;IAEF,OAAO,CAAC,gBAAgB,CAQtB;IAEF,OAAO,CAAC,YAAY,CAsBlB;IAEF,OAAO,CAAC,cAAc,CAYpB;IAEF,OAAO,CAAC,mBAAmB;IAuBpB,OAAO,CAAC,GAAG,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAE,MAAW;IA2B1D,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;CAuB9C"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { RTMProvider_2_1 } from
|
|
2
|
-
export { RTMProvider_2_2 } from
|
|
1
|
+
export { RTMProvider_2_1 } from './RTM_2_1';
|
|
2
|
+
export { RTMProvider_2_2 } from './RTM_2_2';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/rtm-provider.esm.js
CHANGED
|
@@ -109,6 +109,9 @@ function _toPrimitive2(t, r) {
|
|
|
109
109
|
return ("string" === r ? String : Number)(t);
|
|
110
110
|
}
|
|
111
111
|
var RTMProvider_2_1 = class extends EventEmitter {
|
|
112
|
+
get calibrationTimestamp() {
|
|
113
|
+
return this.rtmTimestamp + this.deviation;
|
|
114
|
+
}
|
|
112
115
|
constructor(rtmClient) {
|
|
113
116
|
super();
|
|
114
117
|
_defineProperty2(this, "rtmClient", void 0);
|
|
@@ -118,25 +121,48 @@ var RTMProvider_2_1 = class extends EventEmitter {
|
|
|
118
121
|
_defineProperty2(this, "chunkedMessages", /* @__PURE__ */ new Map());
|
|
119
122
|
_defineProperty2(this, "cachedMessages", []);
|
|
120
123
|
_defineProperty2(this, "intervalId", null);
|
|
124
|
+
_defineProperty2(this, "deviation", 0);
|
|
125
|
+
_defineProperty2(this, "rtmTimestamp", 0);
|
|
126
|
+
_defineProperty2(this, "animationStartTimestamp", void 0);
|
|
127
|
+
_defineProperty2(this, "animationId", void 0);
|
|
121
128
|
_defineProperty2(this, "handleRtmMessage", (evt) => {
|
|
129
|
+
const isRoomChannel = evt.channelName.indexOf("_u_") < 0;
|
|
122
130
|
if (!(evt.message instanceof Uint8Array)) {
|
|
123
|
-
log(
|
|
131
|
+
log("rtm message not Uint8Array", {
|
|
124
132
|
channel: evt.channelName,
|
|
125
133
|
publisher: evt.publisher,
|
|
126
134
|
message: evt.message
|
|
127
135
|
});
|
|
128
136
|
return;
|
|
129
137
|
}
|
|
130
|
-
this.
|
|
138
|
+
if (this.animationId) {
|
|
139
|
+
cancelAnimationFrame(this.animationId);
|
|
140
|
+
this.animationStartTimestamp = void 0;
|
|
141
|
+
this.animationId = void 0;
|
|
142
|
+
this.deviation = 0;
|
|
143
|
+
}
|
|
144
|
+
this.rtmTimestamp = evt.timestamp;
|
|
145
|
+
this.animationId = requestAnimationFrame(this.calibrateAnimate);
|
|
146
|
+
this.receiveChunkMessage(ChunkedUpdateMessage.fromBuffer(evt.message, "", evt.customType), evt.publisher, isRoomChannel);
|
|
147
|
+
});
|
|
148
|
+
_defineProperty2(this, "calibrateAnimate", (timestamp) => {
|
|
149
|
+
if (this.animationStartTimestamp === void 0) {
|
|
150
|
+
this.animationStartTimestamp = timestamp;
|
|
151
|
+
}
|
|
152
|
+
this.deviation = timestamp - this.animationStartTimestamp;
|
|
153
|
+
if (this.animationId) {
|
|
154
|
+
this.animationId = requestAnimationFrame(this.calibrateAnimate);
|
|
155
|
+
}
|
|
131
156
|
});
|
|
132
157
|
_defineProperty2(this, "handleStatus", (connectionStatus) => {
|
|
133
|
-
log(
|
|
158
|
+
log("rtm status update", {
|
|
134
159
|
state: connectionStatus.state,
|
|
135
160
|
reason: connectionStatus.reason
|
|
136
161
|
});
|
|
137
162
|
if (connectionStatus.state === "RECONNECTING" && this.reconnectTimeout === null) {
|
|
163
|
+
this.emit("connectionStatusChange", "RECONNECTING");
|
|
138
164
|
this.reconnectTimeout = window.setTimeout(() => {
|
|
139
|
-
this.emit("error",
|
|
165
|
+
this.emit("error", "reconnecting timeout");
|
|
140
166
|
this.emit("connectionStatusChange", "DISCONNECTED");
|
|
141
167
|
}, 30 * 1e3);
|
|
142
168
|
} else if (connectionStatus.state === "CONNECTED") {
|
|
@@ -174,15 +200,15 @@ var RTMProvider_2_1 = class extends EventEmitter {
|
|
|
174
200
|
return `${this.roomChannel()}_u_${userId}`;
|
|
175
201
|
}
|
|
176
202
|
/**
|
|
177
|
-
|
|
178
|
-
|
|
203
|
+
* 重新订阅频道
|
|
204
|
+
*/
|
|
179
205
|
async resubscribe() {
|
|
180
206
|
try {
|
|
181
207
|
await this.rtmClient.subscribe(this.roomChannel());
|
|
182
208
|
await this.rtmClient.subscribe(this.userChannel(this.userId));
|
|
183
209
|
} catch (error) {
|
|
184
210
|
this.emit("error", `rtm subscribe fail, ${error}`);
|
|
185
|
-
log(
|
|
211
|
+
log("rtm subscribe fail", {
|
|
186
212
|
error: error.toString()
|
|
187
213
|
}, "error");
|
|
188
214
|
}
|
|
@@ -199,7 +225,7 @@ var RTMProvider_2_1 = class extends EventEmitter {
|
|
|
199
225
|
await this.rtmClient.subscribe(this.userChannel(this.userId));
|
|
200
226
|
} catch (error) {
|
|
201
227
|
this.emit("error", `rtm subscribe fail, ${error}`);
|
|
202
|
-
log(
|
|
228
|
+
log("rtm subscribe fail", {
|
|
203
229
|
error: error.toString()
|
|
204
230
|
}, "error");
|
|
205
231
|
}
|
|
@@ -210,7 +236,7 @@ var RTMProvider_2_1 = class extends EventEmitter {
|
|
|
210
236
|
this.rtmClient.publish(channel, msg.buffer, {
|
|
211
237
|
customType: msg.customType
|
|
212
238
|
}).catch((error) => {
|
|
213
|
-
log(
|
|
239
|
+
log("rtm publish failed", {
|
|
214
240
|
channel,
|
|
215
241
|
code: error.code
|
|
216
242
|
}, "warning");
|
|
@@ -227,9 +253,9 @@ var RTMProvider_2_1 = class extends EventEmitter {
|
|
|
227
253
|
await this.rtmClient.unsubscribe(this.userChannel(this.userId));
|
|
228
254
|
window.clearInterval(this.intervalId);
|
|
229
255
|
}
|
|
230
|
-
receiveChunkMessage(msg, publisher) {
|
|
256
|
+
receiveChunkMessage(msg, publisher, isRoomChannel) {
|
|
231
257
|
if (msg.length === 1) {
|
|
232
|
-
this.emit("message", msg.buf, publisher, msg.customType);
|
|
258
|
+
this.emit("message", msg.buf, publisher, msg.customType, isRoomChannel);
|
|
233
259
|
return;
|
|
234
260
|
}
|
|
235
261
|
const chunks = this.chunkedMessages.get(msg.session) || [];
|
|
@@ -242,7 +268,7 @@ var RTMProvider_2_1 = class extends EventEmitter {
|
|
|
242
268
|
output.set(buf, result.length);
|
|
243
269
|
return output;
|
|
244
270
|
}, new Uint8Array());
|
|
245
|
-
this.emit("message", buffer, publisher, msg.customType);
|
|
271
|
+
this.emit("message", buffer, publisher, msg.customType, isRoomChannel);
|
|
246
272
|
this.chunkedMessages.delete(msg.session);
|
|
247
273
|
} else {
|
|
248
274
|
this.chunkedMessages.set(msg.session, chunks);
|
|
@@ -261,7 +287,7 @@ var RTMProvider_2_1 = class extends EventEmitter {
|
|
|
261
287
|
}, target, customType));
|
|
262
288
|
} else {
|
|
263
289
|
const chunkSize = 16 * 1024 / Uint8Array.BYTES_PER_ELEMENT;
|
|
264
|
-
|
|
290
|
+
const len = Math.ceil(size / 16);
|
|
265
291
|
let index = 0;
|
|
266
292
|
while (index < len) {
|
|
267
293
|
this.cachedMessages.push(ChunkedUpdateMessage.fromObject({
|
|
@@ -279,7 +305,7 @@ var RTMProvider_2_1 = class extends EventEmitter {
|
|
|
279
305
|
const result = await this.rtmClient.presence.whoNow(this.roomChannel(), "MESSAGE", {
|
|
280
306
|
includedState: false
|
|
281
307
|
});
|
|
282
|
-
|
|
308
|
+
let nextPage = result.nextPage;
|
|
283
309
|
result.occupants.forEach((userInfo) => {
|
|
284
310
|
const {
|
|
285
311
|
userId
|
|
@@ -325,6 +351,9 @@ function _toPrimitive3(t, r) {
|
|
|
325
351
|
return ("string" === r ? String : Number)(t);
|
|
326
352
|
}
|
|
327
353
|
var RTMProvider_2_2 = class extends EventEmitter2 {
|
|
354
|
+
get calibrationTimestamp() {
|
|
355
|
+
return this.rtmTimestamp + this.deviation;
|
|
356
|
+
}
|
|
328
357
|
constructor(rtmClient) {
|
|
329
358
|
super();
|
|
330
359
|
_defineProperty3(this, "rtmClient", void 0);
|
|
@@ -334,26 +363,49 @@ var RTMProvider_2_2 = class extends EventEmitter2 {
|
|
|
334
363
|
_defineProperty3(this, "chunkedMessages", /* @__PURE__ */ new Map());
|
|
335
364
|
_defineProperty3(this, "cachedMessages", []);
|
|
336
365
|
_defineProperty3(this, "intervalId", null);
|
|
366
|
+
_defineProperty3(this, "deviation", 0);
|
|
367
|
+
_defineProperty3(this, "rtmTimestamp", 0);
|
|
368
|
+
_defineProperty3(this, "animationStartTimestamp", void 0);
|
|
369
|
+
_defineProperty3(this, "animationId", void 0);
|
|
337
370
|
_defineProperty3(this, "handleRtmMessage", (evt) => {
|
|
371
|
+
const isRoomChannel = evt.channelName.indexOf("_u_") >= 0;
|
|
338
372
|
if (!(evt.message instanceof Uint8Array)) {
|
|
339
|
-
log2(
|
|
373
|
+
log2("rtm message not Uint8Array", {
|
|
340
374
|
channel: evt.channelName,
|
|
341
375
|
publisher: evt.publisher,
|
|
342
376
|
message: evt.message
|
|
343
377
|
});
|
|
344
378
|
return;
|
|
345
379
|
}
|
|
346
|
-
this.
|
|
380
|
+
if (this.animationId) {
|
|
381
|
+
cancelAnimationFrame(this.animationId);
|
|
382
|
+
this.animationStartTimestamp = void 0;
|
|
383
|
+
this.animationId = void 0;
|
|
384
|
+
this.deviation = 0;
|
|
385
|
+
}
|
|
386
|
+
this.rtmTimestamp = evt.timestamp;
|
|
387
|
+
this.animationId = requestAnimationFrame(this.calibrateAnimate);
|
|
388
|
+
this.receiveChunkMessage(ChunkedUpdateMessage.fromBuffer(evt.message, "", evt.customType), evt.publisher, isRoomChannel);
|
|
389
|
+
});
|
|
390
|
+
_defineProperty3(this, "calibrateAnimate", (timestamp) => {
|
|
391
|
+
if (this.animationStartTimestamp === void 0) {
|
|
392
|
+
this.animationStartTimestamp = timestamp;
|
|
393
|
+
}
|
|
394
|
+
this.deviation = timestamp - this.animationStartTimestamp;
|
|
395
|
+
if (this.animationId) {
|
|
396
|
+
this.animationId = requestAnimationFrame(this.calibrateAnimate);
|
|
397
|
+
}
|
|
347
398
|
});
|
|
348
399
|
_defineProperty3(this, "handleStatus", (connectionStatus) => {
|
|
349
|
-
log2(
|
|
400
|
+
log2("rtm status update", {
|
|
350
401
|
state: connectionStatus.state,
|
|
351
402
|
reason: connectionStatus.reason,
|
|
352
403
|
rtm: "2.2"
|
|
353
404
|
});
|
|
354
405
|
if (connectionStatus.state === "RECONNECTING" && this.reconnectTimeout === null) {
|
|
406
|
+
this.emit("connectionStatusChange", "RECONNECTING");
|
|
355
407
|
this.reconnectTimeout = window.setTimeout(() => {
|
|
356
|
-
this.emit("error",
|
|
408
|
+
this.emit("error", "reconnecting timeout");
|
|
357
409
|
this.emit("connectionStatusChange", "DISCONNECTED");
|
|
358
410
|
}, 30 * 1e3);
|
|
359
411
|
} else if (connectionStatus.state === "CONNECTED") {
|
|
@@ -402,7 +454,7 @@ var RTMProvider_2_2 = class extends EventEmitter2 {
|
|
|
402
454
|
await this.rtmClient.subscribe(this.userChannel(this.userId));
|
|
403
455
|
} catch (error) {
|
|
404
456
|
this.emit("error", `rtm subscribe fail, ${error}`);
|
|
405
|
-
log2(
|
|
457
|
+
log2("rtm subscribe fail", {
|
|
406
458
|
error: error.toString(),
|
|
407
459
|
rtm: "2.2"
|
|
408
460
|
}, "error");
|
|
@@ -414,7 +466,7 @@ var RTMProvider_2_2 = class extends EventEmitter2 {
|
|
|
414
466
|
this.rtmClient.publish(channel, msg.buffer, {
|
|
415
467
|
customType: msg.customType
|
|
416
468
|
}).catch((error) => {
|
|
417
|
-
log2(
|
|
469
|
+
log2("rtm publish failed", {
|
|
418
470
|
channel,
|
|
419
471
|
code: error.code,
|
|
420
472
|
rtm: "2.2"
|
|
@@ -425,15 +477,15 @@ var RTMProvider_2_2 = class extends EventEmitter2 {
|
|
|
425
477
|
}, 32);
|
|
426
478
|
}
|
|
427
479
|
/**
|
|
428
|
-
|
|
429
|
-
|
|
480
|
+
* 重新订阅频道
|
|
481
|
+
*/
|
|
430
482
|
async resubscribe() {
|
|
431
483
|
try {
|
|
432
484
|
await this.rtmClient.subscribe(this.roomChannel());
|
|
433
485
|
await this.rtmClient.subscribe(this.userChannel(this.userId));
|
|
434
486
|
} catch (error) {
|
|
435
487
|
this.emit("error", `rtm subscribe fail, ${error}`);
|
|
436
|
-
log2(
|
|
488
|
+
log2("rtm subscribe fail", {
|
|
437
489
|
error: error.toString()
|
|
438
490
|
}, "error");
|
|
439
491
|
}
|
|
@@ -446,9 +498,9 @@ var RTMProvider_2_2 = class extends EventEmitter2 {
|
|
|
446
498
|
await this.rtmClient.unsubscribe(this.userChannel(this.userId));
|
|
447
499
|
window.clearInterval(this.intervalId);
|
|
448
500
|
}
|
|
449
|
-
receiveChunkMessage(msg, publisher) {
|
|
501
|
+
receiveChunkMessage(msg, publisher, isRoomChannel) {
|
|
450
502
|
if (msg.length === 1) {
|
|
451
|
-
this.emit("message", msg.buf, publisher, msg.customType);
|
|
503
|
+
this.emit("message", msg.buf, publisher, msg.customType, isRoomChannel);
|
|
452
504
|
return;
|
|
453
505
|
}
|
|
454
506
|
const chunks = this.chunkedMessages.get(msg.session) || [];
|
|
@@ -461,7 +513,7 @@ var RTMProvider_2_2 = class extends EventEmitter2 {
|
|
|
461
513
|
output.set(buf, result.length);
|
|
462
514
|
return output;
|
|
463
515
|
}, new Uint8Array());
|
|
464
|
-
this.emit("message", buffer, publisher, msg.customType);
|
|
516
|
+
this.emit("message", buffer, publisher, msg.customType, isRoomChannel);
|
|
465
517
|
this.chunkedMessages.delete(msg.session);
|
|
466
518
|
} else {
|
|
467
519
|
this.chunkedMessages.set(msg.session, chunks);
|
|
@@ -480,7 +532,7 @@ var RTMProvider_2_2 = class extends EventEmitter2 {
|
|
|
480
532
|
}, target, customType));
|
|
481
533
|
} else {
|
|
482
534
|
const chunkSize = 16 * 1024 / Uint8Array.BYTES_PER_ELEMENT;
|
|
483
|
-
|
|
535
|
+
const len = Math.ceil(size / 16);
|
|
484
536
|
let index = 0;
|
|
485
537
|
while (index < len) {
|
|
486
538
|
this.cachedMessages.push(ChunkedUpdateMessage.fromObject({
|
|
@@ -498,7 +550,7 @@ var RTMProvider_2_2 = class extends EventEmitter2 {
|
|
|
498
550
|
const result = await this.rtmClient.presence.whoNow(this.roomChannel(), "MESSAGE", {
|
|
499
551
|
includedState: false
|
|
500
552
|
});
|
|
501
|
-
|
|
553
|
+
let nextPage = result.nextPage;
|
|
502
554
|
result.occupants.forEach((userInfo) => {
|
|
503
555
|
const {
|
|
504
556
|
userId
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/RTM_2_1.ts", "../src/utils.ts", "../src/ChunkedUpdateMessage.ts", "../src/RTM_2_2.ts"],
|
|
4
|
-
"sourcesContent": ["function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }\nfunction _toPropertyKey(t) { var i = _toPrimitive(t, \"string\"); return \"symbol\" == typeof i ? i : i + \"\"; }\nfunction _toPrimitive(t, r) { if (\"object\" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || \"default\"); if (\"object\" != typeof i) return i; throw new TypeError(\"@@toPrimitive must return a primitive value.\"); } return (\"string\" === r ? String : Number)(t); }\nimport { log } from \"@netless/forge-room\";\nimport EventEmitter from \"eventemitter3\";\nimport { v4 as uuidv4 } from \"uuid\";\nimport { cyrb53 } from \"./utils\";\nimport { ChunkedUpdateMessage } from \"./ChunkedUpdateMessage\";\nexport class RTMProvider_2_1 extends EventEmitter {\n constructor(rtmClient) {\n super();\n _defineProperty(this, \"rtmClient\", void 0);\n _defineProperty(this, \"roomId\", void 0);\n _defineProperty(this, \"userId\", void 0);\n _defineProperty(this, \"reconnectTimeout\", null);\n _defineProperty(this, \"chunkedMessages\", new Map());\n _defineProperty(this, \"cachedMessages\", []);\n _defineProperty(this, \"intervalId\", null);\n _defineProperty(this, \"handleRtmMessage\", evt => {\n if (!(evt.message instanceof Uint8Array)) {\n log(`rtm message not Uint8Array`, {\n channel: evt.channelName,\n publisher: evt.publisher,\n message: evt.message\n });\n return;\n }\n this.receiveChunkMessage(ChunkedUpdateMessage.fromBuffer(evt.message, \"\", evt.customType), evt.publisher);\n });\n _defineProperty(this, \"handleStatus\", connectionStatus => {\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 _defineProperty(this, \"handlePresence\", evt => {\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 this.rtmClient = rtmClient;\n }\n roomChannel() {\n return `r_${this.roomId}`;\n }\n userChannel(userId) {\n if (userId.length > 16) {\n userId = `${cyrb53(userId)}`;\n }\n return `${this.roomChannel()}_u_${userId}`;\n }\n\n /**\n * \u91CD\u65B0\u8BA2\u9605\u9891\u9053\n */\n async resubscribe() {\n try {\n await this.rtmClient.subscribe(this.roomChannel());\n await this.rtmClient.subscribe(this.userChannel(this.userId));\n } catch (error) {\n this.emit(\"error\", `rtm subscribe fail, ${error}`);\n log(`rtm subscribe fail`, {\n error: error.toString()\n }, \"error\");\n }\n }\n async initialize(roomId, userId) {\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) {\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, {\n customType: msg.customType\n }).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 async dispose() {\n this.rtmClient.removeEventListener(\"message\", this.handleRtmMessage);\n this.rtmClient.removeEventListener(\"presence\", this.handlePresence);\n // @ts-ignore\n this.rtmClient.removeEventListener(\"status\", this.handleStatus);\n await this.rtmClient.unsubscribe(this.roomChannel());\n await this.rtmClient.unsubscribe(this.userChannel(this.userId));\n window.clearInterval(this.intervalId);\n }\n receiveChunkMessage(msg, publisher) {\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).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 publish(buf, customType) {\n let target = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : \"\";\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 async userList() {\n const output = new Set();\n const result = await this.rtmClient.presence.whoNow(this.roomChannel(), \"MESSAGE\", {\n includedState: false\n });\n var nextPage = result.nextPage;\n result.occupants.forEach(userInfo => {\n const {\n userId\n } = 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 {\n userId\n } = userInfo;\n output.add(userId);\n });\n }\n return output;\n }\n}", "export const cyrb53 = function (str) {\n let seed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;\n let h1 = 0xdeadbeef ^ seed,\n 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 return 4294967296 * (2097151 & h2) + (h1 >>> 0);\n};", "function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }\nfunction _toPropertyKey(t) { var i = _toPrimitive(t, \"string\"); return \"symbol\" == typeof i ? i : i + \"\"; }\nfunction _toPrimitive(t, r) { if (\"object\" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || \"default\"); if (\"object\" != typeof i) return i; throw new TypeError(\"@@toPrimitive must return a primitive value.\"); } return (\"string\" === r ? String : Number)(t); }\nexport class ChunkedUpdateMessage {\n static fromObject(obj, target, customType) {\n const msg = new ChunkedUpdateMessage();\n msg.target = target;\n msg.customType = customType;\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 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 msg.buffer = new Uint8Array(obj.buf.length + sessionBuf.length + msg.header.buffer.byteLength);\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 return msg;\n }\n static fromBuffer(buf, target, customType) {\n const msg = new ChunkedUpdateMessage();\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 return msg;\n }\n get buf() {\n const len = this.header.getInt32(0);\n return this.buffer.slice(0, len);\n }\n get index() {\n return this.header.getUint8(8);\n }\n get length() {\n return this.header.getUint8(9);\n }\n get session() {\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 constructor() {\n _defineProperty(this, \"target\", void 0);\n _defineProperty(this, \"customType\", void 0);\n _defineProperty(this, \"buffer\", void 0);\n _defineProperty(this, \"header\", void 0);\n }\n}", "function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }\nfunction _toPropertyKey(t) { var i = _toPrimitive(t, \"string\"); return \"symbol\" == typeof i ? i : i + \"\"; }\nfunction _toPrimitive(t, r) { if (\"object\" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || \"default\"); if (\"object\" != typeof i) return i; throw new TypeError(\"@@toPrimitive must return a primitive value.\"); } return (\"string\" === r ? String : Number)(t); }\nimport { log } from \"@netless/forge-room\";\nimport EventEmitter from \"eventemitter3\";\nimport { v4 as uuidv4 } from \"uuid\";\nimport { cyrb53 } from \"./utils\";\nimport { ChunkedUpdateMessage } from \"./ChunkedUpdateMessage\";\nexport class RTMProvider_2_2 extends EventEmitter {\n constructor(rtmClient) {\n super();\n _defineProperty(this, \"rtmClient\", void 0);\n _defineProperty(this, \"roomId\", void 0);\n _defineProperty(this, \"userId\", void 0);\n _defineProperty(this, \"reconnectTimeout\", null);\n _defineProperty(this, \"chunkedMessages\", new Map());\n _defineProperty(this, \"cachedMessages\", []);\n _defineProperty(this, \"intervalId\", null);\n _defineProperty(this, \"handleRtmMessage\", evt => {\n if (!(evt.message instanceof Uint8Array)) {\n log(`rtm message not Uint8Array`, {\n channel: evt.channelName,\n publisher: evt.publisher,\n message: evt.message\n });\n return;\n }\n this.receiveChunkMessage(ChunkedUpdateMessage.fromBuffer(evt.message, \"\", evt.customType), evt.publisher);\n });\n _defineProperty(this, \"handleStatus\", connectionStatus => {\n log(`rtm status update`, {\n state: connectionStatus.state,\n reason: connectionStatus.reason,\n rtm: \"2.2\"\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 _defineProperty(this, \"handlePresence\", evt => {\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 this.rtmClient = rtmClient;\n }\n roomChannel() {\n return `r_${this.roomId}`;\n }\n userChannel(userId) {\n if (userId.length > 16) {\n userId = `${cyrb53(userId)}`;\n }\n return `${this.roomChannel()}_u_${userId}`;\n }\n async initialize(roomId, userId) {\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) {\n this.emit(\"error\", `rtm subscribe fail, ${error}`);\n log(`rtm subscribe fail`, {\n error: error.toString(),\n rtm: \"2.2\"\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, {\n customType: msg.customType\n }).catch(error => {\n log(`rtm publish failed`, {\n channel,\n code: error.code,\n rtm: \"2.2\"\n }, \"warning\");\n this.emit(\"error\", `rtm publish fail, ${error}`);\n });\n }\n }, 32);\n }\n\n /**\n * \u91CD\u65B0\u8BA2\u9605\u9891\u9053\n */\n async resubscribe() {\n try {\n await this.rtmClient.subscribe(this.roomChannel());\n await this.rtmClient.subscribe(this.userChannel(this.userId));\n } catch (error) {\n this.emit(\"error\", `rtm subscribe fail, ${error}`);\n log(`rtm subscribe fail`, {\n error: error.toString()\n }, \"error\");\n }\n }\n async dispose() {\n this.rtmClient.removeEventListener(\"message\", this.handleRtmMessage);\n this.rtmClient.removeEventListener(\"presence\", this.handlePresence);\n // @ts-ignore\n this.rtmClient.removeEventListener(\"status\", this.handleStatus);\n await this.rtmClient.unsubscribe(this.roomChannel());\n await this.rtmClient.unsubscribe(this.userChannel(this.userId));\n window.clearInterval(this.intervalId);\n }\n receiveChunkMessage(msg, publisher) {\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).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 publish(buf, customType) {\n let target = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : \"\";\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 async userList() {\n const output = new Set();\n const result = await this.rtmClient.presence.whoNow(this.roomChannel(), \"MESSAGE\", {\n includedState: false\n });\n var nextPage = result.nextPage;\n result.occupants.forEach(userInfo => {\n const {\n userId\n } = 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 {\n userId\n } = userInfo;\n output.add(userId);\n });\n }\n return output;\n }\n}"],
|
|
5
|
-
"mappings": ";AAGA,SAAS,WAAW;AACpB,OAAO,kBAAkB;AACzB,SAAS,MAAM,cAAc;;;ACLtB,IAAM,SAAS,SAAU,KAAK;AACnC,MAAI,OAAO,UAAU,SAAS,KAAK,UAAU,CAAC,MAAM,SAAY,UAAU,CAAC,IAAI;A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;AAAA,UACA;AAAA,QACF,GAAG,QAAQ,UAAU,CAAC;AACtB,iBAAS;AAAA,MACX;AAAA,IACF;AAAA,EACF;AAAA,EACA,MAAM,WAAW;AACf,UAAM,SAAS,oBAAI,IAAI;AACvB,UAAM,SAAS,MAAM,KAAK,UAAU,SAAS,OAAO,KAAK,YAAY,GAAG,WAAW;AAAA,MACjF,eAAe;AAAA,IACjB,CAAC;AACD,QAAI,WAAW,OAAO;AACtB,WAAO,UAAU,QAAQ,cAAY;AACnC,YAAM;AAAA,QACJ;AAAA,MACF,IAAI;AACJ,aAAO,IAAI,MAAM;AAAA,IACnB,CAAC;AACD,WAAO,UAAU;AACf,YAAMC,UAAS,MAAM,KAAK,UAAU,SAAS,OAAO,KAAK,YAAY,GAAG,WAAW;AAAA,QACjF,eAAe;AAAA,QACf,MAAM;AAAA,MACR,CAAC;AACD,iBAAWA,QAAO;AAClB,MAAAA,QAAO,UAAU,QAAQ,cAAY;AACnC,cAAM;AAAA,UACJ;AAAA,QACF,IAAI;AACJ,eAAO,IAAI,MAAM;AAAA,MACnB,CAAC;AAAA,IACH;AACA,WAAO;AAAA,EACT;AACF;",
|
|
4
|
+
"sourcesContent": ["function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }\nfunction _toPropertyKey(t) { var i = _toPrimitive(t, \"string\"); return \"symbol\" == typeof i ? i : i + \"\"; }\nfunction _toPrimitive(t, r) { if (\"object\" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || \"default\"); if (\"object\" != typeof i) return i; throw new TypeError(\"@@toPrimitive must return a primitive value.\"); } return (\"string\" === r ? String : Number)(t); }\nimport { log } from '@netless/forge-room';\nimport EventEmitter from 'eventemitter3';\nimport { v4 as uuidv4 } from 'uuid';\nimport { cyrb53 } from './utils';\nimport { ChunkedUpdateMessage } from './ChunkedUpdateMessage';\nexport class RTMProvider_2_1 extends EventEmitter {\n get calibrationTimestamp() {\n return this.rtmTimestamp + this.deviation;\n }\n constructor(rtmClient) {\n super();\n _defineProperty(this, \"rtmClient\", void 0);\n _defineProperty(this, \"roomId\", void 0);\n _defineProperty(this, \"userId\", void 0);\n _defineProperty(this, \"reconnectTimeout\", null);\n _defineProperty(this, \"chunkedMessages\", new Map());\n _defineProperty(this, \"cachedMessages\", []);\n _defineProperty(this, \"intervalId\", null);\n _defineProperty(this, \"deviation\", 0);\n _defineProperty(this, \"rtmTimestamp\", 0);\n _defineProperty(this, \"animationStartTimestamp\", void 0);\n _defineProperty(this, \"animationId\", void 0);\n _defineProperty(this, \"handleRtmMessage\", evt => {\n const isRoomChannel = evt.channelName.indexOf('_u_') < 0;\n if (!(evt.message instanceof Uint8Array)) {\n log('rtm message not Uint8Array', {\n channel: evt.channelName,\n publisher: evt.publisher,\n message: evt.message\n });\n return;\n }\n if (this.animationId) {\n cancelAnimationFrame(this.animationId);\n this.animationStartTimestamp = undefined;\n this.animationId = undefined;\n this.deviation = 0;\n }\n this.rtmTimestamp = evt.timestamp;\n this.animationId = requestAnimationFrame(this.calibrateAnimate);\n // console.log(\"rtm timestamp\", evt.timestamp, \"calibrationTimestamp\", this.calibrationTimestamp);\n this.receiveChunkMessage(ChunkedUpdateMessage.fromBuffer(evt.message, '', evt.customType), evt.publisher, isRoomChannel);\n });\n _defineProperty(this, \"calibrateAnimate\", timestamp => {\n if (this.animationStartTimestamp === undefined) {\n this.animationStartTimestamp = timestamp;\n }\n this.deviation = timestamp - this.animationStartTimestamp;\n if (this.animationId) {\n this.animationId = requestAnimationFrame(this.calibrateAnimate);\n }\n });\n _defineProperty(this, \"handleStatus\", connectionStatus => {\n log('rtm status update', {\n state: connectionStatus.state,\n reason: connectionStatus.reason\n });\n if (connectionStatus.state === 'RECONNECTING' && this.reconnectTimeout === null) {\n this.emit('connectionStatusChange', 'RECONNECTING');\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 _defineProperty(this, \"handlePresence\", evt => {\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 this.rtmClient = rtmClient;\n }\n roomChannel() {\n return `r_${this.roomId}`;\n }\n userChannel(userId) {\n if (userId.length > 16) {\n userId = `${cyrb53(userId)}`;\n }\n return `${this.roomChannel()}_u_${userId}`;\n }\n\n /**\n * \u91CD\u65B0\u8BA2\u9605\u9891\u9053\n */\n async resubscribe() {\n try {\n await this.rtmClient.subscribe(this.roomChannel());\n await this.rtmClient.subscribe(this.userChannel(this.userId));\n } catch (error) {\n this.emit('error', `rtm subscribe fail, ${error}`);\n log('rtm subscribe fail', {\n error: error.toString()\n }, 'error');\n }\n }\n async initialize(roomId, userId) {\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) {\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, {\n customType: msg.customType\n }).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 async dispose() {\n this.rtmClient.removeEventListener('message', this.handleRtmMessage);\n this.rtmClient.removeEventListener('presence', this.handlePresence);\n // @ts-ignore\n this.rtmClient.removeEventListener('status', this.handleStatus);\n await this.rtmClient.unsubscribe(this.roomChannel());\n await this.rtmClient.unsubscribe(this.userChannel(this.userId));\n window.clearInterval(this.intervalId);\n }\n receiveChunkMessage(msg, publisher, isRoomChannel) {\n if (msg.length === 1) {\n this.emit('message', msg.buf, publisher, msg.customType, isRoomChannel);\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).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, isRoomChannel);\n this.chunkedMessages.delete(msg.session);\n } else {\n this.chunkedMessages.set(msg.session, chunks);\n }\n }\n publish(buf, customType) {\n let target = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';\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 const 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 async userList() {\n const output = new Set();\n const result = await this.rtmClient.presence.whoNow(this.roomChannel(), 'MESSAGE', {\n includedState: false\n });\n let nextPage = result.nextPage;\n result.occupants.forEach(userInfo => {\n const {\n userId\n } = 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 {\n userId\n } = userInfo;\n output.add(userId);\n });\n }\n return output;\n }\n}", "export const cyrb53 = function (str) {\n let seed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;\n let h1 = 0xdeadbeef ^ seed,\n 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 return 4294967296 * (2097151 & h2) + (h1 >>> 0);\n};", "function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }\nfunction _toPropertyKey(t) { var i = _toPrimitive(t, \"string\"); return \"symbol\" == typeof i ? i : i + \"\"; }\nfunction _toPrimitive(t, r) { if (\"object\" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || \"default\"); if (\"object\" != typeof i) return i; throw new TypeError(\"@@toPrimitive must return a primitive value.\"); } return (\"string\" === r ? String : Number)(t); }\nexport class ChunkedUpdateMessage {\n static fromObject(obj, target, customType) {\n const msg = new ChunkedUpdateMessage();\n msg.target = target;\n msg.customType = customType;\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 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 msg.buffer = new Uint8Array(obj.buf.length + sessionBuf.length + msg.header.buffer.byteLength);\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 return msg;\n }\n static fromBuffer(buf, target, customType) {\n const msg = new ChunkedUpdateMessage();\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 return msg;\n }\n get buf() {\n const len = this.header.getInt32(0);\n return this.buffer.slice(0, len);\n }\n get index() {\n return this.header.getUint8(8);\n }\n get length() {\n return this.header.getUint8(9);\n }\n get session() {\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 constructor() {\n _defineProperty(this, \"target\", void 0);\n _defineProperty(this, \"customType\", void 0);\n _defineProperty(this, \"buffer\", void 0);\n _defineProperty(this, \"header\", void 0);\n }\n}", "function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }\nfunction _toPropertyKey(t) { var i = _toPrimitive(t, \"string\"); return \"symbol\" == typeof i ? i : i + \"\"; }\nfunction _toPrimitive(t, r) { if (\"object\" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || \"default\"); if (\"object\" != typeof i) return i; throw new TypeError(\"@@toPrimitive must return a primitive value.\"); } return (\"string\" === r ? String : Number)(t); }\nimport { log } from '@netless/forge-room';\nimport EventEmitter from 'eventemitter3';\nimport { v4 as uuidv4 } from 'uuid';\nimport { cyrb53 } from './utils';\nimport { ChunkedUpdateMessage } from './ChunkedUpdateMessage';\nexport class RTMProvider_2_2 extends EventEmitter {\n get calibrationTimestamp() {\n return this.rtmTimestamp + this.deviation;\n }\n constructor(rtmClient) {\n super();\n _defineProperty(this, \"rtmClient\", void 0);\n _defineProperty(this, \"roomId\", void 0);\n _defineProperty(this, \"userId\", void 0);\n _defineProperty(this, \"reconnectTimeout\", null);\n _defineProperty(this, \"chunkedMessages\", new Map());\n _defineProperty(this, \"cachedMessages\", []);\n _defineProperty(this, \"intervalId\", null);\n _defineProperty(this, \"deviation\", 0);\n _defineProperty(this, \"rtmTimestamp\", 0);\n _defineProperty(this, \"animationStartTimestamp\", void 0);\n _defineProperty(this, \"animationId\", void 0);\n _defineProperty(this, \"handleRtmMessage\", evt => {\n const isRoomChannel = evt.channelName.indexOf('_u_') >= 0;\n if (!(evt.message instanceof Uint8Array)) {\n log('rtm message not Uint8Array', {\n channel: evt.channelName,\n publisher: evt.publisher,\n message: evt.message\n });\n return;\n }\n if (this.animationId) {\n cancelAnimationFrame(this.animationId);\n this.animationStartTimestamp = undefined;\n this.animationId = undefined;\n this.deviation = 0;\n }\n this.rtmTimestamp = evt.timestamp;\n this.animationId = requestAnimationFrame(this.calibrateAnimate);\n this.receiveChunkMessage(ChunkedUpdateMessage.fromBuffer(evt.message, '', evt.customType), evt.publisher, isRoomChannel);\n });\n _defineProperty(this, \"calibrateAnimate\", timestamp => {\n if (this.animationStartTimestamp === undefined) {\n this.animationStartTimestamp = timestamp;\n }\n this.deviation = timestamp - this.animationStartTimestamp;\n if (this.animationId) {\n this.animationId = requestAnimationFrame(this.calibrateAnimate);\n }\n });\n _defineProperty(this, \"handleStatus\", connectionStatus => {\n log('rtm status update', {\n state: connectionStatus.state,\n reason: connectionStatus.reason,\n rtm: '2.2'\n });\n if (connectionStatus.state === 'RECONNECTING' && this.reconnectTimeout === null) {\n this.emit('connectionStatusChange', 'RECONNECTING');\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 _defineProperty(this, \"handlePresence\", evt => {\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 this.rtmClient = rtmClient;\n }\n roomChannel() {\n return `r_${this.roomId}`;\n }\n userChannel(userId) {\n if (userId.length > 16) {\n userId = `${cyrb53(userId)}`;\n }\n return `${this.roomChannel()}_u_${userId}`;\n }\n async initialize(roomId, userId) {\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) {\n this.emit('error', `rtm subscribe fail, ${error}`);\n log('rtm subscribe fail', {\n error: error.toString(),\n rtm: '2.2'\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, {\n customType: msg.customType\n }).catch(error => {\n log('rtm publish failed', {\n channel,\n code: error.code,\n rtm: '2.2'\n }, 'warning');\n this.emit('error', `rtm publish fail, ${error}`);\n });\n }\n }, 32);\n }\n\n /**\n * \u91CD\u65B0\u8BA2\u9605\u9891\u9053\n */\n async resubscribe() {\n try {\n await this.rtmClient.subscribe(this.roomChannel());\n await this.rtmClient.subscribe(this.userChannel(this.userId));\n } catch (error) {\n this.emit('error', `rtm subscribe fail, ${error}`);\n log('rtm subscribe fail', {\n error: error.toString()\n }, 'error');\n }\n }\n async dispose() {\n this.rtmClient.removeEventListener('message', this.handleRtmMessage);\n this.rtmClient.removeEventListener('presence', this.handlePresence);\n // @ts-ignore\n this.rtmClient.removeEventListener('status', this.handleStatus);\n await this.rtmClient.unsubscribe(this.roomChannel());\n await this.rtmClient.unsubscribe(this.userChannel(this.userId));\n window.clearInterval(this.intervalId);\n }\n receiveChunkMessage(msg, publisher, isRoomChannel) {\n if (msg.length === 1) {\n this.emit('message', msg.buf, publisher, msg.customType, isRoomChannel);\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).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, isRoomChannel);\n this.chunkedMessages.delete(msg.session);\n } else {\n this.chunkedMessages.set(msg.session, chunks);\n }\n }\n publish(buf, customType) {\n let target = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';\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 const 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 async userList() {\n const output = new Set();\n const result = await this.rtmClient.presence.whoNow(this.roomChannel(), 'MESSAGE', {\n includedState: false\n });\n let nextPage = result.nextPage;\n result.occupants.forEach(userInfo => {\n const {\n userId\n } = 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 {\n userId\n } = userInfo;\n output.add(userId);\n });\n }\n return output;\n }\n}"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,WAAW;AACpB,OAAO,kBAAkB;AACzB,SAAS,MAAM,cAAc;;;ACLtB,IAAM,SAAS,SAAU,KAAK;AACnC,MAAI,OAAO,UAAU,SAAS,KAAK,UAAU,CAAC,MAAM,SAAY,UAAU,CAAC,IAAI;AAC/E,MAAI,KAAK,aAAa,MACpB,KAAK,aAAa;AACpB,WAAS,IAAI,GAAG,IAAI,IAAI,IAAI,QAAQ,KAAK;AACvC,SAAK,IAAI,WAAW,CAAC;AACrB,SAAK,KAAK,KAAK,KAAK,IAAI,UAAU;AAClC,SAAK,KAAK,KAAK,KAAK,IAAI,UAAU;AAAA,EACpC;AACA,OAA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Q,KAAK,SAAS;AAAA,UACzD,QAAQ;AAAA,UACR;AAAA,UACA;AAAA,QACF,GAAG,QAAQ,UAAU,CAAC;AACtB,iBAAS;AAAA,MACX;AAAA,IACF;AAAA,EACF;AAAA,EACA,MAAM,WAAW;AACf,UAAM,SAAS,oBAAI,IAAI;AACvB,UAAM,SAAS,MAAM,KAAK,UAAU,SAAS,OAAO,KAAK,YAAY,GAAG,WAAW;AAAA,MACjF,eAAe;AAAA,IACjB,CAAC;AACD,QAAI,WAAW,OAAO;AACtB,WAAO,UAAU,QAAQ,cAAY;AACnC,YAAM;AAAA,QACJ;AAAA,MACF,IAAI;AACJ,aAAO,IAAI,MAAM;AAAA,IACnB,CAAC;AACD,WAAO,UAAU;AACf,YAAMC,UAAS,MAAM,KAAK,UAAU,SAAS,OAAO,KAAK,YAAY,GAAG,WAAW;AAAA,QACjF,eAAe;AAAA,QACf,MAAM;AAAA,MACR,CAAC;AACD,iBAAWA,QAAO;AAClB,MAAAA,QAAO,UAAU,QAAQ,cAAY;AACnC,cAAM;AAAA,UACJ;AAAA,QACF,IAAI;AACJ,eAAO,IAAI,MAAM;AAAA,MACnB,CAAC;AAAA,IACH;AACA,WAAO;AAAA,EACT;AACF;",
|
|
6
6
|
"names": ["_defineProperty", "_toPropertyKey", "_toPrimitive", "result", "log", "EventEmitter", "uuidv4", "_defineProperty", "_toPropertyKey", "_toPrimitive", "EventEmitter", "log", "uuidv4", "result"]
|
|
7
7
|
}
|
package/dist/rtm-provider.js
CHANGED
|
@@ -146,6 +146,9 @@ function _toPrimitive2(t, r) {
|
|
|
146
146
|
return ("string" === r ? String : Number)(t);
|
|
147
147
|
}
|
|
148
148
|
var RTMProvider_2_1 = class extends import_eventemitter3.default {
|
|
149
|
+
get calibrationTimestamp() {
|
|
150
|
+
return this.rtmTimestamp + this.deviation;
|
|
151
|
+
}
|
|
149
152
|
constructor(rtmClient) {
|
|
150
153
|
super();
|
|
151
154
|
_defineProperty2(this, "rtmClient", void 0);
|
|
@@ -155,25 +158,48 @@ var RTMProvider_2_1 = class extends import_eventemitter3.default {
|
|
|
155
158
|
_defineProperty2(this, "chunkedMessages", /* @__PURE__ */ new Map());
|
|
156
159
|
_defineProperty2(this, "cachedMessages", []);
|
|
157
160
|
_defineProperty2(this, "intervalId", null);
|
|
161
|
+
_defineProperty2(this, "deviation", 0);
|
|
162
|
+
_defineProperty2(this, "rtmTimestamp", 0);
|
|
163
|
+
_defineProperty2(this, "animationStartTimestamp", void 0);
|
|
164
|
+
_defineProperty2(this, "animationId", void 0);
|
|
158
165
|
_defineProperty2(this, "handleRtmMessage", (evt) => {
|
|
166
|
+
const isRoomChannel = evt.channelName.indexOf("_u_") < 0;
|
|
159
167
|
if (!(evt.message instanceof Uint8Array)) {
|
|
160
|
-
(0, import_forge_room.log)(
|
|
168
|
+
(0, import_forge_room.log)("rtm message not Uint8Array", {
|
|
161
169
|
channel: evt.channelName,
|
|
162
170
|
publisher: evt.publisher,
|
|
163
171
|
message: evt.message
|
|
164
172
|
});
|
|
165
173
|
return;
|
|
166
174
|
}
|
|
167
|
-
this.
|
|
175
|
+
if (this.animationId) {
|
|
176
|
+
cancelAnimationFrame(this.animationId);
|
|
177
|
+
this.animationStartTimestamp = void 0;
|
|
178
|
+
this.animationId = void 0;
|
|
179
|
+
this.deviation = 0;
|
|
180
|
+
}
|
|
181
|
+
this.rtmTimestamp = evt.timestamp;
|
|
182
|
+
this.animationId = requestAnimationFrame(this.calibrateAnimate);
|
|
183
|
+
this.receiveChunkMessage(ChunkedUpdateMessage.fromBuffer(evt.message, "", evt.customType), evt.publisher, isRoomChannel);
|
|
184
|
+
});
|
|
185
|
+
_defineProperty2(this, "calibrateAnimate", (timestamp) => {
|
|
186
|
+
if (this.animationStartTimestamp === void 0) {
|
|
187
|
+
this.animationStartTimestamp = timestamp;
|
|
188
|
+
}
|
|
189
|
+
this.deviation = timestamp - this.animationStartTimestamp;
|
|
190
|
+
if (this.animationId) {
|
|
191
|
+
this.animationId = requestAnimationFrame(this.calibrateAnimate);
|
|
192
|
+
}
|
|
168
193
|
});
|
|
169
194
|
_defineProperty2(this, "handleStatus", (connectionStatus) => {
|
|
170
|
-
(0, import_forge_room.log)(
|
|
195
|
+
(0, import_forge_room.log)("rtm status update", {
|
|
171
196
|
state: connectionStatus.state,
|
|
172
197
|
reason: connectionStatus.reason
|
|
173
198
|
});
|
|
174
199
|
if (connectionStatus.state === "RECONNECTING" && this.reconnectTimeout === null) {
|
|
200
|
+
this.emit("connectionStatusChange", "RECONNECTING");
|
|
175
201
|
this.reconnectTimeout = window.setTimeout(() => {
|
|
176
|
-
this.emit("error",
|
|
202
|
+
this.emit("error", "reconnecting timeout");
|
|
177
203
|
this.emit("connectionStatusChange", "DISCONNECTED");
|
|
178
204
|
}, 30 * 1e3);
|
|
179
205
|
} else if (connectionStatus.state === "CONNECTED") {
|
|
@@ -211,15 +237,15 @@ var RTMProvider_2_1 = class extends import_eventemitter3.default {
|
|
|
211
237
|
return `${this.roomChannel()}_u_${userId}`;
|
|
212
238
|
}
|
|
213
239
|
/**
|
|
214
|
-
|
|
215
|
-
|
|
240
|
+
* 重新订阅频道
|
|
241
|
+
*/
|
|
216
242
|
async resubscribe() {
|
|
217
243
|
try {
|
|
218
244
|
await this.rtmClient.subscribe(this.roomChannel());
|
|
219
245
|
await this.rtmClient.subscribe(this.userChannel(this.userId));
|
|
220
246
|
} catch (error) {
|
|
221
247
|
this.emit("error", `rtm subscribe fail, ${error}`);
|
|
222
|
-
(0, import_forge_room.log)(
|
|
248
|
+
(0, import_forge_room.log)("rtm subscribe fail", {
|
|
223
249
|
error: error.toString()
|
|
224
250
|
}, "error");
|
|
225
251
|
}
|
|
@@ -236,7 +262,7 @@ var RTMProvider_2_1 = class extends import_eventemitter3.default {
|
|
|
236
262
|
await this.rtmClient.subscribe(this.userChannel(this.userId));
|
|
237
263
|
} catch (error) {
|
|
238
264
|
this.emit("error", `rtm subscribe fail, ${error}`);
|
|
239
|
-
(0, import_forge_room.log)(
|
|
265
|
+
(0, import_forge_room.log)("rtm subscribe fail", {
|
|
240
266
|
error: error.toString()
|
|
241
267
|
}, "error");
|
|
242
268
|
}
|
|
@@ -247,7 +273,7 @@ var RTMProvider_2_1 = class extends import_eventemitter3.default {
|
|
|
247
273
|
this.rtmClient.publish(channel, msg.buffer, {
|
|
248
274
|
customType: msg.customType
|
|
249
275
|
}).catch((error) => {
|
|
250
|
-
(0, import_forge_room.log)(
|
|
276
|
+
(0, import_forge_room.log)("rtm publish failed", {
|
|
251
277
|
channel,
|
|
252
278
|
code: error.code
|
|
253
279
|
}, "warning");
|
|
@@ -264,9 +290,9 @@ var RTMProvider_2_1 = class extends import_eventemitter3.default {
|
|
|
264
290
|
await this.rtmClient.unsubscribe(this.userChannel(this.userId));
|
|
265
291
|
window.clearInterval(this.intervalId);
|
|
266
292
|
}
|
|
267
|
-
receiveChunkMessage(msg, publisher) {
|
|
293
|
+
receiveChunkMessage(msg, publisher, isRoomChannel) {
|
|
268
294
|
if (msg.length === 1) {
|
|
269
|
-
this.emit("message", msg.buf, publisher, msg.customType);
|
|
295
|
+
this.emit("message", msg.buf, publisher, msg.customType, isRoomChannel);
|
|
270
296
|
return;
|
|
271
297
|
}
|
|
272
298
|
const chunks = this.chunkedMessages.get(msg.session) || [];
|
|
@@ -279,7 +305,7 @@ var RTMProvider_2_1 = class extends import_eventemitter3.default {
|
|
|
279
305
|
output.set(buf, result.length);
|
|
280
306
|
return output;
|
|
281
307
|
}, new Uint8Array());
|
|
282
|
-
this.emit("message", buffer, publisher, msg.customType);
|
|
308
|
+
this.emit("message", buffer, publisher, msg.customType, isRoomChannel);
|
|
283
309
|
this.chunkedMessages.delete(msg.session);
|
|
284
310
|
} else {
|
|
285
311
|
this.chunkedMessages.set(msg.session, chunks);
|
|
@@ -298,7 +324,7 @@ var RTMProvider_2_1 = class extends import_eventemitter3.default {
|
|
|
298
324
|
}, target, customType));
|
|
299
325
|
} else {
|
|
300
326
|
const chunkSize = 16 * 1024 / Uint8Array.BYTES_PER_ELEMENT;
|
|
301
|
-
|
|
327
|
+
const len = Math.ceil(size / 16);
|
|
302
328
|
let index = 0;
|
|
303
329
|
while (index < len) {
|
|
304
330
|
this.cachedMessages.push(ChunkedUpdateMessage.fromObject({
|
|
@@ -316,7 +342,7 @@ var RTMProvider_2_1 = class extends import_eventemitter3.default {
|
|
|
316
342
|
const result = await this.rtmClient.presence.whoNow(this.roomChannel(), "MESSAGE", {
|
|
317
343
|
includedState: false
|
|
318
344
|
});
|
|
319
|
-
|
|
345
|
+
let nextPage = result.nextPage;
|
|
320
346
|
result.occupants.forEach((userInfo) => {
|
|
321
347
|
const {
|
|
322
348
|
userId
|
|
@@ -362,6 +388,9 @@ function _toPrimitive3(t, r) {
|
|
|
362
388
|
return ("string" === r ? String : Number)(t);
|
|
363
389
|
}
|
|
364
390
|
var RTMProvider_2_2 = class extends import_eventemitter32.default {
|
|
391
|
+
get calibrationTimestamp() {
|
|
392
|
+
return this.rtmTimestamp + this.deviation;
|
|
393
|
+
}
|
|
365
394
|
constructor(rtmClient) {
|
|
366
395
|
super();
|
|
367
396
|
_defineProperty3(this, "rtmClient", void 0);
|
|
@@ -371,26 +400,49 @@ var RTMProvider_2_2 = class extends import_eventemitter32.default {
|
|
|
371
400
|
_defineProperty3(this, "chunkedMessages", /* @__PURE__ */ new Map());
|
|
372
401
|
_defineProperty3(this, "cachedMessages", []);
|
|
373
402
|
_defineProperty3(this, "intervalId", null);
|
|
403
|
+
_defineProperty3(this, "deviation", 0);
|
|
404
|
+
_defineProperty3(this, "rtmTimestamp", 0);
|
|
405
|
+
_defineProperty3(this, "animationStartTimestamp", void 0);
|
|
406
|
+
_defineProperty3(this, "animationId", void 0);
|
|
374
407
|
_defineProperty3(this, "handleRtmMessage", (evt) => {
|
|
408
|
+
const isRoomChannel = evt.channelName.indexOf("_u_") >= 0;
|
|
375
409
|
if (!(evt.message instanceof Uint8Array)) {
|
|
376
|
-
(0, import_forge_room2.log)(
|
|
410
|
+
(0, import_forge_room2.log)("rtm message not Uint8Array", {
|
|
377
411
|
channel: evt.channelName,
|
|
378
412
|
publisher: evt.publisher,
|
|
379
413
|
message: evt.message
|
|
380
414
|
});
|
|
381
415
|
return;
|
|
382
416
|
}
|
|
383
|
-
this.
|
|
417
|
+
if (this.animationId) {
|
|
418
|
+
cancelAnimationFrame(this.animationId);
|
|
419
|
+
this.animationStartTimestamp = void 0;
|
|
420
|
+
this.animationId = void 0;
|
|
421
|
+
this.deviation = 0;
|
|
422
|
+
}
|
|
423
|
+
this.rtmTimestamp = evt.timestamp;
|
|
424
|
+
this.animationId = requestAnimationFrame(this.calibrateAnimate);
|
|
425
|
+
this.receiveChunkMessage(ChunkedUpdateMessage.fromBuffer(evt.message, "", evt.customType), evt.publisher, isRoomChannel);
|
|
426
|
+
});
|
|
427
|
+
_defineProperty3(this, "calibrateAnimate", (timestamp) => {
|
|
428
|
+
if (this.animationStartTimestamp === void 0) {
|
|
429
|
+
this.animationStartTimestamp = timestamp;
|
|
430
|
+
}
|
|
431
|
+
this.deviation = timestamp - this.animationStartTimestamp;
|
|
432
|
+
if (this.animationId) {
|
|
433
|
+
this.animationId = requestAnimationFrame(this.calibrateAnimate);
|
|
434
|
+
}
|
|
384
435
|
});
|
|
385
436
|
_defineProperty3(this, "handleStatus", (connectionStatus) => {
|
|
386
|
-
(0, import_forge_room2.log)(
|
|
437
|
+
(0, import_forge_room2.log)("rtm status update", {
|
|
387
438
|
state: connectionStatus.state,
|
|
388
439
|
reason: connectionStatus.reason,
|
|
389
440
|
rtm: "2.2"
|
|
390
441
|
});
|
|
391
442
|
if (connectionStatus.state === "RECONNECTING" && this.reconnectTimeout === null) {
|
|
443
|
+
this.emit("connectionStatusChange", "RECONNECTING");
|
|
392
444
|
this.reconnectTimeout = window.setTimeout(() => {
|
|
393
|
-
this.emit("error",
|
|
445
|
+
this.emit("error", "reconnecting timeout");
|
|
394
446
|
this.emit("connectionStatusChange", "DISCONNECTED");
|
|
395
447
|
}, 30 * 1e3);
|
|
396
448
|
} else if (connectionStatus.state === "CONNECTED") {
|
|
@@ -439,7 +491,7 @@ var RTMProvider_2_2 = class extends import_eventemitter32.default {
|
|
|
439
491
|
await this.rtmClient.subscribe(this.userChannel(this.userId));
|
|
440
492
|
} catch (error) {
|
|
441
493
|
this.emit("error", `rtm subscribe fail, ${error}`);
|
|
442
|
-
(0, import_forge_room2.log)(
|
|
494
|
+
(0, import_forge_room2.log)("rtm subscribe fail", {
|
|
443
495
|
error: error.toString(),
|
|
444
496
|
rtm: "2.2"
|
|
445
497
|
}, "error");
|
|
@@ -451,7 +503,7 @@ var RTMProvider_2_2 = class extends import_eventemitter32.default {
|
|
|
451
503
|
this.rtmClient.publish(channel, msg.buffer, {
|
|
452
504
|
customType: msg.customType
|
|
453
505
|
}).catch((error) => {
|
|
454
|
-
(0, import_forge_room2.log)(
|
|
506
|
+
(0, import_forge_room2.log)("rtm publish failed", {
|
|
455
507
|
channel,
|
|
456
508
|
code: error.code,
|
|
457
509
|
rtm: "2.2"
|
|
@@ -462,15 +514,15 @@ var RTMProvider_2_2 = class extends import_eventemitter32.default {
|
|
|
462
514
|
}, 32);
|
|
463
515
|
}
|
|
464
516
|
/**
|
|
465
|
-
|
|
466
|
-
|
|
517
|
+
* 重新订阅频道
|
|
518
|
+
*/
|
|
467
519
|
async resubscribe() {
|
|
468
520
|
try {
|
|
469
521
|
await this.rtmClient.subscribe(this.roomChannel());
|
|
470
522
|
await this.rtmClient.subscribe(this.userChannel(this.userId));
|
|
471
523
|
} catch (error) {
|
|
472
524
|
this.emit("error", `rtm subscribe fail, ${error}`);
|
|
473
|
-
(0, import_forge_room2.log)(
|
|
525
|
+
(0, import_forge_room2.log)("rtm subscribe fail", {
|
|
474
526
|
error: error.toString()
|
|
475
527
|
}, "error");
|
|
476
528
|
}
|
|
@@ -483,9 +535,9 @@ var RTMProvider_2_2 = class extends import_eventemitter32.default {
|
|
|
483
535
|
await this.rtmClient.unsubscribe(this.userChannel(this.userId));
|
|
484
536
|
window.clearInterval(this.intervalId);
|
|
485
537
|
}
|
|
486
|
-
receiveChunkMessage(msg, publisher) {
|
|
538
|
+
receiveChunkMessage(msg, publisher, isRoomChannel) {
|
|
487
539
|
if (msg.length === 1) {
|
|
488
|
-
this.emit("message", msg.buf, publisher, msg.customType);
|
|
540
|
+
this.emit("message", msg.buf, publisher, msg.customType, isRoomChannel);
|
|
489
541
|
return;
|
|
490
542
|
}
|
|
491
543
|
const chunks = this.chunkedMessages.get(msg.session) || [];
|
|
@@ -498,7 +550,7 @@ var RTMProvider_2_2 = class extends import_eventemitter32.default {
|
|
|
498
550
|
output.set(buf, result.length);
|
|
499
551
|
return output;
|
|
500
552
|
}, new Uint8Array());
|
|
501
|
-
this.emit("message", buffer, publisher, msg.customType);
|
|
553
|
+
this.emit("message", buffer, publisher, msg.customType, isRoomChannel);
|
|
502
554
|
this.chunkedMessages.delete(msg.session);
|
|
503
555
|
} else {
|
|
504
556
|
this.chunkedMessages.set(msg.session, chunks);
|
|
@@ -517,7 +569,7 @@ var RTMProvider_2_2 = class extends import_eventemitter32.default {
|
|
|
517
569
|
}, target, customType));
|
|
518
570
|
} else {
|
|
519
571
|
const chunkSize = 16 * 1024 / Uint8Array.BYTES_PER_ELEMENT;
|
|
520
|
-
|
|
572
|
+
const len = Math.ceil(size / 16);
|
|
521
573
|
let index = 0;
|
|
522
574
|
while (index < len) {
|
|
523
575
|
this.cachedMessages.push(ChunkedUpdateMessage.fromObject({
|
|
@@ -535,7 +587,7 @@ var RTMProvider_2_2 = class extends import_eventemitter32.default {
|
|
|
535
587
|
const result = await this.rtmClient.presence.whoNow(this.roomChannel(), "MESSAGE", {
|
|
536
588
|
includedState: false
|
|
537
589
|
});
|
|
538
|
-
|
|
590
|
+
let nextPage = result.nextPage;
|
|
539
591
|
result.occupants.forEach((userInfo) => {
|
|
540
592
|
const {
|
|
541
593
|
userId
|
package/dist/rtm-provider.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts", "../src/RTM_2_1.ts", "../src/utils.ts", "../src/ChunkedUpdateMessage.ts", "../src/RTM_2_2.ts"],
|
|
4
|
-
"sourcesContent": ["export { RTMProvider_2_1 } from \"./RTM_2_1\";\nexport { RTMProvider_2_2 } from \"./RTM_2_2\";", "function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }\nfunction _toPropertyKey(t) { var i = _toPrimitive(t, \"string\"); return \"symbol\" == typeof i ? i : i + \"\"; }\nfunction _toPrimitive(t, r) { if (\"object\" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || \"default\"); if (\"object\" != typeof i) return i; throw new TypeError(\"@@toPrimitive must return a primitive value.\"); } return (\"string\" === r ? String : Number)(t); }\nimport { log } from \"@netless/forge-room\";\nimport EventEmitter from \"eventemitter3\";\nimport { v4 as uuidv4 } from \"uuid\";\nimport { cyrb53 } from \"./utils\";\nimport { ChunkedUpdateMessage } from \"./ChunkedUpdateMessage\";\nexport class RTMProvider_2_1 extends EventEmitter {\n constructor(rtmClient) {\n super();\n _defineProperty(this, \"rtmClient\", void 0);\n _defineProperty(this, \"roomId\", void 0);\n _defineProperty(this, \"userId\", void 0);\n _defineProperty(this, \"reconnectTimeout\", null);\n _defineProperty(this, \"chunkedMessages\", new Map());\n _defineProperty(this, \"cachedMessages\", []);\n _defineProperty(this, \"intervalId\", null);\n _defineProperty(this, \"handleRtmMessage\", evt => {\n if (!(evt.message instanceof Uint8Array)) {\n log(`rtm message not Uint8Array`, {\n channel: evt.channelName,\n publisher: evt.publisher,\n message: evt.message\n });\n return;\n }\n this.receiveChunkMessage(ChunkedUpdateMessage.fromBuffer(evt.message, \"\", evt.customType), evt.publisher);\n });\n _defineProperty(this, \"handleStatus\", connectionStatus => {\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 _defineProperty(this, \"handlePresence\", evt => {\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 this.rtmClient = rtmClient;\n }\n roomChannel() {\n return `r_${this.roomId}`;\n }\n userChannel(userId) {\n if (userId.length > 16) {\n userId = `${cyrb53(userId)}`;\n }\n return `${this.roomChannel()}_u_${userId}`;\n }\n\n /**\n * \u91CD\u65B0\u8BA2\u9605\u9891\u9053\n */\n async resubscribe() {\n try {\n await this.rtmClient.subscribe(this.roomChannel());\n await this.rtmClient.subscribe(this.userChannel(this.userId));\n } catch (error) {\n this.emit(\"error\", `rtm subscribe fail, ${error}`);\n log(`rtm subscribe fail`, {\n error: error.toString()\n }, \"error\");\n }\n }\n async initialize(roomId, userId) {\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) {\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, {\n customType: msg.customType\n }).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 async dispose() {\n this.rtmClient.removeEventListener(\"message\", this.handleRtmMessage);\n this.rtmClient.removeEventListener(\"presence\", this.handlePresence);\n // @ts-ignore\n this.rtmClient.removeEventListener(\"status\", this.handleStatus);\n await this.rtmClient.unsubscribe(this.roomChannel());\n await this.rtmClient.unsubscribe(this.userChannel(this.userId));\n window.clearInterval(this.intervalId);\n }\n receiveChunkMessage(msg, publisher) {\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).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 publish(buf, customType) {\n let target = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : \"\";\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 async userList() {\n const output = new Set();\n const result = await this.rtmClient.presence.whoNow(this.roomChannel(), \"MESSAGE\", {\n includedState: false\n });\n var nextPage = result.nextPage;\n result.occupants.forEach(userInfo => {\n const {\n userId\n } = 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 {\n userId\n } = userInfo;\n output.add(userId);\n });\n }\n return output;\n }\n}", "export const cyrb53 = function (str) {\n let seed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;\n let h1 = 0xdeadbeef ^ seed,\n 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 return 4294967296 * (2097151 & h2) + (h1 >>> 0);\n};", "function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }\nfunction _toPropertyKey(t) { var i = _toPrimitive(t, \"string\"); return \"symbol\" == typeof i ? i : i + \"\"; }\nfunction _toPrimitive(t, r) { if (\"object\" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || \"default\"); if (\"object\" != typeof i) return i; throw new TypeError(\"@@toPrimitive must return a primitive value.\"); } return (\"string\" === r ? String : Number)(t); }\nexport class ChunkedUpdateMessage {\n static fromObject(obj, target, customType) {\n const msg = new ChunkedUpdateMessage();\n msg.target = target;\n msg.customType = customType;\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 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 msg.buffer = new Uint8Array(obj.buf.length + sessionBuf.length + msg.header.buffer.byteLength);\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 return msg;\n }\n static fromBuffer(buf, target, customType) {\n const msg = new ChunkedUpdateMessage();\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 return msg;\n }\n get buf() {\n const len = this.header.getInt32(0);\n return this.buffer.slice(0, len);\n }\n get index() {\n return this.header.getUint8(8);\n }\n get length() {\n return this.header.getUint8(9);\n }\n get session() {\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 constructor() {\n _defineProperty(this, \"target\", void 0);\n _defineProperty(this, \"customType\", void 0);\n _defineProperty(this, \"buffer\", void 0);\n _defineProperty(this, \"header\", void 0);\n }\n}", "function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }\nfunction _toPropertyKey(t) { var i = _toPrimitive(t, \"string\"); return \"symbol\" == typeof i ? i : i + \"\"; }\nfunction _toPrimitive(t, r) { if (\"object\" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || \"default\"); if (\"object\" != typeof i) return i; throw new TypeError(\"@@toPrimitive must return a primitive value.\"); } return (\"string\" === r ? String : Number)(t); }\nimport { log } from \"@netless/forge-room\";\nimport EventEmitter from \"eventemitter3\";\nimport { v4 as uuidv4 } from \"uuid\";\nimport { cyrb53 } from \"./utils\";\nimport { ChunkedUpdateMessage } from \"./ChunkedUpdateMessage\";\nexport class RTMProvider_2_2 extends EventEmitter {\n constructor(rtmClient) {\n super();\n _defineProperty(this, \"rtmClient\", void 0);\n _defineProperty(this, \"roomId\", void 0);\n _defineProperty(this, \"userId\", void 0);\n _defineProperty(this, \"reconnectTimeout\", null);\n _defineProperty(this, \"chunkedMessages\", new Map());\n _defineProperty(this, \"cachedMessages\", []);\n _defineProperty(this, \"intervalId\", null);\n _defineProperty(this, \"handleRtmMessage\", evt => {\n if (!(evt.message instanceof Uint8Array)) {\n log(`rtm message not Uint8Array`, {\n channel: evt.channelName,\n publisher: evt.publisher,\n message: evt.message\n });\n return;\n }\n this.receiveChunkMessage(ChunkedUpdateMessage.fromBuffer(evt.message, \"\", evt.customType), evt.publisher);\n });\n _defineProperty(this, \"handleStatus\", connectionStatus => {\n log(`rtm status update`, {\n state: connectionStatus.state,\n reason: connectionStatus.reason,\n rtm: \"2.2\"\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 _defineProperty(this, \"handlePresence\", evt => {\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 this.rtmClient = rtmClient;\n }\n roomChannel() {\n return `r_${this.roomId}`;\n }\n userChannel(userId) {\n if (userId.length > 16) {\n userId = `${cyrb53(userId)}`;\n }\n return `${this.roomChannel()}_u_${userId}`;\n }\n async initialize(roomId, userId) {\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) {\n this.emit(\"error\", `rtm subscribe fail, ${error}`);\n log(`rtm subscribe fail`, {\n error: error.toString(),\n rtm: \"2.2\"\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, {\n customType: msg.customType\n }).catch(error => {\n log(`rtm publish failed`, {\n channel,\n code: error.code,\n rtm: \"2.2\"\n }, \"warning\");\n this.emit(\"error\", `rtm publish fail, ${error}`);\n });\n }\n }, 32);\n }\n\n /**\n * \u91CD\u65B0\u8BA2\u9605\u9891\u9053\n */\n async resubscribe() {\n try {\n await this.rtmClient.subscribe(this.roomChannel());\n await this.rtmClient.subscribe(this.userChannel(this.userId));\n } catch (error) {\n this.emit(\"error\", `rtm subscribe fail, ${error}`);\n log(`rtm subscribe fail`, {\n error: error.toString()\n }, \"error\");\n }\n }\n async dispose() {\n this.rtmClient.removeEventListener(\"message\", this.handleRtmMessage);\n this.rtmClient.removeEventListener(\"presence\", this.handlePresence);\n // @ts-ignore\n this.rtmClient.removeEventListener(\"status\", this.handleStatus);\n await this.rtmClient.unsubscribe(this.roomChannel());\n await this.rtmClient.unsubscribe(this.userChannel(this.userId));\n window.clearInterval(this.intervalId);\n }\n receiveChunkMessage(msg, publisher) {\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).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 publish(buf, customType) {\n let target = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : \"\";\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 async userList() {\n const output = new Set();\n const result = await this.rtmClient.presence.whoNow(this.roomChannel(), \"MESSAGE\", {\n includedState: false\n });\n var nextPage = result.nextPage;\n result.occupants.forEach(userInfo => {\n const {\n userId\n } = 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 {\n userId\n } = userInfo;\n output.add(userId);\n });\n }\n return output;\n }\n}"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,wBAAoB;AACpB,2BAAyB;AACzB,kBAA6B;;;ACLtB,IAAM,SAAS,SAAU,KAAK;AACnC,MAAI,OAAO,UAAU,SAAS,KAAK,UAAU,CAAC,MAAM,SAAY,UAAU,CAAC,IAAI;AAC/E,MAAI,KAAK,aAAa,MACpB,KAAK,aAAa;AACpB,WAAS,IAAI,GAAG,IAAI,IAAI,IAAI,QAAQ,KAAK;AACvC,SAAK,IAAI,WAAW,CAAC;AACrB,SAAK,KAAK,KAAK,KAAK,IAAI,UAAU;AAClC,SAAK,KAAK,KAAK,KAAK,IAAI,UAAU;AAAA,EACpC;AACA,OAAK,KAAK,KAAK,KAAK,OAAO,IAAI,UAAU;AACzC,QAAM,KAAK,KAAK,KAAK,OAAO,IAAI,UAAU;AAC1C,OAAK,KAAK,KAAK,KAAK,OAAO,IAAI,UAAU;AACzC,QAAM,KAAK,KAAK,KAAK,OAAO,IAAI,UAAU;AAC1C,SAAO,cAAc,UAAU,OAAO,OAAO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AAK,YAAY,GAAG,WAAW;AAAA,QACjF,eAAe;AAAA,QACf,MAAM;AAAA,MACR,CAAC;AACD,iBAAWA,QAAO;AAClB,MAAAA,QAAO,UAAU,QAAQ,cAAY;AACnC,cAAM;AAAA,UACJ;AAAA,QACF,IAAI;AACJ,eAAO,IAAI,MAAM;AAAA,MACnB,CAAC;AAAA,IACH;AACA,WAAO;AAAA,EACT;AACF;",
|
|
4
|
+
"sourcesContent": ["export { RTMProvider_2_1 } from './RTM_2_1';\nexport { RTMProvider_2_2 } from './RTM_2_2';", "function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }\nfunction _toPropertyKey(t) { var i = _toPrimitive(t, \"string\"); return \"symbol\" == typeof i ? i : i + \"\"; }\nfunction _toPrimitive(t, r) { if (\"object\" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || \"default\"); if (\"object\" != typeof i) return i; throw new TypeError(\"@@toPrimitive must return a primitive value.\"); } return (\"string\" === r ? String : Number)(t); }\nimport { log } from '@netless/forge-room';\nimport EventEmitter from 'eventemitter3';\nimport { v4 as uuidv4 } from 'uuid';\nimport { cyrb53 } from './utils';\nimport { ChunkedUpdateMessage } from './ChunkedUpdateMessage';\nexport class RTMProvider_2_1 extends EventEmitter {\n get calibrationTimestamp() {\n return this.rtmTimestamp + this.deviation;\n }\n constructor(rtmClient) {\n super();\n _defineProperty(this, \"rtmClient\", void 0);\n _defineProperty(this, \"roomId\", void 0);\n _defineProperty(this, \"userId\", void 0);\n _defineProperty(this, \"reconnectTimeout\", null);\n _defineProperty(this, \"chunkedMessages\", new Map());\n _defineProperty(this, \"cachedMessages\", []);\n _defineProperty(this, \"intervalId\", null);\n _defineProperty(this, \"deviation\", 0);\n _defineProperty(this, \"rtmTimestamp\", 0);\n _defineProperty(this, \"animationStartTimestamp\", void 0);\n _defineProperty(this, \"animationId\", void 0);\n _defineProperty(this, \"handleRtmMessage\", evt => {\n const isRoomChannel = evt.channelName.indexOf('_u_') < 0;\n if (!(evt.message instanceof Uint8Array)) {\n log('rtm message not Uint8Array', {\n channel: evt.channelName,\n publisher: evt.publisher,\n message: evt.message\n });\n return;\n }\n if (this.animationId) {\n cancelAnimationFrame(this.animationId);\n this.animationStartTimestamp = undefined;\n this.animationId = undefined;\n this.deviation = 0;\n }\n this.rtmTimestamp = evt.timestamp;\n this.animationId = requestAnimationFrame(this.calibrateAnimate);\n // console.log(\"rtm timestamp\", evt.timestamp, \"calibrationTimestamp\", this.calibrationTimestamp);\n this.receiveChunkMessage(ChunkedUpdateMessage.fromBuffer(evt.message, '', evt.customType), evt.publisher, isRoomChannel);\n });\n _defineProperty(this, \"calibrateAnimate\", timestamp => {\n if (this.animationStartTimestamp === undefined) {\n this.animationStartTimestamp = timestamp;\n }\n this.deviation = timestamp - this.animationStartTimestamp;\n if (this.animationId) {\n this.animationId = requestAnimationFrame(this.calibrateAnimate);\n }\n });\n _defineProperty(this, \"handleStatus\", connectionStatus => {\n log('rtm status update', {\n state: connectionStatus.state,\n reason: connectionStatus.reason\n });\n if (connectionStatus.state === 'RECONNECTING' && this.reconnectTimeout === null) {\n this.emit('connectionStatusChange', 'RECONNECTING');\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 _defineProperty(this, \"handlePresence\", evt => {\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 this.rtmClient = rtmClient;\n }\n roomChannel() {\n return `r_${this.roomId}`;\n }\n userChannel(userId) {\n if (userId.length > 16) {\n userId = `${cyrb53(userId)}`;\n }\n return `${this.roomChannel()}_u_${userId}`;\n }\n\n /**\n * \u91CD\u65B0\u8BA2\u9605\u9891\u9053\n */\n async resubscribe() {\n try {\n await this.rtmClient.subscribe(this.roomChannel());\n await this.rtmClient.subscribe(this.userChannel(this.userId));\n } catch (error) {\n this.emit('error', `rtm subscribe fail, ${error}`);\n log('rtm subscribe fail', {\n error: error.toString()\n }, 'error');\n }\n }\n async initialize(roomId, userId) {\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) {\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, {\n customType: msg.customType\n }).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 async dispose() {\n this.rtmClient.removeEventListener('message', this.handleRtmMessage);\n this.rtmClient.removeEventListener('presence', this.handlePresence);\n // @ts-ignore\n this.rtmClient.removeEventListener('status', this.handleStatus);\n await this.rtmClient.unsubscribe(this.roomChannel());\n await this.rtmClient.unsubscribe(this.userChannel(this.userId));\n window.clearInterval(this.intervalId);\n }\n receiveChunkMessage(msg, publisher, isRoomChannel) {\n if (msg.length === 1) {\n this.emit('message', msg.buf, publisher, msg.customType, isRoomChannel);\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).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, isRoomChannel);\n this.chunkedMessages.delete(msg.session);\n } else {\n this.chunkedMessages.set(msg.session, chunks);\n }\n }\n publish(buf, customType) {\n let target = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';\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 const 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 async userList() {\n const output = new Set();\n const result = await this.rtmClient.presence.whoNow(this.roomChannel(), 'MESSAGE', {\n includedState: false\n });\n let nextPage = result.nextPage;\n result.occupants.forEach(userInfo => {\n const {\n userId\n } = 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 {\n userId\n } = userInfo;\n output.add(userId);\n });\n }\n return output;\n }\n}", "export const cyrb53 = function (str) {\n let seed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;\n let h1 = 0xdeadbeef ^ seed,\n 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 return 4294967296 * (2097151 & h2) + (h1 >>> 0);\n};", "function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }\nfunction _toPropertyKey(t) { var i = _toPrimitive(t, \"string\"); return \"symbol\" == typeof i ? i : i + \"\"; }\nfunction _toPrimitive(t, r) { if (\"object\" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || \"default\"); if (\"object\" != typeof i) return i; throw new TypeError(\"@@toPrimitive must return a primitive value.\"); } return (\"string\" === r ? String : Number)(t); }\nexport class ChunkedUpdateMessage {\n static fromObject(obj, target, customType) {\n const msg = new ChunkedUpdateMessage();\n msg.target = target;\n msg.customType = customType;\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 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 msg.buffer = new Uint8Array(obj.buf.length + sessionBuf.length + msg.header.buffer.byteLength);\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 return msg;\n }\n static fromBuffer(buf, target, customType) {\n const msg = new ChunkedUpdateMessage();\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 return msg;\n }\n get buf() {\n const len = this.header.getInt32(0);\n return this.buffer.slice(0, len);\n }\n get index() {\n return this.header.getUint8(8);\n }\n get length() {\n return this.header.getUint8(9);\n }\n get session() {\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 constructor() {\n _defineProperty(this, \"target\", void 0);\n _defineProperty(this, \"customType\", void 0);\n _defineProperty(this, \"buffer\", void 0);\n _defineProperty(this, \"header\", void 0);\n }\n}", "function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }\nfunction _toPropertyKey(t) { var i = _toPrimitive(t, \"string\"); return \"symbol\" == typeof i ? i : i + \"\"; }\nfunction _toPrimitive(t, r) { if (\"object\" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || \"default\"); if (\"object\" != typeof i) return i; throw new TypeError(\"@@toPrimitive must return a primitive value.\"); } return (\"string\" === r ? String : Number)(t); }\nimport { log } from '@netless/forge-room';\nimport EventEmitter from 'eventemitter3';\nimport { v4 as uuidv4 } from 'uuid';\nimport { cyrb53 } from './utils';\nimport { ChunkedUpdateMessage } from './ChunkedUpdateMessage';\nexport class RTMProvider_2_2 extends EventEmitter {\n get calibrationTimestamp() {\n return this.rtmTimestamp + this.deviation;\n }\n constructor(rtmClient) {\n super();\n _defineProperty(this, \"rtmClient\", void 0);\n _defineProperty(this, \"roomId\", void 0);\n _defineProperty(this, \"userId\", void 0);\n _defineProperty(this, \"reconnectTimeout\", null);\n _defineProperty(this, \"chunkedMessages\", new Map());\n _defineProperty(this, \"cachedMessages\", []);\n _defineProperty(this, \"intervalId\", null);\n _defineProperty(this, \"deviation\", 0);\n _defineProperty(this, \"rtmTimestamp\", 0);\n _defineProperty(this, \"animationStartTimestamp\", void 0);\n _defineProperty(this, \"animationId\", void 0);\n _defineProperty(this, \"handleRtmMessage\", evt => {\n const isRoomChannel = evt.channelName.indexOf('_u_') >= 0;\n if (!(evt.message instanceof Uint8Array)) {\n log('rtm message not Uint8Array', {\n channel: evt.channelName,\n publisher: evt.publisher,\n message: evt.message\n });\n return;\n }\n if (this.animationId) {\n cancelAnimationFrame(this.animationId);\n this.animationStartTimestamp = undefined;\n this.animationId = undefined;\n this.deviation = 0;\n }\n this.rtmTimestamp = evt.timestamp;\n this.animationId = requestAnimationFrame(this.calibrateAnimate);\n this.receiveChunkMessage(ChunkedUpdateMessage.fromBuffer(evt.message, '', evt.customType), evt.publisher, isRoomChannel);\n });\n _defineProperty(this, \"calibrateAnimate\", timestamp => {\n if (this.animationStartTimestamp === undefined) {\n this.animationStartTimestamp = timestamp;\n }\n this.deviation = timestamp - this.animationStartTimestamp;\n if (this.animationId) {\n this.animationId = requestAnimationFrame(this.calibrateAnimate);\n }\n });\n _defineProperty(this, \"handleStatus\", connectionStatus => {\n log('rtm status update', {\n state: connectionStatus.state,\n reason: connectionStatus.reason,\n rtm: '2.2'\n });\n if (connectionStatus.state === 'RECONNECTING' && this.reconnectTimeout === null) {\n this.emit('connectionStatusChange', 'RECONNECTING');\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 _defineProperty(this, \"handlePresence\", evt => {\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 this.rtmClient = rtmClient;\n }\n roomChannel() {\n return `r_${this.roomId}`;\n }\n userChannel(userId) {\n if (userId.length > 16) {\n userId = `${cyrb53(userId)}`;\n }\n return `${this.roomChannel()}_u_${userId}`;\n }\n async initialize(roomId, userId) {\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) {\n this.emit('error', `rtm subscribe fail, ${error}`);\n log('rtm subscribe fail', {\n error: error.toString(),\n rtm: '2.2'\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, {\n customType: msg.customType\n }).catch(error => {\n log('rtm publish failed', {\n channel,\n code: error.code,\n rtm: '2.2'\n }, 'warning');\n this.emit('error', `rtm publish fail, ${error}`);\n });\n }\n }, 32);\n }\n\n /**\n * \u91CD\u65B0\u8BA2\u9605\u9891\u9053\n */\n async resubscribe() {\n try {\n await this.rtmClient.subscribe(this.roomChannel());\n await this.rtmClient.subscribe(this.userChannel(this.userId));\n } catch (error) {\n this.emit('error', `rtm subscribe fail, ${error}`);\n log('rtm subscribe fail', {\n error: error.toString()\n }, 'error');\n }\n }\n async dispose() {\n this.rtmClient.removeEventListener('message', this.handleRtmMessage);\n this.rtmClient.removeEventListener('presence', this.handlePresence);\n // @ts-ignore\n this.rtmClient.removeEventListener('status', this.handleStatus);\n await this.rtmClient.unsubscribe(this.roomChannel());\n await this.rtmClient.unsubscribe(this.userChannel(this.userId));\n window.clearInterval(this.intervalId);\n }\n receiveChunkMessage(msg, publisher, isRoomChannel) {\n if (msg.length === 1) {\n this.emit('message', msg.buf, publisher, msg.customType, isRoomChannel);\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).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, isRoomChannel);\n this.chunkedMessages.delete(msg.session);\n } else {\n this.chunkedMessages.set(msg.session, chunks);\n }\n }\n publish(buf, customType) {\n let target = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';\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 const 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 async userList() {\n const output = new Set();\n const result = await this.rtmClient.presence.whoNow(this.roomChannel(), 'MESSAGE', {\n includedState: false\n });\n let nextPage = result.nextPage;\n result.occupants.forEach(userInfo => {\n const {\n userId\n } = 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 {\n userId\n } = userInfo;\n output.add(userId);\n });\n }\n return output;\n }\n}"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,wBAAoB;AACpB,2BAAyB;AACzB,kBAA6B;;;ACLtB,IAAM,SAAS,SAAU,KAAK;AACnC,MAAI,OAAO,UAAU,SAAS,KAAK,UAAU,CAAC,MAAM,SAAY,UAAU,CAAC,IAAI;AAC/E,MAAI,KAAK,aAAa,MACpB,KAAK,aAAa;AACpB,WAAS,IAAI,GAAG,IAAI,IAAI,IAAI,QAAQ,KAAK;AACvC,SAAK,IAAI,WAAW,CAAC;AACrB,SAAK,KAAK,KAAK,KAAK,IAAI,UAAU;AAClC,SAAK,KAAK,KAAK,KAAK,IAAI,UAAU;AAAA,EACpC;AACA,OAAK,KAAK,KAAK,KAAK,OAAO,IAAI,UAAU;AACzC,QAAM,KAAK,KAAK,KAAK,OAAO,IAAI,UAAU;AAC1C,OAAK,KAAK,KAAK,KAAK,OAAO,IAAI,UAAU;AACzC,QAAM,KAAK,KAAK,KAAK,OAAO,IAAI,UAAU;AAC1C,SAAO,cAAc,UAAU,OAAO,OAAO;AAC/C;;;ACdA,SAAS,gBAAgB,GAAG,GAAG,GAAG;AAAE,UAAQ,IAAI,eAAe,CAAC,MAAM,IAAI,OAAO,eAAe,GAAG,GAAG,EAA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,cAAY;AACnC,YAAM;AAAA,QACJ;AAAA,MACF,IAAI;AACJ,aAAO,IAAI,MAAM;AAAA,IACnB,CAAC;AACD,WAAO,UAAU;AACf,YAAMC,UAAS,MAAM,KAAK,UAAU,SAAS,OAAO,KAAK,YAAY,GAAG,WAAW;AAAA,QACjF,eAAe;AAAA,QACf,MAAM;AAAA,MACR,CAAC;AACD,iBAAWA,QAAO;AAClB,MAAAA,QAAO,UAAU,QAAQ,cAAY;AACnC,cAAM;AAAA,UACJ;AAAA,QACF,IAAI;AACJ,eAAO,IAAI,MAAM;AAAA,MACnB,CAAC;AAAA,IACH;AACA,WAAO;AAAA,EACT;AACF;",
|
|
6
6
|
"names": ["_defineProperty", "_toPropertyKey", "_toPrimitive", "EventEmitter", "uuidv4", "result", "import_forge_room", "import_eventemitter3", "import_uuid", "_defineProperty", "_toPropertyKey", "_toPrimitive", "EventEmitter", "uuidv4", "result"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netless/forge-rtm",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/rtm-provider.js",
|
|
6
6
|
"module": "dist/rtm-provider.esm.js",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"js-base64": "^3.7.7",
|
|
12
12
|
"eventemitter3": "^5.0.1",
|
|
13
13
|
"uuid": "^9.0.1",
|
|
14
|
-
"@netless/forge-room": "0.1.
|
|
14
|
+
"@netless/forge-room": "0.1.10"
|
|
15
15
|
},
|
|
16
16
|
"keywords": [],
|
|
17
17
|
"author": "",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
33
|
"dev": "onChange 'src/**/*' -- npm run build",
|
|
34
|
-
"build": "tsc --emitDeclarationOnly && node build.mjs"
|
|
34
|
+
"build": "pnpm lint && tsc --emitDeclarationOnly && node build.mjs",
|
|
35
|
+
"lint": "eslint src"
|
|
35
36
|
}
|
|
36
37
|
}
|