@quitting/core 1.0.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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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AAE,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
  }
@@ -95,6 +95,9 @@ var r = class {
95
95
  usersByExternal(e) {
96
96
  return this.request(`/users/by-external?ids=${e.map(encodeURIComponent).join(",")}`);
97
97
  }
98
+ listUsers() {
99
+ return this.request("/users");
100
+ }
98
101
  callInit(e, t) {
99
102
  return this.request("/call/init", {
100
103
  method: "POST",
@@ -206,7 +209,7 @@ var r = class {
206
209
  body: JSON.stringify({ md5: e })
207
210
  });
208
211
  }
209
- }, o = class {
212
+ }, s = class {
210
213
  transport;
211
214
  sessionToken = null;
212
215
  centrifugoToken = null;
@@ -259,7 +262,7 @@ var r = class {
259
262
  logout() {
260
263
  this.refreshTimer &&= (clearTimeout(this.refreshTimer), null), this.sessionToken = null, this.centrifugoToken = null;
261
264
  }
262
- }, s = class extends r {
265
+ }, c = class extends i {
263
266
  client = null;
264
267
  subscriptions = /* @__PURE__ */ new Map();
265
268
  refCount = /* @__PURE__ */ new Map();
@@ -274,7 +277,7 @@ var r = class {
274
277
  return this.currentState;
275
278
  }
276
279
  async connect(t) {
277
- this.uid = t, this.client = new e(this.wsUrl, { getToken: async () => await this.tokenGetter() }), this.client.on("connected", () => {
280
+ this.uid = t, this.client && this.disconnect(), this.client = new e(this.wsUrl, { getToken: async () => await this.tokenGetter() }), this.client.on("connected", () => {
278
281
  this.currentState = "connected", this.emit("connection:state", "connected"), this.subscribe(`personal#${t}`);
279
282
  }), this.client.on("disconnected", (e) => {
280
283
  this.currentState = "disconnected", this.emit("connection:state", "disconnected"), console.warn("[im] centrifugo disconnected", e?.reason);
@@ -348,6 +351,12 @@ var r = class {
348
351
  case "read_receipt":
349
352
  this.emit("read_receipt", n);
350
353
  break;
354
+ case "typing":
355
+ this.emit("typing", {
356
+ from: n.from || "",
357
+ isTyping: !!n.isTyping
358
+ });
359
+ break;
351
360
  case "presence:update":
352
361
  {
353
362
  let e = n.changes || [];
@@ -376,9 +385,22 @@ var r = class {
376
385
  }
377
386
  }
378
387
  disconnect() {
379
- this.client &&= (this.client.disconnect(), null), this.subscriptions.clear(), this.currentState = "disconnected";
380
- }
381
- }, c = class extends r {
388
+ this.client &&= (this.client.disconnect(), null), this.subscriptions.clear(), this.refCount.clear(), this.currentState = "disconnected";
389
+ }
390
+ }, l = null;
391
+ async function u(e) {
392
+ r("silent"), l &&= (clearTimeout(l), null);
393
+ try {
394
+ await e.disconnect();
395
+ } finally {
396
+ l = setTimeout(() => {
397
+ r("warn"), l = null;
398
+ }, 1500);
399
+ }
400
+ }
401
+ //#endregion
402
+ //#region src/call.ts
403
+ var d = class extends i {
382
404
  callId;
383
405
  callType;
384
406
  roomName;
@@ -472,11 +494,11 @@ var r = class {
472
494
  } catch (e) {
473
495
  console.error("[im] callEnd 失败", e);
474
496
  }
475
- await this.room.disconnect(), this.emitSession("ended", { reason: t });
497
+ await u(this.room), this.emitSession("ended", { reason: t });
476
498
  }
477
499
  }
478
500
  async end(e) {
479
- this.ended || (this.ended = !0, await this.room.disconnect(), this.emitSession("ended", { reason: e }));
501
+ this.ended || (this.ended = !0, await u(this.room), this.emitSession("ended", { reason: e }));
480
502
  }
481
503
  registerRpcMethod(e, t) {
482
504
  this.room.localParticipant.registerRpcMethod(e, (e) => t(e.payload));
@@ -506,7 +528,7 @@ var r = class {
506
528
  return this.token;
507
529
  }
508
530
  token;
509
- }, l = class {
531
+ }, f = class {
510
532
  transport;
511
533
  livekitWs;
512
534
  identity;
@@ -516,7 +538,7 @@ var r = class {
516
538
  this.transport = e, this.livekitWs = t, this.identity = n, this.iceServers = r;
517
539
  }
518
540
  async init(e, t) {
519
- let n = await this.transport.callInit(e, t), r = new c({
541
+ let n = await this.transport.callInit(e, t), r = new d({
520
542
  callId: n.callId,
521
543
  callType: t,
522
544
  roomName: n.roomName,
@@ -528,7 +550,7 @@ var r = class {
528
550
  return this.currentSession = r, r;
529
551
  }
530
552
  async accept(e, t) {
531
- let n = await this.transport.callAccept(e), r = new c({
553
+ let n = await this.transport.callAccept(e), r = new d({
532
554
  callId: e,
533
555
  callType: t,
534
556
  roomName: n.roomName,
@@ -555,7 +577,11 @@ var r = class {
555
577
  console.warn("[im] callEnd 失败(不阻塞)", e);
556
578
  }
557
579
  }
558
- }, u = class e extends r {
580
+ };
581
+ //#endregion
582
+ //#region src/meeting.ts
583
+ r("warn");
584
+ var p = 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({
@@ -607,6 +633,26 @@ var r = class {
607
633
  }).on("activeSpeakersChanged", (e) => {
608
634
  let t = e.map((e) => e.identity);
609
635
  this.emitSession("activeSpeakersChanged", { identities: t });
636
+ }).on("trackMuted", (e, t) => {
637
+ e.source === n.Source.Microphone ? this.emitSession("participantMuteChanged", {
638
+ identity: t.identity,
639
+ muted: !0,
640
+ kind: "audio"
641
+ }) : e.source === n.Source.Camera && this.emitSession("participantMuteChanged", {
642
+ identity: t.identity,
643
+ muted: !0,
644
+ kind: "video"
645
+ });
646
+ }).on("trackUnmuted", (e, t) => {
647
+ e.source === n.Source.Microphone ? this.emitSession("participantMuteChanged", {
648
+ identity: t.identity,
649
+ muted: !1,
650
+ kind: "audio"
651
+ }) : e.source === n.Source.Camera && this.emitSession("participantMuteChanged", {
652
+ identity: t.identity,
653
+ muted: !1,
654
+ kind: "video"
655
+ });
610
656
  }), await this.room.connect(this.livekitWs, this.token, { rtcConfig: { iceServers: this.iceServers } });
611
657
  let e = this.room.localParticipant.identity;
612
658
  e && (this.identity = e, this.hostIdentity ||= e), this.emitSession("connected", {});
@@ -644,11 +690,11 @@ var r = class {
644
690
  } catch (e) {
645
691
  console.error("[im] meetingLeave 失败", e);
646
692
  }
647
- await this.room.disconnect(), this.emitSession("ended", {});
693
+ await u(this.room), this.emitSession("ended", {});
648
694
  }
649
695
  }
650
696
  async end() {
651
- this.ended || (this.ended = !0, await this.room.disconnect(), this.emitSession("ended", {}));
697
+ this.ended || (this.ended = !0, await u(this.room), this.emitSession("ended", {}));
652
698
  }
653
699
  getRemoteParticipants() {
654
700
  let e = [];
@@ -722,7 +768,7 @@ var r = class {
722
768
  console.error(`[im] session handler error: ${e}`, t);
723
769
  }
724
770
  }
725
- }, d = class {
771
+ }, m = class {
726
772
  transport;
727
773
  livekitWs;
728
774
  identity;
@@ -735,7 +781,7 @@ var r = class {
735
781
  let n = await this.transport.meetingCreate({
736
782
  inviteeUids: e,
737
783
  title: t
738
- }), r = new u({
784
+ }), r = new p({
739
785
  meetingId: n.meetingId,
740
786
  title: t,
741
787
  roomName: n.roomName,
@@ -759,7 +805,7 @@ var r = class {
759
805
  };
760
806
  }
761
807
  async join(e, t = "") {
762
- let n = await this.transport.meetingJoin(e), r = new u({
808
+ let n = await this.transport.meetingJoin(e), r = new p({
763
809
  meetingId: e,
764
810
  title: t,
765
811
  roomName: n.roomName,
@@ -781,7 +827,7 @@ var r = class {
781
827
  async respond(e, t, n) {
782
828
  let r = await this.transport.meetingRespond(e, t);
783
829
  if (t !== "accept" || !r?.token || !r?.roomName) return null;
784
- let i = new u({
830
+ let i = new p({
785
831
  meetingId: e,
786
832
  title: r.title || n || "",
787
833
  roomName: r.roomName,
@@ -805,8 +851,8 @@ var r = class {
805
851
  }
806
852
  async dissolve() {
807
853
  if (!this.currentSession) return !1;
808
- let e = this.currentSession.meetingId;
809
- return await this.transport.meetingDissolve(e), this.currentSession = null, !0;
854
+ let e = this.currentSession;
855
+ return await this.transport.meetingDissolve(e.meetingId), this.currentSession = null, await e.end().catch(() => {}), !0;
810
856
  }
811
857
  async getParticipantCount() {
812
858
  return this.currentSession ? (await this.transport.meetingParticipantCount(this.currentSession.meetingId)).count : 0;
@@ -824,7 +870,7 @@ var r = class {
824
870
  async getMembers(e = !1) {
825
871
  return this.currentSession ? this.currentSession.refreshMembers(this.transport, e) : [];
826
872
  }
827
- }, f = class {
873
+ }, h = class {
828
874
  transport;
829
875
  realtime;
830
876
  uid;
@@ -894,7 +940,7 @@ var r = class {
894
940
  dialogChannel(e) {
895
941
  return `dialog#${[this.uid, e].sort()[0]},${[this.uid, e].sort()[1]}`;
896
942
  }
897
- }, p = class {
943
+ }, g = class {
898
944
  transport;
899
945
  constructor(e) {
900
946
  this.transport = e;
@@ -922,7 +968,36 @@ var r = class {
922
968
  }
923
969
  return { mediaId: i.mediaId };
924
970
  }
925
- }, m = [
971
+ }, _ = class {
972
+ transport;
973
+ byExternal = /* @__PURE__ */ new Map();
974
+ byUid = /* @__PURE__ */ new Map();
975
+ loaded = !1;
976
+ loading = null;
977
+ constructor(e) {
978
+ this.transport = e;
979
+ }
980
+ async list(e = !1) {
981
+ return this.loaded && !e ? [...this.byExternal.values()] : (this.loading ||= this.transport.listUsers().then((e) => {
982
+ for (let t of e.users || []) this.upsert(t);
983
+ this.loaded = !0;
984
+ }).finally(() => {
985
+ this.loading = null;
986
+ }), await this.loading, [...this.byExternal.values()]);
987
+ }
988
+ async resolve(e) {
989
+ let t = this.byExternal.get(e) || this.byUid.get(e);
990
+ if (t) return t;
991
+ if (!this.loaded) return await this.list(), this.byExternal.get(e) || this.byUid.get(e);
992
+ }
993
+ upsert(e) {
994
+ this.byExternal.set(e.externalId, e), this.byUid.set(e.uid, e);
995
+ }
996
+ updateOnline(e, t) {
997
+ let n = this.byExternal.get(e);
998
+ n && n.online !== t && (n.online = t);
999
+ }
1000
+ }, v = [
926
1001
  "message",
927
1002
  "message_preview",
928
1003
  "message:revoked",
@@ -947,7 +1022,7 @@ var r = class {
947
1022
  "session:kicked",
948
1023
  "connection:state",
949
1024
  "presence:update"
950
- ], h = class extends r {
1025
+ ], y = class extends i {
951
1026
  auth;
952
1027
  transport;
953
1028
  realtime;
@@ -955,29 +1030,32 @@ var r = class {
955
1030
  meeting;
956
1031
  message;
957
1032
  media;
1033
+ users;
958
1034
  uid = "";
959
1035
  appId;
960
1036
  sessionState = "idle";
1037
+ clientType = 4;
1038
+ realtimeBound = !1;
961
1039
  clientConfig = null;
962
1040
  livekitWs;
963
1041
  apiBase;
964
1042
  name = "";
965
1043
  avatar = "";
966
1044
  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));
1045
+ 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
1046
  }
969
1047
  async connect(e) {
970
- e.name && (this.name = e.name), e.avatar && (this.avatar = e.avatar);
1048
+ e.name && (this.name = e.name), e.avatar && (this.avatar = e.avatar), this.clientType = e.clientType ?? 4;
971
1049
  let t = await this.auth.login(this.appId, e.externalId, e.clientType ?? 4, e.deviceName);
972
1050
  return this.uid = t.uid, t.name && (this.name = t.name), t.avatarUrl && (this.avatar = t.avatarUrl), await this.initAfterAuth(), t;
973
1051
  }
974
1052
  async connectWithExternalJwt(e) {
975
- e.name && (this.name = e.name), e.avatar && (this.avatar = e.avatar), this.uid = e.uid, this.auth.setExternalToken(e.jwt, e.expiresAt), await this.initAfterAuth();
1053
+ e.name && (this.name = e.name), e.avatar && (this.avatar = e.avatar), this.uid = e.uid, this.clientType = e.clientType ?? 4, this.auth.setExternalToken(e.jwt, e.expiresAt), await this.initAfterAuth();
976
1054
  }
977
1055
  async initAfterAuth() {
978
1056
  await this.loadClientConfig();
979
1057
  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);
1058
+ this.call = new f(this.transport, this.livekitWs, this.uid, e), this.meeting = new m(this.transport, this.livekitWs, this.uid, e), this.message = new h(this.transport, this.realtime, this.uid), this.media = new g(this.transport), this.users = new _(this.transport), await this.realtime.connect(this.uid);
981
1059
  try {
982
1060
  let e = await this.transport.getSessionState();
983
1061
  this.sessionState = e.state, this.emit("session:state", {
@@ -988,7 +1066,7 @@ var r = class {
988
1066
  } catch (e) {
989
1067
  console.warn("[im] 同步 sessionState 失败", e);
990
1068
  }
991
- this.realtime.on("call:invite", () => {}), this.realtime.on("call:busy", () => {
1069
+ this.realtimeBound || (this.realtimeBound = !0, this.realtime.on("call:busy", () => {
992
1070
  this.call.currentSession = null;
993
1071
  }), this.realtime.on("call:no_answer", () => {
994
1072
  this.call.currentSession = null;
@@ -1001,13 +1079,17 @@ var r = class {
1001
1079
  }), this.realtime.on("meeting:kicked", (e) => {
1002
1080
  let t = this.meeting?.currentSession;
1003
1081
  t && e?.meetingId === t.meetingId && t.end().catch((e) => console.warn("[im] kicked end session 失败", e));
1004
- }), this.realtime.on("session:kicked", () => {
1005
- console.warn("[im] 会话被踢(同端新登录),断开连接");
1006
- try {
1007
- this.realtime.disconnect();
1008
- } catch {}
1009
- this.auth.logout(), this.uid = "";
1010
- }), this.forwardRealtimeEvents(), this.fetchAndEmitPendingInvites();
1082
+ }), this.realtime.on("session:kicked", (e) => {
1083
+ if (!(e?.clientType !== void 0 && e.clientType !== this.clientType)) {
1084
+ console.warn("[im] 会话被踢(同端新登录),断开连接");
1085
+ try {
1086
+ this.realtime.disconnect();
1087
+ } catch {}
1088
+ this.auth.logout(), this.uid = "";
1089
+ }
1090
+ }), this.realtime.on("presence:update", (e) => {
1091
+ e?.uid && this.users?.updateOnline(e.uid, !!e.online);
1092
+ }), this.forwardRealtimeEvents()), this.fetchAndEmitPendingInvites();
1011
1093
  }
1012
1094
  async loadClientConfig() {
1013
1095
  if (!this.clientConfig) try {
@@ -1035,7 +1117,7 @@ var r = class {
1035
1117
  }
1036
1118
  }
1037
1119
  forwardRealtimeEvents() {
1038
- for (let e of m) this.realtime.on(e, (t) => {
1120
+ for (let e of v) this.realtime.on(e, (t) => {
1039
1121
  this.emit(e, t);
1040
1122
  });
1041
1123
  }
@@ -1044,6 +1126,6 @@ var r = class {
1044
1126
  }
1045
1127
  };
1046
1128
  //#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 };
1129
+ export { a as ApiError, s as AuthManager, f as CallController, d as CallSession, i as EventEmitter, y as ImClient, g as MediaUploader, m as MeetingController, p as MeetingSession, h as MessageController, c as RealtimeConnection, o as Transport, _ as UserDirectory };
1048
1130
 
1049
1131
  //# sourceMappingURL=im-core.es.js.map