Skip to content

Commit eb73e14

Browse files
author
Daily Autobot
committed
Merge branch 'main' into daily-js-releases
2 parents e5b9d60 + cc836b0 commit eb73e14

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

src/hooks/useCallInstance.ts

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import { customDeepEqual } from '../lib/customDeepEqual';
55

66
type InstanceType = 'callFrame' | 'callObject';
77

8-
const defaultOptions: DailyFactoryOptions = {};
8+
const defaultOptions: DailyFactoryOptions = {
9+
strictMode: true,
10+
};
911
const defaultShouldCreateInstance = () => true;
1012

1113
export interface Props {
@@ -100,23 +102,30 @@ export const useCallInstance = (
100102
* but should be created.
101103
* Important to spread props, because createCallObject/createFrame alters the passed object (adds layout and dailyJsVersion).
102104
*/
103-
switch (type) {
104-
case 'callFrame':
105-
co = parentElRef?.current
106-
? Daily.createFrame(parentElRef.current, { ...options })
107-
: Daily.createFrame({ ...options });
108-
break;
109-
case 'callObject':
110-
co = Daily.createCallObject({ ...options });
111-
break;
105+
try {
106+
switch (type) {
107+
case 'callFrame':
108+
co = parentElRef?.current
109+
? Daily.createFrame(parentElRef.current, { ...options })
110+
: Daily.createFrame({ ...options });
111+
break;
112+
case 'callObject':
113+
co = Daily.createCallObject({ ...options });
114+
break;
115+
}
116+
lastUsedOptions.current = options;
117+
118+
setCallInstance(co);
119+
120+
co.once('call-instance-destroyed', handleDestroyedInstance);
121+
} catch (e) {
122+
console.error('Error creating call instance:', e);
123+
if (options.strictMode) {
124+
throw e;
125+
}
112126
}
113-
lastUsedOptions.current = options;
114127
}
115128

116-
setCallInstance(co);
117-
118-
co.once('call-instance-destroyed', handleDestroyedInstance);
119-
120129
/**
121130
* No cleanup phase here, because callObject.destroy() returns a Promise.
122131
* We can't have asynchronous cleanups in a useEffect.

src/hooks/useCallObject.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ type CallObjectProps = Omit<Props, 'parentEl'>;
44

55
/**
66
* Helper hook to maintain custom callObject instances in React codebases.
7+
* This hook will throw an error if the call object cannot be created in strict mode,
8+
* which is true when the browser doesn't support WebRTC.
79
*/
810
export const useCallObject = (props: CallObjectProps) =>
911
useCallInstance('callObject', props);

0 commit comments

Comments
 (0)