@netless/forge-rtm 0.1.10 → 0.1.12
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 +12 -5
- package/dist/RTM_2_1.d.ts.map +1 -1
- package/dist/RTM_2_2.d.ts +12 -5
- package/dist/RTM_2_2.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/rtm-provider.esm.js +108 -40
- package/dist/rtm-provider.esm.js.map +2 -2
- package/dist/rtm-provider.js +108 -40
- 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,23 @@ 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>;
|
|
26
|
+
private isForgeRoomChannel;
|
|
21
27
|
private handleRtmMessage;
|
|
28
|
+
private calibrateAnimate;
|
|
22
29
|
private handleStatus;
|
|
23
30
|
private handlePresence;
|
|
24
31
|
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,kBAAkB;IAI1B,OAAO,CAAC,gBAAgB,CAyBtB;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,23 @@ 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>;
|
|
26
|
+
private isForgeRoomChannel;
|
|
21
27
|
private handleRtmMessage;
|
|
28
|
+
private calibrateAnimate;
|
|
22
29
|
private handleStatus;
|
|
23
30
|
private handlePresence;
|
|
24
31
|
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,kBAAkB;IAI1B,OAAO,CAAC,gBAAgB,CAwBtB;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,53 @@ 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) => {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
+
try {
|
|
130
|
+
const isRoomChannel = evt.channelName.indexOf("_u_") < 0;
|
|
131
|
+
if (!(evt.message instanceof Uint8Array) || !this.isForgeRoomChannel(evt.channelName)) {
|
|
132
|
+
log("rtm message not Uint8Array", {
|
|
133
|
+
channel: evt.channelName,
|
|
134
|
+
publisher: evt.publisher
|
|
135
|
+
});
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
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
|
+
} catch (error) {
|
|
148
|
+
log("rtm handle message error", {
|
|
149
|
+
error: error.toString()
|
|
150
|
+
}, "error");
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
_defineProperty2(this, "calibrateAnimate", (timestamp) => {
|
|
154
|
+
if (this.animationStartTimestamp === void 0) {
|
|
155
|
+
this.animationStartTimestamp = timestamp;
|
|
156
|
+
}
|
|
157
|
+
this.deviation = timestamp - this.animationStartTimestamp;
|
|
158
|
+
if (this.animationId) {
|
|
159
|
+
this.animationId = requestAnimationFrame(this.calibrateAnimate);
|
|
129
160
|
}
|
|
130
|
-
this.receiveChunkMessage(ChunkedUpdateMessage.fromBuffer(evt.message, "", evt.customType), evt.publisher);
|
|
131
161
|
});
|
|
132
162
|
_defineProperty2(this, "handleStatus", (connectionStatus) => {
|
|
133
|
-
log(
|
|
163
|
+
log("rtm status update", {
|
|
134
164
|
state: connectionStatus.state,
|
|
135
165
|
reason: connectionStatus.reason
|
|
136
166
|
});
|
|
137
167
|
if (connectionStatus.state === "RECONNECTING" && this.reconnectTimeout === null) {
|
|
168
|
+
this.emit("connectionStatusChange", "RECONNECTING");
|
|
138
169
|
this.reconnectTimeout = window.setTimeout(() => {
|
|
139
|
-
this.emit("error",
|
|
170
|
+
this.emit("error", "reconnecting timeout");
|
|
140
171
|
this.emit("connectionStatusChange", "DISCONNECTED");
|
|
141
172
|
}, 30 * 1e3);
|
|
142
173
|
} else if (connectionStatus.state === "CONNECTED") {
|
|
@@ -174,15 +205,15 @@ var RTMProvider_2_1 = class extends EventEmitter {
|
|
|
174
205
|
return `${this.roomChannel()}_u_${userId}`;
|
|
175
206
|
}
|
|
176
207
|
/**
|
|
177
|
-
|
|
178
|
-
|
|
208
|
+
* 重新订阅频道
|
|
209
|
+
*/
|
|
179
210
|
async resubscribe() {
|
|
180
211
|
try {
|
|
181
212
|
await this.rtmClient.subscribe(this.roomChannel());
|
|
182
213
|
await this.rtmClient.subscribe(this.userChannel(this.userId));
|
|
183
214
|
} catch (error) {
|
|
184
215
|
this.emit("error", `rtm subscribe fail, ${error}`);
|
|
185
|
-
log(
|
|
216
|
+
log("rtm subscribe fail", {
|
|
186
217
|
error: error.toString()
|
|
187
218
|
}, "error");
|
|
188
219
|
}
|
|
@@ -199,7 +230,7 @@ var RTMProvider_2_1 = class extends EventEmitter {
|
|
|
199
230
|
await this.rtmClient.subscribe(this.userChannel(this.userId));
|
|
200
231
|
} catch (error) {
|
|
201
232
|
this.emit("error", `rtm subscribe fail, ${error}`);
|
|
202
|
-
log(
|
|
233
|
+
log("rtm subscribe fail", {
|
|
203
234
|
error: error.toString()
|
|
204
235
|
}, "error");
|
|
205
236
|
}
|
|
@@ -210,7 +241,7 @@ var RTMProvider_2_1 = class extends EventEmitter {
|
|
|
210
241
|
this.rtmClient.publish(channel, msg.buffer, {
|
|
211
242
|
customType: msg.customType
|
|
212
243
|
}).catch((error) => {
|
|
213
|
-
log(
|
|
244
|
+
log("rtm publish failed", {
|
|
214
245
|
channel,
|
|
215
246
|
code: error.code
|
|
216
247
|
}, "warning");
|
|
@@ -227,9 +258,12 @@ var RTMProvider_2_1 = class extends EventEmitter {
|
|
|
227
258
|
await this.rtmClient.unsubscribe(this.userChannel(this.userId));
|
|
228
259
|
window.clearInterval(this.intervalId);
|
|
229
260
|
}
|
|
230
|
-
|
|
261
|
+
isForgeRoomChannel(channel) {
|
|
262
|
+
return channel === this.roomChannel() || channel === this.userChannel(this.userId);
|
|
263
|
+
}
|
|
264
|
+
receiveChunkMessage(msg, publisher, isRoomChannel) {
|
|
231
265
|
if (msg.length === 1) {
|
|
232
|
-
this.emit("message", msg.buf, publisher, msg.customType);
|
|
266
|
+
this.emit("message", msg.buf, publisher, msg.customType, isRoomChannel);
|
|
233
267
|
return;
|
|
234
268
|
}
|
|
235
269
|
const chunks = this.chunkedMessages.get(msg.session) || [];
|
|
@@ -242,7 +276,7 @@ var RTMProvider_2_1 = class extends EventEmitter {
|
|
|
242
276
|
output.set(buf, result.length);
|
|
243
277
|
return output;
|
|
244
278
|
}, new Uint8Array());
|
|
245
|
-
this.emit("message", buffer, publisher, msg.customType);
|
|
279
|
+
this.emit("message", buffer, publisher, msg.customType, isRoomChannel);
|
|
246
280
|
this.chunkedMessages.delete(msg.session);
|
|
247
281
|
} else {
|
|
248
282
|
this.chunkedMessages.set(msg.session, chunks);
|
|
@@ -261,7 +295,7 @@ var RTMProvider_2_1 = class extends EventEmitter {
|
|
|
261
295
|
}, target, customType));
|
|
262
296
|
} else {
|
|
263
297
|
const chunkSize = 16 * 1024 / Uint8Array.BYTES_PER_ELEMENT;
|
|
264
|
-
|
|
298
|
+
const len = Math.ceil(size / 16);
|
|
265
299
|
let index = 0;
|
|
266
300
|
while (index < len) {
|
|
267
301
|
this.cachedMessages.push(ChunkedUpdateMessage.fromObject({
|
|
@@ -279,7 +313,7 @@ var RTMProvider_2_1 = class extends EventEmitter {
|
|
|
279
313
|
const result = await this.rtmClient.presence.whoNow(this.roomChannel(), "MESSAGE", {
|
|
280
314
|
includedState: false
|
|
281
315
|
});
|
|
282
|
-
|
|
316
|
+
let nextPage = result.nextPage;
|
|
283
317
|
result.occupants.forEach((userInfo) => {
|
|
284
318
|
const {
|
|
285
319
|
userId
|
|
@@ -325,6 +359,9 @@ function _toPrimitive3(t, r) {
|
|
|
325
359
|
return ("string" === r ? String : Number)(t);
|
|
326
360
|
}
|
|
327
361
|
var RTMProvider_2_2 = class extends EventEmitter2 {
|
|
362
|
+
get calibrationTimestamp() {
|
|
363
|
+
return this.rtmTimestamp + this.deviation;
|
|
364
|
+
}
|
|
328
365
|
constructor(rtmClient) {
|
|
329
366
|
super();
|
|
330
367
|
_defineProperty3(this, "rtmClient", void 0);
|
|
@@ -334,26 +371,54 @@ var RTMProvider_2_2 = class extends EventEmitter2 {
|
|
|
334
371
|
_defineProperty3(this, "chunkedMessages", /* @__PURE__ */ new Map());
|
|
335
372
|
_defineProperty3(this, "cachedMessages", []);
|
|
336
373
|
_defineProperty3(this, "intervalId", null);
|
|
374
|
+
_defineProperty3(this, "deviation", 0);
|
|
375
|
+
_defineProperty3(this, "rtmTimestamp", 0);
|
|
376
|
+
_defineProperty3(this, "animationStartTimestamp", void 0);
|
|
377
|
+
_defineProperty3(this, "animationId", void 0);
|
|
337
378
|
_defineProperty3(this, "handleRtmMessage", (evt) => {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
379
|
+
try {
|
|
380
|
+
const isRoomChannel = evt.channelName.indexOf("_u_") >= 0;
|
|
381
|
+
if (!(evt.message instanceof Uint8Array) || !this.isForgeRoomChannel(evt.channelName)) {
|
|
382
|
+
log2("rtm message not Uint8Array", {
|
|
383
|
+
channel: evt.channelName,
|
|
384
|
+
publisher: evt.publisher
|
|
385
|
+
});
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
if (this.animationId) {
|
|
389
|
+
cancelAnimationFrame(this.animationId);
|
|
390
|
+
this.animationStartTimestamp = void 0;
|
|
391
|
+
this.animationId = void 0;
|
|
392
|
+
this.deviation = 0;
|
|
393
|
+
}
|
|
394
|
+
this.rtmTimestamp = evt.timestamp;
|
|
395
|
+
this.animationId = requestAnimationFrame(this.calibrateAnimate);
|
|
396
|
+
this.receiveChunkMessage(ChunkedUpdateMessage.fromBuffer(evt.message, "", evt.customType), evt.publisher, isRoomChannel);
|
|
397
|
+
} catch (e) {
|
|
398
|
+
log2("rtm handle message error", {
|
|
399
|
+
error: e.toString()
|
|
400
|
+
}, "error");
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
_defineProperty3(this, "calibrateAnimate", (timestamp) => {
|
|
404
|
+
if (this.animationStartTimestamp === void 0) {
|
|
405
|
+
this.animationStartTimestamp = timestamp;
|
|
406
|
+
}
|
|
407
|
+
this.deviation = timestamp - this.animationStartTimestamp;
|
|
408
|
+
if (this.animationId) {
|
|
409
|
+
this.animationId = requestAnimationFrame(this.calibrateAnimate);
|
|
345
410
|
}
|
|
346
|
-
this.receiveChunkMessage(ChunkedUpdateMessage.fromBuffer(evt.message, "", evt.customType), evt.publisher);
|
|
347
411
|
});
|
|
348
412
|
_defineProperty3(this, "handleStatus", (connectionStatus) => {
|
|
349
|
-
log2(
|
|
413
|
+
log2("rtm status update", {
|
|
350
414
|
state: connectionStatus.state,
|
|
351
415
|
reason: connectionStatus.reason,
|
|
352
416
|
rtm: "2.2"
|
|
353
417
|
});
|
|
354
418
|
if (connectionStatus.state === "RECONNECTING" && this.reconnectTimeout === null) {
|
|
419
|
+
this.emit("connectionStatusChange", "RECONNECTING");
|
|
355
420
|
this.reconnectTimeout = window.setTimeout(() => {
|
|
356
|
-
this.emit("error",
|
|
421
|
+
this.emit("error", "reconnecting timeout");
|
|
357
422
|
this.emit("connectionStatusChange", "DISCONNECTED");
|
|
358
423
|
}, 30 * 1e3);
|
|
359
424
|
} else if (connectionStatus.state === "CONNECTED") {
|
|
@@ -402,7 +467,7 @@ var RTMProvider_2_2 = class extends EventEmitter2 {
|
|
|
402
467
|
await this.rtmClient.subscribe(this.userChannel(this.userId));
|
|
403
468
|
} catch (error) {
|
|
404
469
|
this.emit("error", `rtm subscribe fail, ${error}`);
|
|
405
|
-
log2(
|
|
470
|
+
log2("rtm subscribe fail", {
|
|
406
471
|
error: error.toString(),
|
|
407
472
|
rtm: "2.2"
|
|
408
473
|
}, "error");
|
|
@@ -414,7 +479,7 @@ var RTMProvider_2_2 = class extends EventEmitter2 {
|
|
|
414
479
|
this.rtmClient.publish(channel, msg.buffer, {
|
|
415
480
|
customType: msg.customType
|
|
416
481
|
}).catch((error) => {
|
|
417
|
-
log2(
|
|
482
|
+
log2("rtm publish failed", {
|
|
418
483
|
channel,
|
|
419
484
|
code: error.code,
|
|
420
485
|
rtm: "2.2"
|
|
@@ -425,15 +490,15 @@ var RTMProvider_2_2 = class extends EventEmitter2 {
|
|
|
425
490
|
}, 32);
|
|
426
491
|
}
|
|
427
492
|
/**
|
|
428
|
-
|
|
429
|
-
|
|
493
|
+
* 重新订阅频道
|
|
494
|
+
*/
|
|
430
495
|
async resubscribe() {
|
|
431
496
|
try {
|
|
432
497
|
await this.rtmClient.subscribe(this.roomChannel());
|
|
433
498
|
await this.rtmClient.subscribe(this.userChannel(this.userId));
|
|
434
499
|
} catch (error) {
|
|
435
500
|
this.emit("error", `rtm subscribe fail, ${error}`);
|
|
436
|
-
log2(
|
|
501
|
+
log2("rtm subscribe fail", {
|
|
437
502
|
error: error.toString()
|
|
438
503
|
}, "error");
|
|
439
504
|
}
|
|
@@ -446,9 +511,12 @@ var RTMProvider_2_2 = class extends EventEmitter2 {
|
|
|
446
511
|
await this.rtmClient.unsubscribe(this.userChannel(this.userId));
|
|
447
512
|
window.clearInterval(this.intervalId);
|
|
448
513
|
}
|
|
449
|
-
|
|
514
|
+
isForgeRoomChannel(channel) {
|
|
515
|
+
return channel === this.roomChannel() || channel === this.userChannel(this.userId);
|
|
516
|
+
}
|
|
517
|
+
receiveChunkMessage(msg, publisher, isRoomChannel) {
|
|
450
518
|
if (msg.length === 1) {
|
|
451
|
-
this.emit("message", msg.buf, publisher, msg.customType);
|
|
519
|
+
this.emit("message", msg.buf, publisher, msg.customType, isRoomChannel);
|
|
452
520
|
return;
|
|
453
521
|
}
|
|
454
522
|
const chunks = this.chunkedMessages.get(msg.session) || [];
|
|
@@ -461,7 +529,7 @@ var RTMProvider_2_2 = class extends EventEmitter2 {
|
|
|
461
529
|
output.set(buf, result.length);
|
|
462
530
|
return output;
|
|
463
531
|
}, new Uint8Array());
|
|
464
|
-
this.emit("message", buffer, publisher, msg.customType);
|
|
532
|
+
this.emit("message", buffer, publisher, msg.customType, isRoomChannel);
|
|
465
533
|
this.chunkedMessages.delete(msg.session);
|
|
466
534
|
} else {
|
|
467
535
|
this.chunkedMessages.set(msg.session, chunks);
|
|
@@ -480,7 +548,7 @@ var RTMProvider_2_2 = class extends EventEmitter2 {
|
|
|
480
548
|
}, target, customType));
|
|
481
549
|
} else {
|
|
482
550
|
const chunkSize = 16 * 1024 / Uint8Array.BYTES_PER_ELEMENT;
|
|
483
|
-
|
|
551
|
+
const len = Math.ceil(size / 16);
|
|
484
552
|
let index = 0;
|
|
485
553
|
while (index < len) {
|
|
486
554
|
this.cachedMessages.push(ChunkedUpdateMessage.fromObject({
|
|
@@ -498,7 +566,7 @@ var RTMProvider_2_2 = class extends EventEmitter2 {
|
|
|
498
566
|
const result = await this.rtmClient.presence.whoNow(this.roomChannel(), "MESSAGE", {
|
|
499
567
|
includedState: false
|
|
500
568
|
});
|
|
501
|
-
|
|
569
|
+
let nextPage = result.nextPage;
|
|
502
570
|
result.occupants.forEach((userInfo) => {
|
|
503
571
|
const {
|
|
504
572
|
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;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,g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AAW;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 try {\n const isRoomChannel = evt.channelName.indexOf('_u_') < 0;\n if (!(evt.message instanceof Uint8Array) || !this.isForgeRoomChannel(evt.channelName)) {\n log('rtm message not Uint8Array', {\n channel: evt.channelName,\n publisher: evt.publisher\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 } catch (error) {\n log('rtm handle message error', {\n error: error.toString()\n }, 'error');\n }\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 isForgeRoomChannel(channel) {\n return channel === this.roomChannel() || channel === this.userChannel(this.userId);\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 try {\n const isRoomChannel = evt.channelName.indexOf('_u_') >= 0;\n if (!(evt.message instanceof Uint8Array) || !this.isForgeRoomChannel(evt.channelName)) {\n log('rtm message not Uint8Array', {\n channel: evt.channelName,\n publisher: evt.publisher\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 } catch (e) {\n log('rtm handle message error', {\n error: e.toString()\n }, 'error');\n }\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 isForgeRoomChannel(channel) {\n return channel === this.roomChannel() || channel === this.userChannel(this.userId);\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,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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AO;AAAA,QACP;AAAA,MACF,GAAG,QAAQ,UAAU,CAAC;AAAA,IACxB,OAAO;AACL,YAAM,YAAY,KAAK,OAAO,WAAW;AACzC,YAAM,MAAM,KAAK,KAAK,OAAO,EAAE;AAC/B,UAAI,QAAQ;AACZ,aAAO,QAAQ,KAAK;AAClB,aAAK,eAAe,KAAK,qBAAqB,WAAW;AAAA,UACvD,KAAK,IAAI,MAAM,QAAQ,YAAY,QAAQ,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,53 @@ 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) => {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
+
try {
|
|
167
|
+
const isRoomChannel = evt.channelName.indexOf("_u_") < 0;
|
|
168
|
+
if (!(evt.message instanceof Uint8Array) || !this.isForgeRoomChannel(evt.channelName)) {
|
|
169
|
+
(0, import_forge_room.log)("rtm message not Uint8Array", {
|
|
170
|
+
channel: evt.channelName,
|
|
171
|
+
publisher: evt.publisher
|
|
172
|
+
});
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
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
|
+
} catch (error) {
|
|
185
|
+
(0, import_forge_room.log)("rtm handle message error", {
|
|
186
|
+
error: error.toString()
|
|
187
|
+
}, "error");
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
_defineProperty2(this, "calibrateAnimate", (timestamp) => {
|
|
191
|
+
if (this.animationStartTimestamp === void 0) {
|
|
192
|
+
this.animationStartTimestamp = timestamp;
|
|
193
|
+
}
|
|
194
|
+
this.deviation = timestamp - this.animationStartTimestamp;
|
|
195
|
+
if (this.animationId) {
|
|
196
|
+
this.animationId = requestAnimationFrame(this.calibrateAnimate);
|
|
166
197
|
}
|
|
167
|
-
this.receiveChunkMessage(ChunkedUpdateMessage.fromBuffer(evt.message, "", evt.customType), evt.publisher);
|
|
168
198
|
});
|
|
169
199
|
_defineProperty2(this, "handleStatus", (connectionStatus) => {
|
|
170
|
-
(0, import_forge_room.log)(
|
|
200
|
+
(0, import_forge_room.log)("rtm status update", {
|
|
171
201
|
state: connectionStatus.state,
|
|
172
202
|
reason: connectionStatus.reason
|
|
173
203
|
});
|
|
174
204
|
if (connectionStatus.state === "RECONNECTING" && this.reconnectTimeout === null) {
|
|
205
|
+
this.emit("connectionStatusChange", "RECONNECTING");
|
|
175
206
|
this.reconnectTimeout = window.setTimeout(() => {
|
|
176
|
-
this.emit("error",
|
|
207
|
+
this.emit("error", "reconnecting timeout");
|
|
177
208
|
this.emit("connectionStatusChange", "DISCONNECTED");
|
|
178
209
|
}, 30 * 1e3);
|
|
179
210
|
} else if (connectionStatus.state === "CONNECTED") {
|
|
@@ -211,15 +242,15 @@ var RTMProvider_2_1 = class extends import_eventemitter3.default {
|
|
|
211
242
|
return `${this.roomChannel()}_u_${userId}`;
|
|
212
243
|
}
|
|
213
244
|
/**
|
|
214
|
-
|
|
215
|
-
|
|
245
|
+
* 重新订阅频道
|
|
246
|
+
*/
|
|
216
247
|
async resubscribe() {
|
|
217
248
|
try {
|
|
218
249
|
await this.rtmClient.subscribe(this.roomChannel());
|
|
219
250
|
await this.rtmClient.subscribe(this.userChannel(this.userId));
|
|
220
251
|
} catch (error) {
|
|
221
252
|
this.emit("error", `rtm subscribe fail, ${error}`);
|
|
222
|
-
(0, import_forge_room.log)(
|
|
253
|
+
(0, import_forge_room.log)("rtm subscribe fail", {
|
|
223
254
|
error: error.toString()
|
|
224
255
|
}, "error");
|
|
225
256
|
}
|
|
@@ -236,7 +267,7 @@ var RTMProvider_2_1 = class extends import_eventemitter3.default {
|
|
|
236
267
|
await this.rtmClient.subscribe(this.userChannel(this.userId));
|
|
237
268
|
} catch (error) {
|
|
238
269
|
this.emit("error", `rtm subscribe fail, ${error}`);
|
|
239
|
-
(0, import_forge_room.log)(
|
|
270
|
+
(0, import_forge_room.log)("rtm subscribe fail", {
|
|
240
271
|
error: error.toString()
|
|
241
272
|
}, "error");
|
|
242
273
|
}
|
|
@@ -247,7 +278,7 @@ var RTMProvider_2_1 = class extends import_eventemitter3.default {
|
|
|
247
278
|
this.rtmClient.publish(channel, msg.buffer, {
|
|
248
279
|
customType: msg.customType
|
|
249
280
|
}).catch((error) => {
|
|
250
|
-
(0, import_forge_room.log)(
|
|
281
|
+
(0, import_forge_room.log)("rtm publish failed", {
|
|
251
282
|
channel,
|
|
252
283
|
code: error.code
|
|
253
284
|
}, "warning");
|
|
@@ -264,9 +295,12 @@ var RTMProvider_2_1 = class extends import_eventemitter3.default {
|
|
|
264
295
|
await this.rtmClient.unsubscribe(this.userChannel(this.userId));
|
|
265
296
|
window.clearInterval(this.intervalId);
|
|
266
297
|
}
|
|
267
|
-
|
|
298
|
+
isForgeRoomChannel(channel) {
|
|
299
|
+
return channel === this.roomChannel() || channel === this.userChannel(this.userId);
|
|
300
|
+
}
|
|
301
|
+
receiveChunkMessage(msg, publisher, isRoomChannel) {
|
|
268
302
|
if (msg.length === 1) {
|
|
269
|
-
this.emit("message", msg.buf, publisher, msg.customType);
|
|
303
|
+
this.emit("message", msg.buf, publisher, msg.customType, isRoomChannel);
|
|
270
304
|
return;
|
|
271
305
|
}
|
|
272
306
|
const chunks = this.chunkedMessages.get(msg.session) || [];
|
|
@@ -279,7 +313,7 @@ var RTMProvider_2_1 = class extends import_eventemitter3.default {
|
|
|
279
313
|
output.set(buf, result.length);
|
|
280
314
|
return output;
|
|
281
315
|
}, new Uint8Array());
|
|
282
|
-
this.emit("message", buffer, publisher, msg.customType);
|
|
316
|
+
this.emit("message", buffer, publisher, msg.customType, isRoomChannel);
|
|
283
317
|
this.chunkedMessages.delete(msg.session);
|
|
284
318
|
} else {
|
|
285
319
|
this.chunkedMessages.set(msg.session, chunks);
|
|
@@ -298,7 +332,7 @@ var RTMProvider_2_1 = class extends import_eventemitter3.default {
|
|
|
298
332
|
}, target, customType));
|
|
299
333
|
} else {
|
|
300
334
|
const chunkSize = 16 * 1024 / Uint8Array.BYTES_PER_ELEMENT;
|
|
301
|
-
|
|
335
|
+
const len = Math.ceil(size / 16);
|
|
302
336
|
let index = 0;
|
|
303
337
|
while (index < len) {
|
|
304
338
|
this.cachedMessages.push(ChunkedUpdateMessage.fromObject({
|
|
@@ -316,7 +350,7 @@ var RTMProvider_2_1 = class extends import_eventemitter3.default {
|
|
|
316
350
|
const result = await this.rtmClient.presence.whoNow(this.roomChannel(), "MESSAGE", {
|
|
317
351
|
includedState: false
|
|
318
352
|
});
|
|
319
|
-
|
|
353
|
+
let nextPage = result.nextPage;
|
|
320
354
|
result.occupants.forEach((userInfo) => {
|
|
321
355
|
const {
|
|
322
356
|
userId
|
|
@@ -362,6 +396,9 @@ function _toPrimitive3(t, r) {
|
|
|
362
396
|
return ("string" === r ? String : Number)(t);
|
|
363
397
|
}
|
|
364
398
|
var RTMProvider_2_2 = class extends import_eventemitter32.default {
|
|
399
|
+
get calibrationTimestamp() {
|
|
400
|
+
return this.rtmTimestamp + this.deviation;
|
|
401
|
+
}
|
|
365
402
|
constructor(rtmClient) {
|
|
366
403
|
super();
|
|
367
404
|
_defineProperty3(this, "rtmClient", void 0);
|
|
@@ -371,26 +408,54 @@ var RTMProvider_2_2 = class extends import_eventemitter32.default {
|
|
|
371
408
|
_defineProperty3(this, "chunkedMessages", /* @__PURE__ */ new Map());
|
|
372
409
|
_defineProperty3(this, "cachedMessages", []);
|
|
373
410
|
_defineProperty3(this, "intervalId", null);
|
|
411
|
+
_defineProperty3(this, "deviation", 0);
|
|
412
|
+
_defineProperty3(this, "rtmTimestamp", 0);
|
|
413
|
+
_defineProperty3(this, "animationStartTimestamp", void 0);
|
|
414
|
+
_defineProperty3(this, "animationId", void 0);
|
|
374
415
|
_defineProperty3(this, "handleRtmMessage", (evt) => {
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
416
|
+
try {
|
|
417
|
+
const isRoomChannel = evt.channelName.indexOf("_u_") >= 0;
|
|
418
|
+
if (!(evt.message instanceof Uint8Array) || !this.isForgeRoomChannel(evt.channelName)) {
|
|
419
|
+
(0, import_forge_room2.log)("rtm message not Uint8Array", {
|
|
420
|
+
channel: evt.channelName,
|
|
421
|
+
publisher: evt.publisher
|
|
422
|
+
});
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
if (this.animationId) {
|
|
426
|
+
cancelAnimationFrame(this.animationId);
|
|
427
|
+
this.animationStartTimestamp = void 0;
|
|
428
|
+
this.animationId = void 0;
|
|
429
|
+
this.deviation = 0;
|
|
430
|
+
}
|
|
431
|
+
this.rtmTimestamp = evt.timestamp;
|
|
432
|
+
this.animationId = requestAnimationFrame(this.calibrateAnimate);
|
|
433
|
+
this.receiveChunkMessage(ChunkedUpdateMessage.fromBuffer(evt.message, "", evt.customType), evt.publisher, isRoomChannel);
|
|
434
|
+
} catch (e) {
|
|
435
|
+
(0, import_forge_room2.log)("rtm handle message error", {
|
|
436
|
+
error: e.toString()
|
|
437
|
+
}, "error");
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
_defineProperty3(this, "calibrateAnimate", (timestamp) => {
|
|
441
|
+
if (this.animationStartTimestamp === void 0) {
|
|
442
|
+
this.animationStartTimestamp = timestamp;
|
|
443
|
+
}
|
|
444
|
+
this.deviation = timestamp - this.animationStartTimestamp;
|
|
445
|
+
if (this.animationId) {
|
|
446
|
+
this.animationId = requestAnimationFrame(this.calibrateAnimate);
|
|
382
447
|
}
|
|
383
|
-
this.receiveChunkMessage(ChunkedUpdateMessage.fromBuffer(evt.message, "", evt.customType), evt.publisher);
|
|
384
448
|
});
|
|
385
449
|
_defineProperty3(this, "handleStatus", (connectionStatus) => {
|
|
386
|
-
(0, import_forge_room2.log)(
|
|
450
|
+
(0, import_forge_room2.log)("rtm status update", {
|
|
387
451
|
state: connectionStatus.state,
|
|
388
452
|
reason: connectionStatus.reason,
|
|
389
453
|
rtm: "2.2"
|
|
390
454
|
});
|
|
391
455
|
if (connectionStatus.state === "RECONNECTING" && this.reconnectTimeout === null) {
|
|
456
|
+
this.emit("connectionStatusChange", "RECONNECTING");
|
|
392
457
|
this.reconnectTimeout = window.setTimeout(() => {
|
|
393
|
-
this.emit("error",
|
|
458
|
+
this.emit("error", "reconnecting timeout");
|
|
394
459
|
this.emit("connectionStatusChange", "DISCONNECTED");
|
|
395
460
|
}, 30 * 1e3);
|
|
396
461
|
} else if (connectionStatus.state === "CONNECTED") {
|
|
@@ -439,7 +504,7 @@ var RTMProvider_2_2 = class extends import_eventemitter32.default {
|
|
|
439
504
|
await this.rtmClient.subscribe(this.userChannel(this.userId));
|
|
440
505
|
} catch (error) {
|
|
441
506
|
this.emit("error", `rtm subscribe fail, ${error}`);
|
|
442
|
-
(0, import_forge_room2.log)(
|
|
507
|
+
(0, import_forge_room2.log)("rtm subscribe fail", {
|
|
443
508
|
error: error.toString(),
|
|
444
509
|
rtm: "2.2"
|
|
445
510
|
}, "error");
|
|
@@ -451,7 +516,7 @@ var RTMProvider_2_2 = class extends import_eventemitter32.default {
|
|
|
451
516
|
this.rtmClient.publish(channel, msg.buffer, {
|
|
452
517
|
customType: msg.customType
|
|
453
518
|
}).catch((error) => {
|
|
454
|
-
(0, import_forge_room2.log)(
|
|
519
|
+
(0, import_forge_room2.log)("rtm publish failed", {
|
|
455
520
|
channel,
|
|
456
521
|
code: error.code,
|
|
457
522
|
rtm: "2.2"
|
|
@@ -462,15 +527,15 @@ var RTMProvider_2_2 = class extends import_eventemitter32.default {
|
|
|
462
527
|
}, 32);
|
|
463
528
|
}
|
|
464
529
|
/**
|
|
465
|
-
|
|
466
|
-
|
|
530
|
+
* 重新订阅频道
|
|
531
|
+
*/
|
|
467
532
|
async resubscribe() {
|
|
468
533
|
try {
|
|
469
534
|
await this.rtmClient.subscribe(this.roomChannel());
|
|
470
535
|
await this.rtmClient.subscribe(this.userChannel(this.userId));
|
|
471
536
|
} catch (error) {
|
|
472
537
|
this.emit("error", `rtm subscribe fail, ${error}`);
|
|
473
|
-
(0, import_forge_room2.log)(
|
|
538
|
+
(0, import_forge_room2.log)("rtm subscribe fail", {
|
|
474
539
|
error: error.toString()
|
|
475
540
|
}, "error");
|
|
476
541
|
}
|
|
@@ -483,9 +548,12 @@ var RTMProvider_2_2 = class extends import_eventemitter32.default {
|
|
|
483
548
|
await this.rtmClient.unsubscribe(this.userChannel(this.userId));
|
|
484
549
|
window.clearInterval(this.intervalId);
|
|
485
550
|
}
|
|
486
|
-
|
|
551
|
+
isForgeRoomChannel(channel) {
|
|
552
|
+
return channel === this.roomChannel() || channel === this.userChannel(this.userId);
|
|
553
|
+
}
|
|
554
|
+
receiveChunkMessage(msg, publisher, isRoomChannel) {
|
|
487
555
|
if (msg.length === 1) {
|
|
488
|
-
this.emit("message", msg.buf, publisher, msg.customType);
|
|
556
|
+
this.emit("message", msg.buf, publisher, msg.customType, isRoomChannel);
|
|
489
557
|
return;
|
|
490
558
|
}
|
|
491
559
|
const chunks = this.chunkedMessages.get(msg.session) || [];
|
|
@@ -498,7 +566,7 @@ var RTMProvider_2_2 = class extends import_eventemitter32.default {
|
|
|
498
566
|
output.set(buf, result.length);
|
|
499
567
|
return output;
|
|
500
568
|
}, new Uint8Array());
|
|
501
|
-
this.emit("message", buffer, publisher, msg.customType);
|
|
569
|
+
this.emit("message", buffer, publisher, msg.customType, isRoomChannel);
|
|
502
570
|
this.chunkedMessages.delete(msg.session);
|
|
503
571
|
} else {
|
|
504
572
|
this.chunkedMessages.set(msg.session, chunks);
|
|
@@ -517,7 +585,7 @@ var RTMProvider_2_2 = class extends import_eventemitter32.default {
|
|
|
517
585
|
}, target, customType));
|
|
518
586
|
} else {
|
|
519
587
|
const chunkSize = 16 * 1024 / Uint8Array.BYTES_PER_ELEMENT;
|
|
520
|
-
|
|
588
|
+
const len = Math.ceil(size / 16);
|
|
521
589
|
let index = 0;
|
|
522
590
|
while (index < len) {
|
|
523
591
|
this.cachedMessages.push(ChunkedUpdateMessage.fromObject({
|
|
@@ -535,7 +603,7 @@ var RTMProvider_2_2 = class extends import_eventemitter32.default {
|
|
|
535
603
|
const result = await this.rtmClient.presence.whoNow(this.roomChannel(), "MESSAGE", {
|
|
536
604
|
includedState: false
|
|
537
605
|
});
|
|
538
|
-
|
|
606
|
+
let nextPage = result.nextPage;
|
|
539
607
|
result.occupants.forEach((userInfo) => {
|
|
540
608
|
const {
|
|
541
609
|
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;AAC/C;;;ACdA,SAAS,gBAAgB,GAAG,GAAG,GAAG;AAAE,UAAQ,IAAI,eAAe,CAAC,MAAM,IAAI,OAAO,eAAe,GAAG,GAAG,EAAE,OAAO,GAAG,YAAY,MAAI,cAAc,MAAI,UAAU,KAAG,CAAC,IAAI,EAAE,CAAC,IAAI,GAAG;AAAG;AACnL,SAAS,eAAe,GAAG;AAAE,MAAI,IAAI,aAAa,GAAG,QAAQ;AAAG,SAAO,YAAY,OAAO,IAAI,IAAI,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export { 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 try {\n const isRoomChannel = evt.channelName.indexOf('_u_') < 0;\n if (!(evt.message instanceof Uint8Array) || !this.isForgeRoomChannel(evt.channelName)) {\n log('rtm message not Uint8Array', {\n channel: evt.channelName,\n publisher: evt.publisher\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 } catch (error) {\n log('rtm handle message error', {\n error: error.toString()\n }, 'error');\n }\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 isForgeRoomChannel(channel) {\n return channel === this.roomChannel() || channel === this.userChannel(this.userId);\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 try {\n const isRoomChannel = evt.channelName.indexOf('_u_') >= 0;\n if (!(evt.message instanceof Uint8Array) || !this.isForgeRoomChannel(evt.channelName)) {\n log('rtm message not Uint8Array', {\n channel: evt.channelName,\n publisher: evt.publisher\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 } catch (e) {\n log('rtm handle message error', {\n error: e.toString()\n }, 'error');\n }\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 isForgeRoomChannel(channel) {\n return channel === this.roomChannel() || channel === this.userChannel(this.userId);\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,EAAE,OAAO,GAAG,YAAY,MAAI,cAAc,MAAI,UAAU,KAA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KAAK;AAClB,aAAK,eAAe,KAAK,qBAAqB,WAAW;AAAA,UACvD,KAAK,IAAI,MAAM,QAAQ,YAAY,QAAQ,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", "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.12",
|
|
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.12-alpha.0"
|
|
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
|
}
|