@quitting/core 1.0.1 → 1.0.2

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.
@@ -1 +1 @@
1
- {"version":3,"file":"call.d.ts","sourceRoot":"","sources":["../src/call.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAG/E,KAAK,SAAS,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAA;AAQnD,qBAAa,WAAY,SAAQ,YAAY;IACpC,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,QAAQ,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,CAAC,EAAE,MAAM,CAAA;IAE5B,OAAO,CAAC,IAAI,CAAM;IAClB,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,KAAK,CAAQ;IAGrB,OAAO,CAAC,gBAAgB,CAAmC;gBAE/C,IAAI,EAAE;QAChB,MAAM,EAAE,MAAM,CAAA;QACd,QAAQ,EAAE,QAAQ,CAAA;QAClB,QAAQ,EAAE,MAAM,CAAA;QAChB,QAAQ,EAAE,MAAM,CAAA;QAChB,KAAK,EAAE,MAAM,CAAA;QACb,SAAS,EAAE,MAAM,CAAA;QACjB,UAAU,EAAE,SAAS,EAAE,CAAA;KACxB;IAoBK,OAAO;IA8CP,aAAa,IAAI,OAAO,CAAC;QAAE,GAAG,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;IA8BnF,gBAAgB,CAAC,EAAE,EAAE,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EAAE,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC;IA+BhE,GAAG,CAAC,MAAM,GAAE,aAA2B,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAa/E"}
@@ -1,8 +1,8 @@
1
1
  import { Centrifuge as e } from "centrifuge";
2
- import { Room as t, Track as n } from "livekit-client";
2
+ import { Room as t, Track as n, setLogLevel as r } from "livekit-client";
3
3
  export * from "@quitting/contract";
4
4
  //#region src/events.ts
5
- var r = class {
5
+ var i = class {
6
6
  listeners = /* @__PURE__ */ new Map();
7
7
  on(e, t) {
8
8
  return this.listeners.has(e) || this.listeners.set(e, /* @__PURE__ */ new Set()), this.listeners.get(e).add(t), () => this.off(e, t);
@@ -21,13 +21,13 @@ var r = class {
21
21
  removeAllListeners() {
22
22
  this.listeners.clear();
23
23
  }
24
- }, i = class extends Error {
24
+ }, a = class extends Error {
25
25
  code;
26
26
  httpStatus;
27
27
  constructor(e, t, n) {
28
28
  super(n), this.name = "ApiError", this.code = e, this.httpStatus = t;
29
29
  }
30
- }, a = class {
30
+ }, o = class {
31
31
  apiBase;
32
32
  tokenGetter;
33
33
  constructor(e, t) {
@@ -37,8 +37,8 @@ var r = class {
37
37
  let n = `${this.apiBase}${e}`, r = {
38
38
  "Content-Type": "application/json",
39
39
  ...t.headers
40
- }, a = this.tokenGetter();
41
- a && (r.Authorization = `Bearer ${a}`), r["X-Trace-Id"] = crypto.randomUUID?.() || Math.random().toString(36).slice(2);
40
+ }, i = this.tokenGetter();
41
+ i && (r.Authorization = `Bearer ${i}`), r["X-Trace-Id"] = crypto.randomUUID?.() || Math.random().toString(36).slice(2);
42
42
  let o = await fetch(n, {
43
43
  ...t,
44
44
  headers: r
@@ -49,7 +49,7 @@ var r = class {
49
49
  let n = await o.json();
50
50
  n?.code && (e = Number(n.code)), n?.message && (t = n.message);
51
51
  } catch {}
52
- throw new i(e, o.status, t);
52
+ throw new a(e, o.status, t);
53
53
  }
54
54
  return o.json();
55
55
  }
@@ -206,7 +206,7 @@ var r = class {
206
206
  body: JSON.stringify({ md5: e })
207
207
  });
208
208
  }
209
- }, o = class {
209
+ }, s = class {
210
210
  transport;
211
211
  sessionToken = null;
212
212
  centrifugoToken = null;
@@ -259,7 +259,7 @@ var r = class {
259
259
  logout() {
260
260
  this.refreshTimer &&= (clearTimeout(this.refreshTimer), null), this.sessionToken = null, this.centrifugoToken = null;
261
261
  }
262
- }, s = class extends r {
262
+ }, c = class extends i {
263
263
  client = null;
264
264
  subscriptions = /* @__PURE__ */ new Map();
265
265
  refCount = /* @__PURE__ */ new Map();
@@ -378,7 +378,7 @@ var r = class {
378
378
  disconnect() {
379
379
  this.client &&= (this.client.disconnect(), null), this.subscriptions.clear(), this.currentState = "disconnected";
380
380
  }
381
- }, c = class extends r {
381
+ }, l = class extends i {
382
382
  callId;
383
383
  callType;
384
384
  roomName;
@@ -472,11 +472,25 @@ var r = class {
472
472
  } catch (e) {
473
473
  console.error("[im] callEnd 失败", e);
474
474
  }
475
- await this.room.disconnect(), this.emitSession("ended", { reason: t });
475
+ r("silent");
476
+ try {
477
+ await this.room.disconnect();
478
+ } finally {
479
+ r("warn");
480
+ }
481
+ this.emitSession("ended", { reason: t });
476
482
  }
477
483
  }
478
484
  async end(e) {
479
- this.ended || (this.ended = !0, await this.room.disconnect(), this.emitSession("ended", { reason: e }));
485
+ if (!this.ended) {
486
+ this.ended = !0, r("silent");
487
+ try {
488
+ await this.room.disconnect();
489
+ } finally {
490
+ r("warn");
491
+ }
492
+ this.emitSession("ended", { reason: e });
493
+ }
480
494
  }
481
495
  registerRpcMethod(e, t) {
482
496
  this.room.localParticipant.registerRpcMethod(e, (e) => t(e.payload));
@@ -506,7 +520,7 @@ var r = class {
506
520
  return this.token;
507
521
  }
508
522
  token;
509
- }, l = class {
523
+ }, u = class {
510
524
  transport;
511
525
  livekitWs;
512
526
  identity;
@@ -516,7 +530,7 @@ var r = class {
516
530
  this.transport = e, this.livekitWs = t, this.identity = n, this.iceServers = r;
517
531
  }
518
532
  async init(e, t) {
519
- let n = await this.transport.callInit(e, t), r = new c({
533
+ let n = await this.transport.callInit(e, t), r = new l({
520
534
  callId: n.callId,
521
535
  callType: t,
522
536
  roomName: n.roomName,
@@ -528,7 +542,7 @@ var r = class {
528
542
  return this.currentSession = r, r;
529
543
  }
530
544
  async accept(e, t) {
531
- let n = await this.transport.callAccept(e), r = new c({
545
+ let n = await this.transport.callAccept(e), r = new l({
532
546
  callId: e,
533
547
  callType: t,
534
548
  roomName: n.roomName,
@@ -555,7 +569,19 @@ var r = class {
555
569
  console.warn("[im] callEnd 失败(不阻塞)", e);
556
570
  }
557
571
  }
558
- }, u = class e extends r {
572
+ };
573
+ //#endregion
574
+ //#region src/meeting.ts
575
+ r("warn");
576
+ async function d(e) {
577
+ r("silent");
578
+ try {
579
+ await e.disconnect();
580
+ } finally {
581
+ r("warn");
582
+ }
583
+ }
584
+ var f = class e extends i {
559
585
  meetingId;
560
586
  title;
561
587
  roomName;
@@ -570,7 +596,7 @@ var r = class {
570
596
  sessionListeners = /* @__PURE__ */ new Map();
571
597
  membersCache = [];
572
598
  membersCacheAt = 0;
573
- static MEMBERS_CACHE_TTL = 2e3;
599
+ static MEMBERS_CACHE_TTL = 8e3;
574
600
  pendingAttach = /* @__PURE__ */ new Map();
575
601
  constructor(e) {
576
602
  super(), this.meetingId = e.meetingId, this.title = e.title, this.roomName = e.roomName, this.identity = e.identity, this.token = e.token, this.isHost = e.isHost, this.hostIdentity = e.hostIdentity, this.livekitWs = e.livekitWs, this.iceServers = e.iceServers, this.room = new t({
@@ -644,11 +670,11 @@ var r = class {
644
670
  } catch (e) {
645
671
  console.error("[im] meetingLeave 失败", e);
646
672
  }
647
- await this.room.disconnect(), this.emitSession("ended", {});
673
+ await d(this.room), this.emitSession("ended", {});
648
674
  }
649
675
  }
650
676
  async end() {
651
- this.ended || (this.ended = !0, await this.room.disconnect(), this.emitSession("ended", {}));
677
+ this.ended || (this.ended = !0, await d(this.room), this.emitSession("ended", {}));
652
678
  }
653
679
  getRemoteParticipants() {
654
680
  let e = [];
@@ -722,7 +748,7 @@ var r = class {
722
748
  console.error(`[im] session handler error: ${e}`, t);
723
749
  }
724
750
  }
725
- }, d = class {
751
+ }, p = class {
726
752
  transport;
727
753
  livekitWs;
728
754
  identity;
@@ -735,7 +761,7 @@ var r = class {
735
761
  let n = await this.transport.meetingCreate({
736
762
  inviteeUids: e,
737
763
  title: t
738
- }), r = new u({
764
+ }), r = new f({
739
765
  meetingId: n.meetingId,
740
766
  title: t,
741
767
  roomName: n.roomName,
@@ -759,7 +785,7 @@ var r = class {
759
785
  };
760
786
  }
761
787
  async join(e, t = "") {
762
- let n = await this.transport.meetingJoin(e), r = new u({
788
+ let n = await this.transport.meetingJoin(e), r = new f({
763
789
  meetingId: e,
764
790
  title: t,
765
791
  roomName: n.roomName,
@@ -781,7 +807,7 @@ var r = class {
781
807
  async respond(e, t, n) {
782
808
  let r = await this.transport.meetingRespond(e, t);
783
809
  if (t !== "accept" || !r?.token || !r?.roomName) return null;
784
- let i = new u({
810
+ let i = new f({
785
811
  meetingId: e,
786
812
  title: r.title || n || "",
787
813
  roomName: r.roomName,
@@ -824,7 +850,7 @@ var r = class {
824
850
  async getMembers(e = !1) {
825
851
  return this.currentSession ? this.currentSession.refreshMembers(this.transport, e) : [];
826
852
  }
827
- }, f = class {
853
+ }, m = class {
828
854
  transport;
829
855
  realtime;
830
856
  uid;
@@ -894,7 +920,7 @@ var r = class {
894
920
  dialogChannel(e) {
895
921
  return `dialog#${[this.uid, e].sort()[0]},${[this.uid, e].sort()[1]}`;
896
922
  }
897
- }, p = class {
923
+ }, h = class {
898
924
  transport;
899
925
  constructor(e) {
900
926
  this.transport = e;
@@ -922,7 +948,7 @@ var r = class {
922
948
  }
923
949
  return { mediaId: i.mediaId };
924
950
  }
925
- }, m = [
951
+ }, g = [
926
952
  "message",
927
953
  "message_preview",
928
954
  "message:revoked",
@@ -947,7 +973,7 @@ var r = class {
947
973
  "session:kicked",
948
974
  "connection:state",
949
975
  "presence:update"
950
- ], h = class extends r {
976
+ ], _ = class extends i {
951
977
  auth;
952
978
  transport;
953
979
  realtime;
@@ -964,7 +990,7 @@ var r = class {
964
990
  name = "";
965
991
  avatar = "";
966
992
  constructor(e) {
967
- super(), this.appId = e.appId, this.apiBase = e.apiBase, this.livekitWs = e.livekitWs, this.auth = new o(null), this.transport = new a(e.apiBase, () => this.auth.getToken()), this.auth = new o(this.transport), this.realtime = new s(e.centrifugoWs, async () => await this.auth.getCentrifugoToken(this.name, this.avatar));
993
+ super(), this.appId = e.appId, this.apiBase = e.apiBase, this.livekitWs = e.livekitWs, this.auth = new s(null), this.transport = new o(e.apiBase, () => this.auth.getToken()), this.auth = new s(this.transport), this.realtime = new c(e.centrifugoWs, async () => await this.auth.getCentrifugoToken(this.name, this.avatar));
968
994
  }
969
995
  async connect(e) {
970
996
  e.name && (this.name = e.name), e.avatar && (this.avatar = e.avatar);
@@ -977,7 +1003,7 @@ var r = class {
977
1003
  async initAfterAuth() {
978
1004
  await this.loadClientConfig();
979
1005
  let e = this.clientConfig?.iceServers ?? [];
980
- this.call = new l(this.transport, this.livekitWs, this.uid, e), this.meeting = new d(this.transport, this.livekitWs, this.uid, e), this.message = new f(this.transport, this.realtime, this.uid), this.media = new p(this.transport), await this.realtime.connect(this.uid);
1006
+ this.call = new u(this.transport, this.livekitWs, this.uid, e), this.meeting = new p(this.transport, this.livekitWs, this.uid, e), this.message = new m(this.transport, this.realtime, this.uid), this.media = new h(this.transport), await this.realtime.connect(this.uid);
981
1007
  try {
982
1008
  let e = await this.transport.getSessionState();
983
1009
  this.sessionState = e.state, this.emit("session:state", {
@@ -1035,7 +1061,7 @@ var r = class {
1035
1061
  }
1036
1062
  }
1037
1063
  forwardRealtimeEvents() {
1038
- for (let e of m) this.realtime.on(e, (t) => {
1064
+ for (let e of g) this.realtime.on(e, (t) => {
1039
1065
  this.emit(e, t);
1040
1066
  });
1041
1067
  }
@@ -1044,6 +1070,6 @@ var r = class {
1044
1070
  }
1045
1071
  };
1046
1072
  //#endregion
1047
- export { i as ApiError, o as AuthManager, l as CallController, c as CallSession, r as EventEmitter, h as ImClient, p as MediaUploader, d as MeetingController, u as MeetingSession, f as MessageController, s as RealtimeConnection, a as Transport };
1073
+ export { a as ApiError, s as AuthManager, u as CallController, l as CallSession, i as EventEmitter, _ as ImClient, h as MediaUploader, p as MeetingController, f as MeetingSession, m as MessageController, c as RealtimeConnection, o as Transport };
1048
1074
 
1049
1075
  //# sourceMappingURL=im-core.es.js.map