@naviedu/room-platform-react 0.0.41 → 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 +3 -1
  2. package/index.esm.js +335 -55
  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;
@@ -696,7 +697,7 @@ declare type RoomPrivateRoomStatus = 'ringing' | 'active';
696
697
 
697
698
  export declare function useRoomPlatform(): RoomPlatformContextValue;
698
699
 
699
- declare function useRoomPlatformCameraBackground({ localVideoTrack }: UseRoomPlatformCameraBackgroundInput): {
700
+ declare function useRoomPlatformCameraBackground({ localVideoTrack, onProcessorSettled, }: UseRoomPlatformCameraBackgroundInput): {
700
701
  state: RoomPlatformCameraBackgroundState;
701
702
  uploadItems: RoomPlatformCameraBackgroundUploadPreview[];
702
703
  uploadPreviewUrl: string;
@@ -713,6 +714,7 @@ declare function useRoomPlatformCameraBackground({ localVideoTrack }: UseRoomPla
713
714
 
714
715
  declare type UseRoomPlatformCameraBackgroundInput = {
715
716
  localVideoTrack: LocalVideoTrack | null;
717
+ onProcessorSettled?: (track: LocalVideoTrack) => void | Promise<void>;
716
718
  };
717
719
 
718
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;
@@ -20803,7 +21037,7 @@ var processorModeKey = function(mode) {
20803
21037
  return mode.mode === 'background-blur' ? "".concat(mode.mode, ":").concat(mode.blurRadius) : "".concat(mode.mode, ":").concat(mode.imagePath);
20804
21038
  };
20805
21039
  function useRoomPlatformCameraBackground(param) {
20806
- var localVideoTrack = param.localVideoTrack;
21040
+ var localVideoTrack = param.localVideoTrack, onProcessorSettled = param.onProcessorSettled;
20807
21041
  var _ref, _ref1;
20808
21042
  var _uploadItems_find, _uploadItems_;
20809
21043
  var isSupported = typeof window !== 'undefined' && supportsBackgroundProcessors();
@@ -20931,7 +21165,7 @@ function useRoomPlatformCameraBackground(param) {
20931
21165
  }, [
20932
21166
  clearUploadPreviewUrls
20933
21167
  ]);
20934
- var ensureProcessor = useCallback(function(track, mode) {
21168
+ var ensureProcessor = useCallback(function(track, mode, notifySettled) {
20935
21169
  return _async_to_generator$e(function() {
20936
21170
  var modeKey, currentEntry, processor;
20937
21171
  return _ts_generator$e(this, function(_state) {
@@ -20957,22 +21191,47 @@ function useRoomPlatformCameraBackground(param) {
20957
21191
  _state.label = 2;
20958
21192
  case 2:
20959
21193
  return [
20960
- 2
21194
+ 2,
21195
+ false
20961
21196
  ];
20962
21197
  case 3:
20963
21198
  processor = BackgroundProcessor(mode);
21199
+ _state.label = 4;
21200
+ case 4:
21201
+ _state.trys.push([
21202
+ 4,
21203
+ ,
21204
+ 6,
21205
+ 8
21206
+ ]);
20964
21207
  return [
20965
21208
  4,
20966
21209
  track.setProcessor(processor, true)
20967
21210
  ];
20968
- case 4:
21211
+ case 5:
20969
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:
20970
21228
  processorByTrackRef.current.set(track, {
20971
21229
  processor: processor,
20972
21230
  modeKey: modeKey
20973
21231
  });
20974
21232
  return [
20975
- 2
21233
+ 2,
21234
+ true
20976
21235
  ];
20977
21236
  }
20978
21237
  });
@@ -21031,7 +21290,7 @@ function useRoomPlatformCameraBackground(param) {
21031
21290
  2,
21032
21291
  enqueueProcessorOperation(function() {
21033
21292
  return _async_to_generator$e(function() {
21034
- 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;
21035
21294
  return _ts_generator$e(this, function(_state) {
21036
21295
  switch(_state.label){
21037
21296
  case 0:
@@ -21044,9 +21303,9 @@ function useRoomPlatformCameraBackground(param) {
21044
21303
  case 1:
21045
21304
  _state.trys.push([
21046
21305
  1,
21047
- 8,
21306
+ 10,
21048
21307
  ,
21049
- 9
21308
+ 11
21050
21309
  ]);
21051
21310
  if (!(settings.mode === 'none')) return [
21052
21311
  3,
@@ -21113,10 +21372,22 @@ function useRoomPlatformCameraBackground(param) {
21113
21372
  case 6:
21114
21373
  return [
21115
21374
  4,
21116
- ensureProcessor(localVideoTrack, mode)
21375
+ ensureProcessor(localVideoTrack, mode, onProcessorSettled)
21117
21376
  ];
21118
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:
21119
21388
  _state.sent();
21389
+ _state.label = 9;
21390
+ case 9:
21120
21391
  previousObjectUrl = activeObjectUrlRef.current;
21121
21392
  activeObjectUrlRef.current = nextObjectUrl;
21122
21393
  if (previousObjectUrl && previousObjectUrl !== nextObjectUrl) {
@@ -21137,7 +21408,7 @@ function useRoomPlatformCameraBackground(param) {
21137
21408
  2,
21138
21409
  true
21139
21410
  ];
21140
- case 8:
21411
+ case 10:
21141
21412
  _state.sent();
21142
21413
  if (nextObjectUrl && activeObjectUrlRef.current !== nextObjectUrl) {
21143
21414
  URL.revokeObjectURL(nextObjectUrl);
@@ -21154,7 +21425,7 @@ function useRoomPlatformCameraBackground(param) {
21154
21425
  2,
21155
21426
  false
21156
21427
  ];
21157
- case 9:
21428
+ case 11:
21158
21429
  return [
21159
21430
  2
21160
21431
  ];
@@ -21169,7 +21440,8 @@ function useRoomPlatformCameraBackground(param) {
21169
21440
  enqueueProcessorOperation,
21170
21441
  ensureProcessor,
21171
21442
  isSupported,
21172
- localVideoTrack
21443
+ localVideoTrack,
21444
+ onProcessorSettled
21173
21445
  ]);
21174
21446
  var saveAndApply = useCallback(function(input) {
21175
21447
  return _async_to_generator$e(function() {
@@ -21564,7 +21836,7 @@ function useRoomPlatformCameraBackground(param) {
21564
21836
  case 0:
21565
21837
  if (!localVideoTrack) return [
21566
21838
  3,
21567
- 5
21839
+ 6
21568
21840
  ];
21569
21841
  _state.label = 1;
21570
21842
  case 1:
@@ -21572,7 +21844,7 @@ function useRoomPlatformCameraBackground(param) {
21572
21844
  1,
21573
21845
  3,
21574
21846
  4,
21575
- 5
21847
+ 6
21576
21848
  ]);
21577
21849
  return [
21578
21850
  4,
@@ -21582,20 +21854,26 @@ function useRoomPlatformCameraBackground(param) {
21582
21854
  _state.sent();
21583
21855
  return [
21584
21856
  3,
21585
- 5
21857
+ 6
21586
21858
  ];
21587
21859
  case 3:
21588
21860
  _state.sent();
21589
21861
  return [
21590
21862
  3,
21591
- 5
21863
+ 6
21592
21864
  ];
21593
21865
  case 4:
21594
21866
  processors.delete(localVideoTrack);
21595
21867
  return [
21596
- 7
21868
+ 4,
21869
+ onProcessorSettled === null || onProcessorSettled === void 0 ? void 0 : onProcessorSettled(localVideoTrack)
21597
21870
  ];
21598
21871
  case 5:
21872
+ _state.sent();
21873
+ return [
21874
+ 7
21875
+ ];
21876
+ case 6:
21599
21877
  clearActiveObjectUrl();
21600
21878
  return [
21601
21879
  2
@@ -21608,7 +21886,8 @@ function useRoomPlatformCameraBackground(param) {
21608
21886
  }, [
21609
21887
  clearActiveObjectUrl,
21610
21888
  enqueueProcessorOperation,
21611
- localVideoTrack
21889
+ localVideoTrack,
21890
+ onProcessorSettled
21612
21891
  ]);
21613
21892
  useEffect(function() {
21614
21893
  var restore = function() {
@@ -29307,9 +29586,10 @@ var RoomPlatformConnectedWorkspace = function(props) {
29307
29586
  }));
29308
29587
  };
29309
29588
  var RoomPlatformWorkspace = function(props) {
29310
- var _useRoomPlatform = useRoomPlatform(), localCameraTrack = _useRoomPlatform.localCameraTrack, room = _useRoomPlatform.room;
29589
+ var _useRoomPlatform = useRoomPlatform(), localCameraTrack = _useRoomPlatform.localCameraTrack, reconcileLocalCameraAfterProcessor = _useRoomPlatform.reconcileLocalCameraAfterProcessor, room = _useRoomPlatform.room;
29311
29590
  var cameraBackground = useRoomPlatformCameraBackground({
29312
- localVideoTrack: localCameraTrack
29591
+ localVideoTrack: localCameraTrack,
29592
+ onProcessorSettled: reconcileLocalCameraAfterProcessor
29313
29593
  });
29314
29594
  return room ? /*#__PURE__*/ jsx(RoomPlatformConnectedWorkspace, _object_spread_props(_object_spread({}, props), {
29315
29595
  cameraBackground: cameraBackground
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naviedu/room-platform-react",
3
- "version": "0.0.41",
3
+ "version": "0.0.43",
4
4
  "type": "module",
5
5
  "main": "./index.esm.js",
6
6
  "module": "./index.esm.js",