@defcomm/meetingsdk 0.2.5 → 0.2.6

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/index.mjs CHANGED
@@ -392,7 +392,6 @@ var SFUClient = class {
392
392
  this.trackToSource = /* @__PURE__ */ new Map();
393
393
  this.localTrackIds = /* @__PURE__ */ new Map();
394
394
  this.subscriberStatsTimer = null;
395
- this.lastRecordingId = null;
396
395
  this.heartbeatTimer = null;
397
396
  this.apiBase = options.apiBase || "https://api.example.com/api";
398
397
  this.wsBase = options.wsBase || "wss://api.example.com/ws";
@@ -405,8 +404,6 @@ var SFUClient = class {
405
404
  });
406
405
  this.onParticipantPresence = options.onParticipantPresence || (() => {
407
406
  });
408
- this.onParticipantMediaState = options.onParticipantMediaState || (() => {
409
- });
410
407
  this.onTrackPublished = options.onTrackPublished || (() => {
411
408
  });
412
409
  this.onTrackUnpublished = options.onTrackUnpublished || (() => {
@@ -557,9 +554,7 @@ var SFUClient = class {
557
554
  this.room = nextRoom;
558
555
  this.joinOptions = {
559
556
  displayName: options.displayName,
560
- avatarUrl: options.avatarUrl,
561
- audioMuted: options.audioMuted,
562
- videoMuted: options.videoMuted
557
+ avatarUrl: options.avatarUrl
563
558
  };
564
559
  if (options.participantId) this.participantId = options.participantId;
565
560
  if (!this.resumeToken) {
@@ -628,9 +623,7 @@ var SFUClient = class {
628
623
  room_code: this.room,
629
624
  resume_token: this.resumeToken,
630
625
  display_name: options.displayName,
631
- avatar_url: options.avatarUrl,
632
- audio_muted: options.audioMuted ?? this.joinOptions.audioMuted ?? false,
633
- video_muted: options.videoMuted ?? this.joinOptions.videoMuted ?? false
626
+ avatar_url: options.avatarUrl
634
627
  };
635
628
  if (this.pendingJoinRequestId) {
636
629
  this.send({
@@ -744,9 +737,7 @@ var SFUClient = class {
744
737
  room_code: this.room,
745
738
  resume_token: this.resumeToken,
746
739
  display_name: this.joinOptions.displayName,
747
- avatar_url: this.joinOptions.avatarUrl,
748
- audio_muted: this.joinOptions.audioMuted ?? false,
749
- video_muted: this.joinOptions.videoMuted ?? false
740
+ avatar_url: this.joinOptions.avatarUrl
750
741
  }
751
742
  });
752
743
  }
@@ -887,7 +878,6 @@ var SFUClient = class {
887
878
  break;
888
879
  }
889
880
  case "recording_started": {
890
- this.lastRecordingId = payload.recording_id || this.lastRecordingId;
891
881
  this.onRecordingStarted({
892
882
  recording_id: payload.recording_id,
893
883
  started_at: payload.started_at
@@ -895,7 +885,6 @@ var SFUClient = class {
895
885
  break;
896
886
  }
897
887
  case "recording_stopped": {
898
- this.lastRecordingId = null;
899
888
  this.onRecordingStopped({
900
889
  recording_id: payload.recording_id,
901
890
  stopped_at: payload.stopped_at
@@ -931,29 +920,6 @@ var SFUClient = class {
931
920
  this.onScreenShareStopped(participantId, trackId);
932
921
  break;
933
922
  }
934
- case "room_state": {
935
- await this.reconcileRoomState(payload);
936
- break;
937
- }
938
- case "participant_media_state": {
939
- const participantId = payload.participant_id;
940
- if (participantId) {
941
- const current = this.participants.get(participantId);
942
- if (current) {
943
- this.participants.set(participantId, {
944
- ...current,
945
- audio_muted: Boolean(payload.audio_muted),
946
- video_muted: Boolean(payload.video_muted)
947
- });
948
- }
949
- }
950
- this.onParticipantMediaState?.(
951
- participantId,
952
- Boolean(payload.audio_muted),
953
- Boolean(payload.video_muted)
954
- );
955
- break;
956
- }
957
923
  case "error": {
958
924
  const message2 = payload.message || "SFU signaling error";
959
925
  if (this.state === "reconnecting" && message2.includes("participant session is stale")) {
@@ -976,90 +942,6 @@ var SFUClient = class {
976
942
  console.debug("[SFU] Ignoring unknown server message", message);
977
943
  }
978
944
  }
979
- async reconcileRoomState(payload) {
980
- const nextParticipants = /* @__PURE__ */ new Map();
981
- for (const participant of payload.participants || []) {
982
- if (participant?.participant_id) {
983
- nextParticipants.set(participant.participant_id, participant);
984
- }
985
- }
986
- for (const participantId of this.participants.keys()) {
987
- if (participantId !== this.currentParticipantId && !nextParticipants.has(participantId)) {
988
- this.participants.delete(participantId);
989
- this.onParticipantLeft(participantId);
990
- }
991
- }
992
- for (const participant of nextParticipants.values()) {
993
- if (participant.participant_id === this.currentParticipantId) continue;
994
- const previous = this.participants.get(participant.participant_id);
995
- const wasScreenSharing = Boolean(previous?.screen_sharing);
996
- const isScreenSharing = Boolean(participant.screen_sharing);
997
- this.participants.set(participant.participant_id, participant);
998
- if (!previous) {
999
- this.onParticipantJoined(participant);
1000
- }
1001
- if (participant.presence) {
1002
- this.onParticipantPresence(
1003
- participant.participant_id,
1004
- String(participant.presence).toLowerCase()
1005
- );
1006
- }
1007
- this.onParticipantMediaState(
1008
- participant.participant_id,
1009
- Boolean(participant.audio_muted),
1010
- Boolean(participant.video_muted)
1011
- );
1012
- if (!wasScreenSharing && isScreenSharing) {
1013
- this.onScreenShareStarted(participant.participant_id, void 0);
1014
- } else if (wasScreenSharing && !isScreenSharing) {
1015
- this.onScreenShareStopped(
1016
- participant.participant_id,
1017
- participant.screen_track_id || void 0
1018
- );
1019
- }
1020
- }
1021
- const nextTracks = /* @__PURE__ */ new Map();
1022
- for (const track of payload.tracks || []) {
1023
- if (track?.track_id) {
1024
- nextTracks.set(track.track_id, track);
1025
- this.rememberTrack(track);
1026
- }
1027
- }
1028
- for (const [trackId, oldTrack] of [...this.trackMetadata.entries()]) {
1029
- if (!nextTracks.has(trackId)) {
1030
- this.trackMetadata.delete(trackId);
1031
- this.trackToParticipant.delete(trackId);
1032
- this.trackToSource.delete(trackId);
1033
- this.subscribedTracks.delete(trackId);
1034
- if (oldTrack.participant_id !== this.currentParticipantId) {
1035
- this.onTrackUnpublished(oldTrack);
1036
- }
1037
- }
1038
- }
1039
- if (this.autoSubscribe) {
1040
- const missing = [...nextTracks.values()].filter(
1041
- (track) => track.participant_id !== this.currentParticipantId && !this.subscribedTracks.has(track.track_id)
1042
- ).map((track) => track.track_id);
1043
- if (missing.length) await this.subscribeMultiple(missing);
1044
- }
1045
- const nextRecordingId = payload.recording?.recording_id || null;
1046
- if (payload.recording) {
1047
- if (this.lastRecordingId !== nextRecordingId) {
1048
- this.lastRecordingId = nextRecordingId;
1049
- this.onRecordingStarted({
1050
- recording_id: payload.recording.recording_id,
1051
- started_at: payload.recording.started_at
1052
- });
1053
- }
1054
- } else if (this.lastRecordingId) {
1055
- const recordingId = this.lastRecordingId;
1056
- this.lastRecordingId = null;
1057
- this.onRecordingStopped({
1058
- recording_id: recordingId,
1059
- stopped_at: (/* @__PURE__ */ new Date()).toISOString()
1060
- });
1061
- }
1062
- }
1063
945
  rememberTrack(track) {
1064
946
  this.trackMetadata.set(track.track_id, track);
1065
947
  this.trackToParticipant.set(track.track_id, track.participant_id);
@@ -1546,25 +1428,31 @@ var SFUClient = class {
1546
1428
  this.localStream?.getAudioTracks().forEach((track) => {
1547
1429
  track.enabled = !muted;
1548
1430
  });
1549
- this.send({
1550
- type: "set_media_state",
1551
- payload: {
1552
- audio_muted: muted,
1553
- video_muted: !(this.localStream?.getVideoTracks()[0]?.enabled ?? true)
1554
- }
1555
- });
1431
+ const trackId = this.localTrackIds.get("audio");
1432
+ if (trackId) {
1433
+ this.send({
1434
+ type: "track_state",
1435
+ payload: {
1436
+ track_id: trackId,
1437
+ muted
1438
+ }
1439
+ });
1440
+ }
1556
1441
  }
1557
1442
  muteVideo(muted) {
1558
1443
  this.localStream?.getVideoTracks().forEach((track) => {
1559
1444
  track.enabled = !muted;
1560
1445
  });
1561
- this.send({
1562
- type: "set_media_state",
1563
- payload: {
1564
- audio_muted: !(this.localStream?.getAudioTracks()[0]?.enabled ?? true),
1565
- video_muted: muted
1566
- }
1567
- });
1446
+ const trackId = this.localTrackIds.get("camera");
1447
+ if (trackId) {
1448
+ this.send({
1449
+ type: "track_state",
1450
+ payload: {
1451
+ track_id: trackId,
1452
+ muted
1453
+ }
1454
+ });
1455
+ }
1568
1456
  }
1569
1457
  async startRecording() {
1570
1458
  if (!this.send({ type: "start_recording" })) {
@@ -2023,11 +1911,7 @@ var VideoSDKCore = class {
2023
1911
  console.log(`[SFU] ${resumed ? "Resumed" : "Joined"} room`, payload);
2024
1912
  this.state.updateLocalParticipant({
2025
1913
  id: this.myId,
2026
- name: this.participantName,
2027
- media: {
2028
- micEnabled: this.localStream?.getAudioTracks()[0]?.enabled ?? true,
2029
- camEnabled: this.localStream?.getVideoTracks()[0]?.enabled ?? true
2030
- }
1914
+ name: this.participantName
2031
1915
  });
2032
1916
  },
2033
1917
  onDisconnected: () => {
@@ -2039,11 +1923,6 @@ var VideoSDKCore = class {
2039
1923
  // ADMISSION CONTROL
2040
1924
  onJoinPending: (info) => {
2041
1925
  console.log("[SFU] Join request pending", info);
2042
- this.events.onEntryRequested?.({
2043
- requestId: info.request_id,
2044
- participantId: this.myId,
2045
- name: this.participantName
2046
- });
2047
1926
  },
2048
1927
  onJoinApproved: (requestId) => {
2049
1928
  console.log("[SFU] Join approved", requestId);
@@ -2096,44 +1975,22 @@ var VideoSDKCore = class {
2096
1975
  return;
2097
1976
  }
2098
1977
  const pname = participant.user_metadata?.name || participant.display_name || "Participant";
2099
- const participantMedia = participant.media || {};
2100
- const participantState = {
1978
+ this.state.addParticipant({
2101
1979
  id: pid,
2102
1980
  name: pname,
2103
- connectionState: participant.presence === "reconnecting" ? "reconnecting" : "connected",
1981
+ connectionState: "connected",
2104
1982
  media: {
2105
- micEnabled: !Boolean(participant.audio_muted),
2106
- camEnabled: !Boolean(participant.video_muted),
2107
- isScreenSharing: Boolean(participant.screen_sharing),
2108
- screenStream: participantMedia.screenStream ?? null,
1983
+ micEnabled: true,
1984
+ camEnabled: true,
1985
+ isScreenSharing: false,
2109
1986
  stream: null
2110
1987
  }
2111
- };
2112
- if (!this.state.addParticipant(participantState)) {
2113
- this.state.updateParticipantMedia(pid, participantState.media);
2114
- }
1988
+ });
2115
1989
  this.events.onUserJoined?.({
2116
1990
  id: pid,
2117
1991
  name: pname
2118
1992
  });
2119
1993
  },
2120
- onParticipantMediaState: (participantId, audioMuted, videoMuted) => {
2121
- if (participantId === this.myId) {
2122
- this.state.updateLocalParticipant({
2123
- media: {
2124
- micEnabled: !audioMuted,
2125
- camEnabled: !videoMuted
2126
- }
2127
- });
2128
- return;
2129
- }
2130
- this.state.updateParticipantMedia(participantId, {
2131
- micEnabled: !audioMuted,
2132
- camEnabled: !videoMuted
2133
- });
2134
- this.events.onMuteStateChanged?.(participantId, "audio", audioMuted);
2135
- this.events.onMuteStateChanged?.(participantId, "video", videoMuted);
2136
- },
2137
1994
  onParticipantPresence: (participantId, presence) => {
2138
1995
  if (participantId === this.myId) {
2139
1996
  return;
@@ -2297,9 +2154,7 @@ var VideoSDKCore = class {
2297
2154
  client.setLocalStream(this.localStream);
2298
2155
  await client.getToken(roomId, {
2299
2156
  displayName: name,
2300
- participantId: this.myId,
2301
- audioMuted: !this.localStream?.getAudioTracks()[0]?.enabled,
2302
- videoMuted: !this.localStream?.getVideoTracks()[0]?.enabled
2157
+ participantId: this.myId
2303
2158
  });
2304
2159
  }
2305
2160
  // SFU STATE
@@ -2463,7 +2318,6 @@ var VideoSDKCore = class {
2463
2318
  screenTrack: this.screenStream.getVideoTracks()[0]
2464
2319
  }
2465
2320
  });
2466
- this.state.setPresenterId(this.myId);
2467
2321
  return this.screenStream;
2468
2322
  } catch (err) {
2469
2323
  this.emitError(
@@ -2485,9 +2339,6 @@ var VideoSDKCore = class {
2485
2339
  this.screenStream.getTracks().forEach((track) => track.stop());
2486
2340
  this.screenStream = null;
2487
2341
  this.isScreenSharing = false;
2488
- if (this.state.presenterId === this.myId) {
2489
- this.state.setPresenterId(null);
2490
- }
2491
2342
  this.state.updateLocalParticipant({
2492
2343
  media: {
2493
2344
  isScreenSharing: false,