Skip to content

Commit

Permalink
Surface encryption error on LiveKitRoom (#706)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasIO authored Nov 12, 2023
1 parent 9211eb0 commit 00be594
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/cyan-yaks-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@livekit/components-react": patch
---

Surface encryption error on LiveKitRoom
2 changes: 2 additions & 0 deletions packages/react/etc/components-react.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ export interface LiveKitRoomProps extends Omit<React_2.HTMLAttributes<HTMLDivEle
// (undocumented)
onDisconnected?: () => void;
// (undocumented)
onEncryptionError?: (error: Error) => void;
// (undocumented)
onError?: (error: Error) => void;
// (undocumented)
onMediaDeviceFailure?: (failure?: MediaDeviceFailure) => void;
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/components/LiveKitRoom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export interface LiveKitRoomProps extends Omit<React.HTMLAttributes<HTMLDivEleme
onDisconnected?: () => void;
onError?: (error: Error) => void;
onMediaDeviceFailure?: (failure?: MediaDeviceFailure) => void;
onEncryptionError?: (error: Error) => void;
/**
* Optional room instance.
* By passing your own room instance you overwrite the `options` parameter,
Expand Down
20 changes: 14 additions & 6 deletions packages/react/src/hooks/useLiveKitRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export function useLiveKitRoom<T extends HTMLElement>(
onDisconnected,
onError,
onMediaDeviceFailure,
onEncryptionError,
simulateParticipants,
...rest
} = { ...defaultRoomProps, ...props };
Expand Down Expand Up @@ -79,18 +80,25 @@ export function useLiveKitRoom<T extends HTMLElement>(
});
};

const onMediaDeviceError = (e: Error) => {
const handleMediaDeviceError = (e: Error) => {
const mediaDeviceFailure = MediaDeviceFailure.getFailure(e);
onMediaDeviceFailure?.(mediaDeviceFailure);
};
room.on(RoomEvent.SignalConnected, onSignalConnected);
room.on(RoomEvent.MediaDevicesError, onMediaDeviceError);
const handleEncryptionError = (e: Error) => {
onEncryptionError?.(e);
};
room
.on(RoomEvent.SignalConnected, onSignalConnected)
.on(RoomEvent.MediaDevicesError, handleMediaDeviceError)
.on(RoomEvent.EncryptionError, handleEncryptionError);

return () => {
room.off(RoomEvent.SignalConnected, onSignalConnected);
room.off(RoomEvent.MediaDevicesError, onMediaDeviceError);
room
.off(RoomEvent.SignalConnected, onSignalConnected)
.off(RoomEvent.MediaDevicesError, handleMediaDeviceError)
.off(RoomEvent.EncryptionError, handleEncryptionError);
};
}, [room, audio, video, screen, onError]);
}, [room, audio, video, screen, onError, onEncryptionError, onMediaDeviceFailure]);

React.useEffect(() => {
if (!room) return;
Expand Down

0 comments on commit 00be594

Please sign in to comment.