@naviedu/room-platform-react 0.0.42 → 0.0.43

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.
Files changed (3) hide show
  1. package/index.d.ts +4 -12
  2. package/index.esm.js +346 -77
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -262,6 +262,7 @@ declare type RoomPlatformContextValue = {
262
262
  localCameraTrack: LocalVideoTrack | null;
263
263
  localMedia: RoomPlatformLocalMediaState;
264
264
  performAction: (name: RoomPlatformActionName, payload?: Record<string, string>) => Promise<void>;
265
+ reconcileLocalCameraAfterProcessor: (track: LocalVideoTrack) => Promise<void>;
265
266
  room: Room | null;
266
267
  setLocalMediaEnabled: (kind: RoomPlatformLocalMediaKind, enabled: boolean) => Promise<void>;
267
268
  status: RoomPlatformConnectionStatus;
@@ -292,7 +293,7 @@ declare type RoomPlatformControlBarProps = {
292
293
  onToggleTheaterMode?: () => void;
293
294
  };
294
295
 
295
- export declare function RoomPlatformCurrentOperationStrip({ activeSpeakerParticipantIdentity, canClearActiveSpeaker, isClearingActiveSpeaker, onClearActiveSpeaker, currentPrivateRoomOperation, onCancelPrivateRoom, participants, currentOperation, }: {
296
+ export declare function RoomPlatformCurrentOperationStrip({ activeSpeakerParticipantIdentity, canClearActiveSpeaker, isClearingActiveSpeaker, onClearActiveSpeaker, currentPrivateRoomOperation, onCancelPrivateRoom, participants, }: {
296
297
  activeSpeakerParticipantIdentity?: string;
297
298
  canClearActiveSpeaker?: boolean;
298
299
  isClearingActiveSpeaker?: boolean;
@@ -303,11 +304,6 @@ export declare function RoomPlatformCurrentOperationStrip({ activeSpeakerPartici
303
304
  };
304
305
  onCancelPrivateRoom?: () => Promise<void> | void;
305
306
  participants: readonly Pick<RoomParticipantPresence, 'name' | 'participantIdentity' | 'externalActorId' | 'isLocal'>[];
306
- currentOperation?: {
307
- label: string;
308
- name: string;
309
- leading?: ReactNode;
310
- };
311
307
  }): JSX.Element;
312
308
 
313
309
  export declare type RoomPlatformDeviceKind = 'audioinput' | 'audiooutput' | 'videoinput';
@@ -342,11 +338,6 @@ export declare type RoomPlatformExtensionProps = {
342
338
  };
343
339
 
344
340
  export declare type RoomPlatformExtensions = {
345
- currentOperation?: {
346
- label: string;
347
- name: string;
348
- leading?: ReactNode;
349
- };
350
341
  topBarLeading?: ComponentType<RoomPlatformExtensionProps>;
351
342
  topBarTrailing?: ComponentType<RoomPlatformExtensionProps>;
352
343
  monitor?: {
@@ -706,7 +697,7 @@ declare type RoomPrivateRoomStatus = 'ringing' | 'active';
706
697
 
707
698
  export declare function useRoomPlatform(): RoomPlatformContextValue;
708
699
 
709
- declare function useRoomPlatformCameraBackground({ localVideoTrack }: UseRoomPlatformCameraBackgroundInput): {
700
+ declare function useRoomPlatformCameraBackground({ localVideoTrack, onProcessorSettled, }: UseRoomPlatformCameraBackgroundInput): {
710
701
  state: RoomPlatformCameraBackgroundState;
711
702
  uploadItems: RoomPlatformCameraBackgroundUploadPreview[];
712
703
  uploadPreviewUrl: string;
@@ -723,6 +714,7 @@ declare function useRoomPlatformCameraBackground({ localVideoTrack }: UseRoomPla
723
714
 
724
715
  declare type UseRoomPlatformCameraBackgroundInput = {
725
716
  localVideoTrack: LocalVideoTrack | null;
717
+ onProcessorSettled?: (track: LocalVideoTrack) => void | Promise<void>;
726
718
  };
727
719
 
728
720
  export declare function useRoomPlatformMonitorViewer({ enabled, onStartError, performAction, }: RoomPlatformMonitorViewerProps): void;
package/index.esm.js CHANGED
@@ -13569,6 +13569,18 @@ function toWhiteboardProviderProps(integration, roomId) {
13569
13569
  };
13570
13570
  }
13571
13571
 
13572
+ var roleFromMetadata = function(metadata) {
13573
+ try {
13574
+ var parsed = JSON.parse(metadata !== null && metadata !== void 0 ? metadata : '{}');
13575
+ return typeof parsed.role === 'string' ? parsed.role : undefined;
13576
+ } catch (unused) {
13577
+ return undefined;
13578
+ }
13579
+ };
13580
+ var isManagedParticipantRole = function(role) {
13581
+ return role === 'student' || role === 'admin' || role === 'operator';
13582
+ };
13583
+
13572
13584
  var RoomPlatformPrivateRoomContext = createContext(undefined);
13573
13585
  function useRoomPlatformPrivateRoomContext() {
13574
13586
  var context = useContext(RoomPlatformPrivateRoomContext);
@@ -14044,14 +14056,6 @@ var localMediaStateOf = function(room) {
14044
14056
  screenShare: room.localParticipant.isScreenShareEnabled
14045
14057
  };
14046
14058
  };
14047
- var roleFromMetadata = function(metadata) {
14048
- try {
14049
- var parsed = JSON.parse(metadata !== null && metadata !== void 0 ? metadata : '{}');
14050
- return typeof parsed.role === 'string' ? parsed.role : undefined;
14051
- } catch (unused) {
14052
- return undefined;
14053
- }
14054
- };
14055
14059
  var externalActorIdFromMetadata$2 = function(metadata) {
14056
14060
  try {
14057
14061
  var parsed = JSON.parse(metadata !== null && metadata !== void 0 ? metadata : '{}');
@@ -14096,12 +14100,15 @@ function RoomPlatformProvider(param) {
14096
14100
  var hasFirstSuccessfulConnectionRef = useRef(false);
14097
14101
  var cameraDesiredRef = useRef(false);
14098
14102
  var canonicalCameraTrackRef = useRef(null);
14103
+ var managedCameraUpstreamDirtyRef = useRef(new WeakSet());
14099
14104
  var cameraTrackEndedHandlerRef = useRef(undefined);
14105
+ var cameraTrackRestartedHandlerRef = useRef(undefined);
14100
14106
  var cameraCreationRef = useRef(undefined);
14101
14107
  var cameraTransitionRef = useRef(Promise.resolve());
14102
14108
  var cameraRevisionRef = useRef(0);
14103
14109
  var accessGenerationRef = useRef(0);
14104
14110
  var handleCameraEndedRef = useRef(undefined);
14111
+ var handleCameraRestartedRef = useRef(undefined);
14105
14112
  var initialLaunchTokenRef = useRef(launchToken);
14106
14113
  var recoveryRef = useRef(undefined);
14107
14114
  var roomConnectionRef = useRef(null);
@@ -14341,11 +14348,117 @@ function RoomPlatformProvider(param) {
14341
14348
  cameraShouldBeForced
14342
14349
  ]);
14343
14350
  var cameraShouldCapture = useCallback(function(currentRoom, currentAccess) {
14344
- return !cameraRoomIsPrivate(currentRoom) && (cameraShouldBeForced(currentRoom) || cameraDesiredRef.current && canPreviewCamera(currentAccess.capabilities));
14351
+ return !cameraRoomIsPrivate(currentRoom) && (isManagedParticipantRole(roleFromMetadata(currentRoom.localParticipant.metadata)) || cameraShouldBeForced(currentRoom) || cameraDesiredRef.current && canPreviewCamera(currentAccess.capabilities));
14345
14352
  }, [
14346
14353
  cameraRoomIsPrivate,
14347
14354
  cameraShouldBeForced
14348
14355
  ]);
14356
+ var managedCameraShouldResume = useCallback(function(currentRoom, currentAccess) {
14357
+ var _controlStateRef_current, _controlStateRef_current1;
14358
+ return roleFromMetadata(currentRoom.localParticipant.metadata) === 'student' && (((_controlStateRef_current = controlStateRef.current) === null || _controlStateRef_current === void 0 ? void 0 : _controlStateRef_current.monitorActive) === true || ((_controlStateRef_current1 = controlStateRef.current) === null || _controlStateRef_current1 === void 0 ? void 0 : _controlStateRef_current1.activeSpeakerParticipantIdentity) === currentAccess.liveKit.participantIdentity);
14359
+ }, []);
14360
+ var reconcileManagedCameraUpstream = useCallback(function(track, currentRoom, currentAccess) {
14361
+ return _async_to_generator$k(function() {
14362
+ var shouldResume, error;
14363
+ return _ts_generator$k(this, function(_state) {
14364
+ switch(_state.label){
14365
+ case 0:
14366
+ if (!isManagedParticipantRole(roleFromMetadata(currentRoom.localParticipant.metadata))) return [
14367
+ 2,
14368
+ undefined
14369
+ ];
14370
+ shouldResume = managedCameraShouldResume(currentRoom, currentAccess);
14371
+ _state.label = 1;
14372
+ case 1:
14373
+ _state.trys.push([
14374
+ 1,
14375
+ 12,
14376
+ ,
14377
+ 13
14378
+ ]);
14379
+ if (!managedCameraUpstreamDirtyRef.current.has(track)) return [
14380
+ 3,
14381
+ 6
14382
+ ];
14383
+ if (!shouldResume) return [
14384
+ 3,
14385
+ 3
14386
+ ];
14387
+ return [
14388
+ 4,
14389
+ track.pauseUpstream()
14390
+ ];
14391
+ case 2:
14392
+ _state.sent();
14393
+ return [
14394
+ 3,
14395
+ 5
14396
+ ];
14397
+ case 3:
14398
+ return [
14399
+ 4,
14400
+ track.resumeUpstream()
14401
+ ];
14402
+ case 4:
14403
+ _state.sent();
14404
+ _state.label = 5;
14405
+ case 5:
14406
+ return [
14407
+ 3,
14408
+ 7
14409
+ ];
14410
+ case 6:
14411
+ if (track.isUpstreamPaused === !shouldResume) {
14412
+ return [
14413
+ 2,
14414
+ shouldResume && track.mediaStreamTrack.readyState === 'live' && !track.isUpstreamPaused
14415
+ ];
14416
+ }
14417
+ _state.label = 7;
14418
+ case 7:
14419
+ if (!shouldResume) return [
14420
+ 3,
14421
+ 9
14422
+ ];
14423
+ return [
14424
+ 4,
14425
+ track.resumeUpstream()
14426
+ ];
14427
+ case 8:
14428
+ _state.sent();
14429
+ return [
14430
+ 3,
14431
+ 11
14432
+ ];
14433
+ case 9:
14434
+ return [
14435
+ 4,
14436
+ track.pauseUpstream()
14437
+ ];
14438
+ case 10:
14439
+ _state.sent();
14440
+ _state.label = 11;
14441
+ case 11:
14442
+ managedCameraUpstreamDirtyRef.current.delete(track);
14443
+ return [
14444
+ 3,
14445
+ 13
14446
+ ];
14447
+ case 12:
14448
+ error = _state.sent();
14449
+ managedCameraUpstreamDirtyRef.current.add(track);
14450
+ throw error;
14451
+ case 13:
14452
+ return [
14453
+ 2,
14454
+ shouldResume && track.mediaStreamTrack.readyState === 'live' && !track.isUpstreamPaused
14455
+ ];
14456
+ }
14457
+ });
14458
+ })();
14459
+ }, [
14460
+ managedCameraShouldResume
14461
+ ]);
14349
14462
  var cameraShouldPublish = useCallback(function(currentRoom, currentAccess) {
14350
14463
  return cameraShouldCapture(currentRoom, currentAccess) && cameraCanPublish(currentRoom, currentAccess);
14351
14464
  }, [
@@ -14354,7 +14467,9 @@ function RoomPlatformProvider(param) {
14354
14467
  ]);
14355
14468
  var removeCanonicalCameraTrack = useCallback(function(track, stop) {
14356
14469
  if (cameraTrackEndedHandlerRef.current) track.off(TrackEvent.Ended, cameraTrackEndedHandlerRef.current);
14470
+ if (cameraTrackRestartedHandlerRef.current) track.off(TrackEvent.Restarted, cameraTrackRestartedHandlerRef.current);
14357
14471
  cameraTrackEndedHandlerRef.current = undefined;
14472
+ cameraTrackRestartedHandlerRef.current = undefined;
14358
14473
  if (canonicalCameraTrackRef.current === track) canonicalCameraTrackRef.current = null;
14359
14474
  if (stop) track.stop();
14360
14475
  if (isMountedRef.current) {
@@ -14380,7 +14495,7 @@ function RoomPlatformProvider(param) {
14380
14495
  });
14381
14496
  var creation = function() {
14382
14497
  return _async_to_generator$k(function() {
14383
- var _roomConnectionRef_current, created, stillCurrent, ended, creationError;
14498
+ var _roomConnectionRef_current, created, stillCurrent, ended, restarted, creationError;
14384
14499
  return _ts_generator$k(this, function(_state) {
14385
14500
  switch(_state.label){
14386
14501
  case 0:
@@ -14415,9 +14530,20 @@ function RoomPlatformProvider(param) {
14415
14530
  return (_ref = (_handleCameraEndedRef_current = handleCameraEndedRef.current) === null || _handleCameraEndedRef_current === void 0 ? void 0 : _handleCameraEndedRef_current.call(handleCameraEndedRef, lifecycle, created)) !== null && _ref !== void 0 ? _ref : Promise.resolve();
14416
14531
  });
14417
14532
  };
14533
+ restarted = function() {
14534
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
14535
+ args[_key] = arguments[_key];
14536
+ }
14537
+ var _ref;
14538
+ var _handleCameraRestartedRef_current;
14539
+ if (args.length > 0 && args[0] !== created) return;
14540
+ void ((_ref = (_handleCameraRestartedRef_current = handleCameraRestartedRef.current) === null || _handleCameraRestartedRef_current === void 0 ? void 0 : _handleCameraRestartedRef_current.call(handleCameraRestartedRef, lifecycle, created)) !== null && _ref !== void 0 ? _ref : Promise.resolve());
14541
+ };
14418
14542
  canonicalCameraTrackRef.current = created;
14419
14543
  cameraTrackEndedHandlerRef.current = ended;
14544
+ cameraTrackRestartedHandlerRef.current = restarted;
14420
14545
  created.on(TrackEvent.Ended, ended);
14546
+ created.on(TrackEvent.Restarted, restarted);
14421
14547
  if (isMountedRef.current) setLocalCameraTrack(created);
14422
14548
  return [
14423
14549
  2,
@@ -14538,7 +14664,7 @@ function RoomPlatformProvider(param) {
14538
14664
  ]);
14539
14665
  var publishCanonicalCamera = useCallback(function(lifecycle, revision, generation, currentRoom) {
14540
14666
  return _async_to_generator$k(function() {
14541
- var _roomConnectionRef_current, currentAccess, track, publication, _roomConnectionRef_current1, latestAccess, canRetainForPreview, publication1, wasPublished, publishError, _roomConnectionRef_current2, latestAccess1, canRetain;
14667
+ var _roomConnectionRef_current, currentAccess, track, _roomConnectionRef_current1, publication, managedCameraEnabled, latestAccess, canRetainForPreview, publication1, wasPublished, managedCameraEnabled1, publishError, _roomConnectionRef_current2, latestAccess1, canRetain;
14542
14668
  return _ts_generator$k(this, function(_state) {
14543
14669
  switch(_state.label){
14544
14670
  case 0:
@@ -14550,43 +14676,61 @@ function RoomPlatformProvider(param) {
14550
14676
  if (!isLifecycleActive(lifecycle) || cameraRevisionRef.current !== revision || accessGenerationRef.current !== generation || ((_roomConnectionRef_current = roomConnectionRef.current) === null || _roomConnectionRef_current === void 0 ? void 0 : _roomConnectionRef_current.room) !== currentRoom || !cameraShouldPublish(currentRoom, currentAccess)) return [
14551
14677
  2
14552
14678
  ];
14553
- publication = currentRoom.localParticipant.getTrackPublication(Track.Source.Camera);
14554
- if ((publication === null || publication === void 0 ? void 0 : publication.track) === track) return [
14555
- 2
14556
- ];
14557
14679
  _state.label = 1;
14558
14680
  case 1:
14559
14681
  _state.trys.push([
14560
14682
  1,
14561
- 7,
14683
+ 10,
14562
14684
  ,
14563
- 8
14685
+ 11
14564
14686
  ]);
14687
+ publication = currentRoom.localParticipant.getTrackPublication(Track.Source.Camera);
14688
+ if (!((publication === null || publication === void 0 ? void 0 : publication.track) === track)) return [
14689
+ 3,
14690
+ 3
14691
+ ];
14565
14692
  return [
14566
14693
  4,
14567
- currentRoom.localParticipant.publishTrack(track)
14694
+ reconcileManagedCameraUpstream(track, currentRoom, currentAccess)
14568
14695
  ];
14569
14696
  case 2:
14697
+ managedCameraEnabled = _state.sent();
14698
+ if (isMountedRef.current && managedCameraEnabled !== undefined) {
14699
+ setLocalMedia(function(current) {
14700
+ return _object_spread_props$b(_object_spread$d({}, current), {
14701
+ camera: managedCameraEnabled
14702
+ });
14703
+ });
14704
+ }
14705
+ return [
14706
+ 2
14707
+ ];
14708
+ case 3:
14709
+ return [
14710
+ 4,
14711
+ currentRoom.localParticipant.publishTrack(track)
14712
+ ];
14713
+ case 4:
14570
14714
  _state.sent();
14571
14715
  latestAccess = accessRef.current;
14572
14716
  canRetainForPreview = Boolean(latestAccess && cameraDesiredRef.current && canPreviewCamera(latestAccess.capabilities) && cameraShouldCapture(currentRoom, latestAccess));
14573
14717
  if (!(latestAccess && isLifecycleActive(lifecycle) && cameraRevisionRef.current === revision && accessGenerationRef.current === generation && !cameraShouldPublish(currentRoom, latestAccess))) return [
14574
14718
  3,
14575
- 4
14719
+ 6
14576
14720
  ];
14577
14721
  return [
14578
14722
  4,
14579
14723
  unpublishCanonicalCamera(canRetainForPreview)
14580
14724
  ];
14581
- case 3:
14725
+ case 5:
14582
14726
  _state.sent();
14583
14727
  return [
14584
14728
  2
14585
14729
  ];
14586
- case 4:
14730
+ case 6:
14587
14731
  if (!(!isLifecycleActive(lifecycle) || cameraRevisionRef.current !== revision || accessGenerationRef.current !== generation || ((_roomConnectionRef_current1 = roomConnectionRef.current) === null || _roomConnectionRef_current1 === void 0 ? void 0 : _roomConnectionRef_current1.room) !== currentRoom)) return [
14588
14732
  3,
14589
- 6
14733
+ 8
14590
14734
  ];
14591
14735
  publication1 = currentRoom.localParticipant.getTrackPublication(Track.Source.Camera);
14592
14736
  wasPublished = (publication1 === null || publication1 === void 0 ? void 0 : publication1.track) === track;
@@ -14594,7 +14738,7 @@ function RoomPlatformProvider(param) {
14594
14738
  4,
14595
14739
  currentRoom.localParticipant.unpublishTrack(track, !canRetainForPreview)
14596
14740
  ];
14597
- case 5:
14741
+ case 7:
14598
14742
  _state.sent();
14599
14743
  if (!canRetainForPreview) removeCanonicalCameraTrack(track, !wasPublished);
14600
14744
  else if (isMountedRef.current) setLocalMedia(function(current) {
@@ -14605,20 +14749,33 @@ function RoomPlatformProvider(param) {
14605
14749
  return [
14606
14750
  2
14607
14751
  ];
14608
- case 6:
14609
- if (isMountedRef.current) setLocalMedia(function(current) {
14610
- return _object_spread_props$b(_object_spread$d({}, current), {
14611
- camera: true
14752
+ case 8:
14753
+ return [
14754
+ 4,
14755
+ reconcileManagedCameraUpstream(track, currentRoom, currentAccess)
14756
+ ];
14757
+ case 9:
14758
+ managedCameraEnabled1 = _state.sent();
14759
+ if (isMountedRef.current) {
14760
+ setLocalMedia(function(current) {
14761
+ return _object_spread_props$b(_object_spread$d({}, current), {
14762
+ camera: managedCameraEnabled1 !== null && managedCameraEnabled1 !== void 0 ? managedCameraEnabled1 : true
14763
+ });
14612
14764
  });
14613
- });
14765
+ }
14614
14766
  return [
14615
14767
  3,
14616
- 8
14768
+ 11
14617
14769
  ];
14618
- case 7:
14770
+ case 10:
14619
14771
  publishError = _state.sent();
14772
+ if (isMountedRef.current) setLocalMedia(function(current) {
14773
+ return _object_spread_props$b(_object_spread$d({}, current), {
14774
+ camera: false
14775
+ });
14776
+ });
14620
14777
  latestAccess1 = accessRef.current;
14621
- canRetain = isLifecycleActive(lifecycle) && latestAccess1 !== undefined && ((_roomConnectionRef_current2 = roomConnectionRef.current) === null || _roomConnectionRef_current2 === void 0 ? void 0 : _roomConnectionRef_current2.room) === currentRoom && cameraDesiredRef.current && canPreviewCamera(latestAccess1.capabilities) && cameraShouldCapture(currentRoom, latestAccess1);
14778
+ canRetain = isLifecycleActive(lifecycle) && latestAccess1 !== undefined && ((_roomConnectionRef_current2 = roomConnectionRef.current) === null || _roomConnectionRef_current2 === void 0 ? void 0 : _roomConnectionRef_current2.room) === currentRoom && (isManagedParticipantRole(roleFromMetadata(currentRoom.localParticipant.metadata)) || cameraDesiredRef.current) && canPreviewCamera(latestAccess1.capabilities) && cameraShouldCapture(currentRoom, latestAccess1);
14622
14779
  if (!canRetain) removeCanonicalCameraTrack(track, true);
14623
14780
  reportError(publishError, {
14624
14781
  recoverable: true,
@@ -14626,9 +14783,9 @@ function RoomPlatformProvider(param) {
14626
14783
  });
14627
14784
  return [
14628
14785
  3,
14629
- 8
14786
+ 11
14630
14787
  ];
14631
- case 8:
14788
+ case 11:
14632
14789
  return [
14633
14790
  2
14634
14791
  ];
@@ -14639,6 +14796,7 @@ function RoomPlatformProvider(param) {
14639
14796
  cameraShouldCapture,
14640
14797
  cameraShouldPublish,
14641
14798
  isLifecycleActive,
14799
+ reconcileManagedCameraUpstream,
14642
14800
  removeCanonicalCameraTrack,
14643
14801
  reportError,
14644
14802
  unpublishCanonicalCamera
@@ -14823,6 +14981,76 @@ function RoomPlatformProvider(param) {
14823
14981
  publishCanonicalCamera,
14824
14982
  unpublishCanonicalCamera
14825
14983
  ]);
14984
+ var handleCameraRestarted = useCallback(function(lifecycle, restartedTrack) {
14985
+ return _async_to_generator$k(function() {
14986
+ var connection, currentAccess, publication;
14987
+ return _ts_generator$k(this, function(_state) {
14988
+ switch(_state.label){
14989
+ case 0:
14990
+ if (canonicalCameraTrackRef.current !== restartedTrack || !isLifecycleActive(lifecycle)) return [
14991
+ 2
14992
+ ];
14993
+ connection = roomConnectionRef.current;
14994
+ currentAccess = accessRef.current;
14995
+ if (!connection || connection.disposed || !currentAccess) return [
14996
+ 2
14997
+ ];
14998
+ publication = connection.room.localParticipant.getTrackPublication(Track.Source.Camera);
14999
+ if ((publication === null || publication === void 0 ? void 0 : publication.track) !== restartedTrack) return [
15000
+ 2
15001
+ ];
15002
+ managedCameraUpstreamDirtyRef.current.add(restartedTrack);
15003
+ return [
15004
+ 4,
15005
+ reconcileCanonicalCamera(lifecycle, cameraRevisionRef.current, accessGenerationRef.current)
15006
+ ];
15007
+ case 1:
15008
+ _state.sent();
15009
+ return [
15010
+ 2
15011
+ ];
15012
+ }
15013
+ });
15014
+ })();
15015
+ }, [
15016
+ isLifecycleActive,
15017
+ reconcileCanonicalCamera
15018
+ ]);
15019
+ useEffect(function() {
15020
+ handleCameraRestartedRef.current = handleCameraRestarted;
15021
+ }, [
15022
+ handleCameraRestarted
15023
+ ]);
15024
+ var reconcileLocalCameraAfterProcessor = useCallback(function(track) {
15025
+ return _async_to_generator$k(function() {
15026
+ var lifecycle, connection;
15027
+ return _ts_generator$k(this, function(_state) {
15028
+ switch(_state.label){
15029
+ case 0:
15030
+ if (canonicalCameraTrackRef.current !== track) return [
15031
+ 2
15032
+ ];
15033
+ lifecycle = lifecycleRef.current;
15034
+ connection = roomConnectionRef.current;
15035
+ if (!lifecycle || !connection || connection.disposed || !accessRef.current) return [
15036
+ 2
15037
+ ];
15038
+ managedCameraUpstreamDirtyRef.current.add(track);
15039
+ return [
15040
+ 4,
15041
+ reconcileCanonicalCamera(lifecycle, cameraRevisionRef.current, accessGenerationRef.current)
15042
+ ];
15043
+ case 1:
15044
+ _state.sent();
15045
+ return [
15046
+ 2
15047
+ ];
15048
+ }
15049
+ });
15050
+ })();
15051
+ }, [
15052
+ reconcileCanonicalCamera
15053
+ ]);
14826
15054
  var disposeRoom = useCallback(function(connection) {
14827
15055
  var reconnectCompleted = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
14828
15056
  if (!connection.disposed) {
@@ -15605,11 +15833,13 @@ function RoomPlatformProvider(param) {
15605
15833
  if (existingOperation !== undefined) return existingOperation;
15606
15834
  var operation = (function() {
15607
15835
  return _async_to_generator$k(function() {
15608
- var _controlStateRef_current, _accessRef_current, connection, currentAccess, hasTemporarySpeakerGrant, ringingPrivateRoom, participant, actorId, isRingingForActor, _ref, currentSnapshot, snapshot;
15836
+ var _controlStateRef_current, _accessRef_current, connection, role, currentAccess, hasTemporarySpeakerGrant, ringingPrivateRoom, participant, actorId, isRingingForActor, _ref, currentSnapshot, snapshot;
15609
15837
  return _ts_generator$k(this, function(_state) {
15610
15838
  switch(_state.label){
15611
15839
  case 0:
15612
15840
  connection = roomConnectionRef.current;
15841
+ role = roleFromMetadata(connection === null || connection === void 0 ? void 0 : connection.room.localParticipant.metadata);
15842
+ if ((kind === 'camera' || kind === 'microphone') && isManagedParticipantRole(role)) throw new Error('ROOM_PLATFORM_MEDIA_MANAGED');
15613
15843
  if (!(kind === 'camera')) return [
15614
15844
  3,
15615
15845
  2
@@ -16020,6 +16250,7 @@ function RoomPlatformProvider(param) {
16020
16250
  localCameraTrack: localCameraTrack,
16021
16251
  localMedia: localMedia,
16022
16252
  performAction: performAction,
16253
+ reconcileLocalCameraAfterProcessor: reconcileLocalCameraAfterProcessor,
16023
16254
  room: room,
16024
16255
  setLocalMediaEnabled: setLocalMediaEnabled,
16025
16256
  status: status,
@@ -16037,6 +16268,7 @@ function RoomPlatformProvider(param) {
16037
16268
  localCameraTrack,
16038
16269
  localMedia,
16039
16270
  performAction,
16271
+ reconcileLocalCameraAfterProcessor,
16040
16272
  room,
16041
16273
  setLocalMediaEnabled,
16042
16274
  status,
@@ -18685,6 +18917,8 @@ function RoomPlatformControlBar(param) {
18685
18917
  var currentParticipant = useRoomPresence().find(function(participant) {
18686
18918
  return participant.isLocal;
18687
18919
  });
18920
+ var localRole = roleFromMetadata(room === null || room === void 0 ? void 0 : room.localParticipant.metadata);
18921
+ var managedParticipant = isManagedParticipantRole(localRole);
18688
18922
  var localParticipantIsActiveSpeaker = Boolean(access && (controlState === null || controlState === void 0 ? void 0 : controlState.activeSpeakerParticipantIdentity) === access.liveKit.participantIdentity);
18689
18923
  var canPublishNow = Boolean((currentParticipant === null || currentParticipant === void 0 ? void 0 : currentParticipant.canPublishAudio) || hasCapability('media:publish_audio') || localParticipantIsActiveSpeaker);
18690
18924
  var hasPendingSpeakRequest = Boolean(access && (controlState === null || controlState === void 0 ? void 0 : controlState.raisedHandParticipantIdentities.includes(access.liveKit.participantIdentity)));
@@ -18801,7 +19035,7 @@ function RoomPlatformControlBar(param) {
18801
19035
  className: trackButtonClassName$1,
18802
19036
  "data-control-state": enabled ? 'on' : 'off',
18803
19037
  "data-lk-enabled": enabled,
18804
- disabled: !canPublishNow || !room || isLocalMediaPending(kind),
19038
+ disabled: managedParticipant || !canPublishNow || !room || isLocalMediaPending(kind),
18805
19039
  onClick: function() {
18806
19040
  return void setLocalMediaEnabled(kind, !enabled).catch(function() {
18807
19041
  return undefined;
@@ -19106,7 +19340,7 @@ function _ts_generator$g(thisArg, body) {
19106
19340
  }
19107
19341
  }
19108
19342
  function RoomPlatformCurrentOperationStrip(param) {
19109
- var activeSpeakerParticipantIdentity = param.activeSpeakerParticipantIdentity, canClearActiveSpeaker = param.canClearActiveSpeaker, isClearingActiveSpeaker = param.isClearingActiveSpeaker, onClearActiveSpeaker = param.onClearActiveSpeaker, currentPrivateRoomOperation = param.currentPrivateRoomOperation, onCancelPrivateRoom = param.onCancelPrivateRoom, participants = param.participants, currentOperation = param.currentOperation;
19343
+ var activeSpeakerParticipantIdentity = param.activeSpeakerParticipantIdentity, canClearActiveSpeaker = param.canClearActiveSpeaker, isClearingActiveSpeaker = param.isClearingActiveSpeaker, onClearActiveSpeaker = param.onClearActiveSpeaker, currentPrivateRoomOperation = param.currentPrivateRoomOperation, onCancelPrivateRoom = param.onCancelPrivateRoom, participants = param.participants;
19110
19344
  var _ref, _ref1;
19111
19345
  var _useState = _sliced_to_array$g(useState(false), 2), isCancelingPrivateRoomOperation = _useState[0], setIsCancelingPrivateRoomOperation = _useState[1];
19112
19346
  var roomPlatformToast = useRoomPlatformToast();
@@ -19118,10 +19352,6 @@ function RoomPlatformCurrentOperationStrip(param) {
19118
19352
  return participant.externalActorId === currentPrivateRoomOperation.studentExternalActorId;
19119
19353
  }) : undefined;
19120
19354
  var privateStudentName = (_ref1 = privateStudent === null || privateStudent === void 0 ? void 0 : privateStudent.name) !== null && _ref1 !== void 0 ? _ref1 : currentPrivateRoomOperation === null || currentPrivateRoomOperation === void 0 ? void 0 : currentPrivateRoomOperation.studentExternalActorId;
19121
- var operation = currentOperation !== null && currentOperation !== void 0 ? currentOperation : activeSpeakerName ? {
19122
- label: 'Đang phát biểu',
19123
- name: activeSpeakerName
19124
- } : undefined;
19125
19355
  var cancelPrivateRoomOperation = function() {
19126
19356
  return _async_to_generator$g(function() {
19127
19357
  return _ts_generator$g(this, function(_state) {
@@ -19169,29 +19399,23 @@ function RoomPlatformCurrentOperationStrip(param) {
19169
19399
  });
19170
19400
  })();
19171
19401
  };
19172
- if (!operation && !privateStudentName) return null;
19402
+ if (!activeSpeakerName && !privateStudentName) return null;
19173
19403
  return /*#__PURE__*/ jsxs("div", {
19174
19404
  className: "grid gap-2 border-b border-primary/10 p-3",
19175
19405
  children: [
19176
- operation ? /*#__PURE__*/ jsxs("div", {
19406
+ activeSpeakerName ? /*#__PURE__*/ jsxs("div", {
19177
19407
  className: "flex items-center justify-between gap-3 rounded-lg border border-liveclass-orange/30 bg-liveclass-orange/10 px-3 py-2",
19178
19408
  children: [
19179
19409
  /*#__PURE__*/ jsxs("div", {
19180
- className: "flex min-w-0 items-center gap-2",
19410
+ className: "min-w-0",
19181
19411
  children: [
19182
- operation.leading,
19183
- /*#__PURE__*/ jsxs("div", {
19184
- className: "min-w-0",
19185
- children: [
19186
- /*#__PURE__*/ jsx("p", {
19187
- className: "text-xs font-semibold uppercase text-liveclass-orange",
19188
- children: operation.label
19189
- }),
19190
- /*#__PURE__*/ jsx("p", {
19191
- className: "truncate text-sm font-semibold text-primary",
19192
- children: operation.name
19193
- })
19194
- ]
19412
+ /*#__PURE__*/ jsx("p", {
19413
+ className: "text-xs font-semibold uppercase text-liveclass-orange",
19414
+ children: "Đang ph\xe1t biểu"
19415
+ }),
19416
+ /*#__PURE__*/ jsx("p", {
19417
+ className: "truncate text-sm font-semibold text-primary",
19418
+ children: activeSpeakerName
19195
19419
  })
19196
19420
  ]
19197
19421
  }),
@@ -20813,7 +21037,7 @@ var processorModeKey = function(mode) {
20813
21037
  return mode.mode === 'background-blur' ? "".concat(mode.mode, ":").concat(mode.blurRadius) : "".concat(mode.mode, ":").concat(mode.imagePath);
20814
21038
  };
20815
21039
  function useRoomPlatformCameraBackground(param) {
20816
- var localVideoTrack = param.localVideoTrack;
21040
+ var localVideoTrack = param.localVideoTrack, onProcessorSettled = param.onProcessorSettled;
20817
21041
  var _ref, _ref1;
20818
21042
  var _uploadItems_find, _uploadItems_;
20819
21043
  var isSupported = typeof window !== 'undefined' && supportsBackgroundProcessors();
@@ -20941,7 +21165,7 @@ function useRoomPlatformCameraBackground(param) {
20941
21165
  }, [
20942
21166
  clearUploadPreviewUrls
20943
21167
  ]);
20944
- var ensureProcessor = useCallback(function(track, mode) {
21168
+ var ensureProcessor = useCallback(function(track, mode, notifySettled) {
20945
21169
  return _async_to_generator$e(function() {
20946
21170
  var modeKey, currentEntry, processor;
20947
21171
  return _ts_generator$e(this, function(_state) {
@@ -20967,22 +21191,47 @@ function useRoomPlatformCameraBackground(param) {
20967
21191
  _state.label = 2;
20968
21192
  case 2:
20969
21193
  return [
20970
- 2
21194
+ 2,
21195
+ false
20971
21196
  ];
20972
21197
  case 3:
20973
21198
  processor = BackgroundProcessor(mode);
21199
+ _state.label = 4;
21200
+ case 4:
21201
+ _state.trys.push([
21202
+ 4,
21203
+ ,
21204
+ 6,
21205
+ 8
21206
+ ]);
20974
21207
  return [
20975
21208
  4,
20976
21209
  track.setProcessor(processor, true)
20977
21210
  ];
20978
- case 4:
21211
+ case 5:
20979
21212
  _state.sent();
21213
+ return [
21214
+ 3,
21215
+ 8
21216
+ ];
21217
+ case 6:
21218
+ return [
21219
+ 4,
21220
+ notifySettled === null || notifySettled === void 0 ? void 0 : notifySettled(track)
21221
+ ];
21222
+ case 7:
21223
+ _state.sent();
21224
+ return [
21225
+ 7
21226
+ ];
21227
+ case 8:
20980
21228
  processorByTrackRef.current.set(track, {
20981
21229
  processor: processor,
20982
21230
  modeKey: modeKey
20983
21231
  });
20984
21232
  return [
20985
- 2
21233
+ 2,
21234
+ true
20986
21235
  ];
20987
21236
  }
20988
21237
  });
@@ -21041,7 +21290,7 @@ function useRoomPlatformCameraBackground(param) {
21041
21290
  2,
21042
21291
  enqueueProcessorOperation(function() {
21043
21292
  return _async_to_generator$e(function() {
21044
- var nextObjectUrl, mode, preset, imagePath, _settings_uploadAssetId, _asset_mirroredBlob, asset, processorBlob, previousObjectUrl;
21293
+ var nextObjectUrl, mode, preset, imagePath, _settings_uploadAssetId, _asset_mirroredBlob, asset, processorBlob, processorSettledInEnsure, previousObjectUrl;
21045
21294
  return _ts_generator$e(this, function(_state) {
21046
21295
  switch(_state.label){
21047
21296
  case 0:
@@ -21054,9 +21303,9 @@ function useRoomPlatformCameraBackground(param) {
21054
21303
  case 1:
21055
21304
  _state.trys.push([
21056
21305
  1,
21057
- 8,
21306
+ 10,
21058
21307
  ,
21059
- 9
21308
+ 11
21060
21309
  ]);
21061
21310
  if (!(settings.mode === 'none')) return [
21062
21311
  3,
@@ -21123,10 +21372,22 @@ function useRoomPlatformCameraBackground(param) {
21123
21372
  case 6:
21124
21373
  return [
21125
21374
  4,
21126
- ensureProcessor(localVideoTrack, mode)
21375
+ ensureProcessor(localVideoTrack, mode, onProcessorSettled)
21127
21376
  ];
21128
21377
  case 7:
21378
+ processorSettledInEnsure = _state.sent();
21379
+ if (!!processorSettledInEnsure) return [
21380
+ 3,
21381
+ 9
21382
+ ];
21383
+ return [
21384
+ 4,
21385
+ onProcessorSettled === null || onProcessorSettled === void 0 ? void 0 : onProcessorSettled(localVideoTrack)
21386
+ ];
21387
+ case 8:
21129
21388
  _state.sent();
21389
+ _state.label = 9;
21390
+ case 9:
21130
21391
  previousObjectUrl = activeObjectUrlRef.current;
21131
21392
  activeObjectUrlRef.current = nextObjectUrl;
21132
21393
  if (previousObjectUrl && previousObjectUrl !== nextObjectUrl) {
@@ -21147,7 +21408,7 @@ function useRoomPlatformCameraBackground(param) {
21147
21408
  2,
21148
21409
  true
21149
21410
  ];
21150
- case 8:
21411
+ case 10:
21151
21412
  _state.sent();
21152
21413
  if (nextObjectUrl && activeObjectUrlRef.current !== nextObjectUrl) {
21153
21414
  URL.revokeObjectURL(nextObjectUrl);
@@ -21164,7 +21425,7 @@ function useRoomPlatformCameraBackground(param) {
21164
21425
  2,
21165
21426
  false
21166
21427
  ];
21167
- case 9:
21428
+ case 11:
21168
21429
  return [
21169
21430
  2
21170
21431
  ];
@@ -21179,7 +21440,8 @@ function useRoomPlatformCameraBackground(param) {
21179
21440
  enqueueProcessorOperation,
21180
21441
  ensureProcessor,
21181
21442
  isSupported,
21182
- localVideoTrack
21443
+ localVideoTrack,
21444
+ onProcessorSettled
21183
21445
  ]);
21184
21446
  var saveAndApply = useCallback(function(input) {
21185
21447
  return _async_to_generator$e(function() {
@@ -21574,7 +21836,7 @@ function useRoomPlatformCameraBackground(param) {
21574
21836
  case 0:
21575
21837
  if (!localVideoTrack) return [
21576
21838
  3,
21577
- 5
21839
+ 6
21578
21840
  ];
21579
21841
  _state.label = 1;
21580
21842
  case 1:
@@ -21582,7 +21844,7 @@ function useRoomPlatformCameraBackground(param) {
21582
21844
  1,
21583
21845
  3,
21584
21846
  4,
21585
- 5
21847
+ 6
21586
21848
  ]);
21587
21849
  return [
21588
21850
  4,
@@ -21592,20 +21854,26 @@ function useRoomPlatformCameraBackground(param) {
21592
21854
  _state.sent();
21593
21855
  return [
21594
21856
  3,
21595
- 5
21857
+ 6
21596
21858
  ];
21597
21859
  case 3:
21598
21860
  _state.sent();
21599
21861
  return [
21600
21862
  3,
21601
- 5
21863
+ 6
21602
21864
  ];
21603
21865
  case 4:
21604
21866
  processors.delete(localVideoTrack);
21605
21867
  return [
21606
- 7
21868
+ 4,
21869
+ onProcessorSettled === null || onProcessorSettled === void 0 ? void 0 : onProcessorSettled(localVideoTrack)
21607
21870
  ];
21608
21871
  case 5:
21872
+ _state.sent();
21873
+ return [
21874
+ 7
21875
+ ];
21876
+ case 6:
21609
21877
  clearActiveObjectUrl();
21610
21878
  return [
21611
21879
  2
@@ -21618,7 +21886,8 @@ function useRoomPlatformCameraBackground(param) {
21618
21886
  }, [
21619
21887
  clearActiveObjectUrl,
21620
21888
  enqueueProcessorOperation,
21621
- localVideoTrack
21889
+ localVideoTrack,
21890
+ onProcessorSettled
21622
21891
  ]);
21623
21892
  useEffect(function() {
21624
21893
  var restore = function() {
@@ -29138,7 +29407,6 @@ var RoomPlatformWorkspaceContent = function(param) {
29138
29407
  canClearActiveSpeaker: canModerate,
29139
29408
  isClearingActiveSpeaker: isClearingActiveSpeaker,
29140
29409
  onClearActiveSpeaker: canModerate ? clearActiveSpeaker : undefined,
29141
- currentOperation: extensions === null || extensions === void 0 ? void 0 : extensions.currentOperation,
29142
29410
  currentPrivateRoomOperation: currentPrivateRoomOperation,
29143
29411
  onCancelPrivateRoom: cancelPrivateRoom,
29144
29412
  participants: participants
@@ -29318,9 +29586,10 @@ var RoomPlatformConnectedWorkspace = function(props) {
29318
29586
  }));
29319
29587
  };
29320
29588
  var RoomPlatformWorkspace = function(props) {
29321
- var _useRoomPlatform = useRoomPlatform(), localCameraTrack = _useRoomPlatform.localCameraTrack, room = _useRoomPlatform.room;
29589
+ var _useRoomPlatform = useRoomPlatform(), localCameraTrack = _useRoomPlatform.localCameraTrack, reconcileLocalCameraAfterProcessor = _useRoomPlatform.reconcileLocalCameraAfterProcessor, room = _useRoomPlatform.room;
29322
29590
  var cameraBackground = useRoomPlatformCameraBackground({
29323
- localVideoTrack: localCameraTrack
29591
+ localVideoTrack: localCameraTrack,
29592
+ onProcessorSettled: reconcileLocalCameraAfterProcessor
29324
29593
  });
29325
29594
  return room ? /*#__PURE__*/ jsx(RoomPlatformConnectedWorkspace, _object_spread_props(_object_spread({}, props), {
29326
29595
  cameraBackground: cameraBackground
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naviedu/room-platform-react",
3
- "version": "0.0.42",
3
+ "version": "0.0.43",
4
4
  "type": "module",
5
5
  "main": "./index.esm.js",
6
6
  "module": "./index.esm.js",