UNPKG

1.58 kBJavaScriptView Raw
1import { isSfuSupported } from './shared-with-pluot-core/Environment';
2
3export function randomStringId() {
4 return Date.now() + Math.random().toString();
5}
6
7export function notImplementedError() {
8 throw new Error('Method must be implemented in subclass');
9}
10
11export function callObjectBundleUrl(meetingOrBaseUrl) {
12 // Take the provided URL, which is either a meeting URL (like
13 // https://somecompany.daily.co/hello) or a base URL (like
14 // https://somecompany.daily.co), and make it a base URL.
15 let baseUrl = meetingOrBaseUrl ? new URL(meetingOrBaseUrl).origin : null;
16
17 // Production:
18 // - no url provided --> load bundle from c.daily.co (CDN)
19 // - x.daily.co url provided --> load bundle from c.daily.co (CDN)
20 // - x.staging.daily.co url provided --> see dev/staging logic
21 if (
22 process.env.NODE_ENV === 'production' &&
23 (!baseUrl || baseUrl.match(/https:\/\/[^.]+\.daily\.co/))
24 ) {
25 if (!isSfuSupported()) {
26 return `https://c.daily.co/static/call-machine-object-nosfu-bundle.js`;
27 } else {
28 return `https://c.daily.co/static/call-machine-object-bundle.js`;
29 }
30 }
31
32 // Dev/staging:
33 // - no url provided --> error
34 // - url provided --> load bundle from url
35 if (!baseUrl) {
36 console.warn(
37 'No baseUrl provided for call object bundle. Defaulting to production CDN...'
38 );
39 baseUrl = 'https://c.daily.co';
40 }
41 if (!isSfuSupported()) {
42 return `${baseUrl}/static/call-machine-object-nosfu-bundle.js`;
43 } else {
44 return `${baseUrl}/static/call-machine-object-bundle.js`;
45 }
46}