Skip to content

Commit

Permalink
Merge branch 'main' into daily-js-releases
Browse files Browse the repository at this point in the history
  • Loading branch information
Daily Autobot committed Jun 7, 2023
2 parents 7f8da8b + 114b32e commit 7c4a311
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 19 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ Please check our [our documentation site](https://docs.daily.co/) to get started

# ⚠ Upcoming changes that may require action

## Refactoring of Logic around Gathering and Updating Local Media

**Project Code Name: v2 Cam And Mic**

We are gradually rolling out a complete refactor of our internal logic that deals with gathering and updating a client's local media (unmuting, changing devices, etc). This refactor will resolve a number of known issues around local device handling and simplify usage and permissions gathering that have long been a source of customer frustrations🎉. We will be porting all domains to use this new logic in the 0.47.0 or 0.48.0 release (depending on timing and success of the rollout).

Nothing is required of you to adopt these changes at the time of rollout, but if you would like to opt in early to try the refactor beforehand, simply specify `dailyConfig: { v2CamAndMic: true }` wherever you provide your [call options](https://docs.daily.co/reference/daily-js/daily-iframe-class/properties). While we are comprehensively testing the refactor to catch any issues, we recommend previewing and testing this behavior if you have unique or complicated setups around local media devices.

### Prebuilt Users:
This behavior is already being rolled out gradually across a percentage of prebuilt calls. If you believe you are seeing an increase in issues around local media, please reach out to [email protected].

### In the dashboard:
To determine if a given user session is using new (v2) or old logic, look for the log line:

```
using v2 cam and mic logic: <true/false>
```

## `avoidEval` will become `true` by default

Today you can opt in to making `daily-js` behave in a CSP-friendly way by specifying `dailyConfig: { avoidEval: true }` wherever you provide your [call options](https://docs.daily.co/reference/daily-js/daily-iframe-class/properties). You can read more about this option and how to set up your CSP (Content Security Policy) in [this guide](https://docs.daily.co/guides/privacy-and-security/content-security-policy#custom-call-object).
Expand Down
101 changes: 92 additions & 9 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,12 @@ export interface DailyMicAudioModeSettings {

export interface DailyAdvancedConfig {
camSimulcastEncodings?: any[];
/**
* @deprecated This property will be removed. Use the method updateSendSettings instead.
*/
disableSimulcast?: boolean;
keepCamIndicatorLightOn?: boolean;
v2CamAndMic?: boolean;
experimentalGetUserMediaConstraintsModify?: (
constraints: MediaStreamConstraints
) => void;
Expand Down Expand Up @@ -433,18 +437,37 @@ export type DailyParticipantPermissionsUpdate = {
};

export interface DailyParticipant {
// tracks
audioTrack?: MediaStreamTrack;
videoTrack?: MediaStreamTrack;
screenVideoTrack?: MediaStreamTrack;
screenAudioTrack?: MediaStreamTrack;
/**
* @deprecated This property will be removed. Use tracks.audio.persistentTrack instead.
*/
audioTrack?: MediaStreamTrack | false;
/**
* @deprecated This property will be removed. Use tracks.video.persistentTrack instead.
*/
videoTrack?: MediaStreamTrack | false;
/**
* @deprecated This property will be removed. Use tracks.screenVideo.persistentTrack instead.
*/
screenVideoTrack?: MediaStreamTrack | false;
/**
* @deprecated This property will be removed. Use tracks.screenAudio.persistentTrack instead.
*/
screenAudioTrack?: MediaStreamTrack | false;

// legacy track state
/**
* @deprecated This property will be removed. Use tracks.audio.state instead.
*/
audio: boolean;
/**
* @deprecated This property will be removed. Use tracks.video.state instead.
*/
video: boolean;
/**
* @deprecated This property will be removed. Use tracks.screenVideo.state instead.
*/
screen: boolean;

// new track state
// track state
tracks: {
audio: DailyTrackState;
video: DailyTrackState;
Expand Down Expand Up @@ -539,14 +562,66 @@ export interface DailyDeviceInfos {
speaker: {} | MediaDeviceInfo;
}

/**
* @deprecated
* Almost all the properties in this type were just used by Electron.
* And the mediaStream can be replaced to use custom tracks.
*/
export interface DailyScreenCaptureOptions {
/**
* @deprecated This property will be removed. It is only used for Electron.
*/
audio?: boolean;
/**
* @deprecated This property will be removed. It is only used for Electron.
*/
maxWidth?: number;
/**
* @deprecated This property will be removed. It is only used for Electron.
*/
maxHeight?: number;
/**
* @deprecated This property will be removed. It is only used for Electron.
*/
chromeMediaSourceId?: string;
/**
* @deprecated This property will be removed. It is recommended to use our custom tracks API.
*/
mediaStream?: MediaStream;
}

// More details about all the possible options
// https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getDisplayMedia
export interface DailyDisplayMediaStreamOptions {
audio?: boolean | MediaTrackConstraints;
video?: boolean | MediaTrackConstraints;
selfBrowserSurface?: 'include' | 'exclude';
surfaceSwitching?: 'include' | 'exclude';
systemAudio?: 'include' | 'exclude';
}

export interface DailyDisplayMediaStreamOptionsElectron {
audio?: boolean;
video: {
maxWidth?: number;
maxHeight?: number;
};
chromeMediaSourceId?: string;
}

export interface DailyStartScreenShare {
displayMediaOptions?:
| DailyDisplayMediaStreamOptions
| DailyDisplayMediaStreamOptionsElectron;
screenVideoSendSettings?:
| DailyVideoSendSettings
| DailyScreenVideoSendSettingsPreset;
}

export type DailyStartScreenShareOptions =
| DailyScreenCaptureOptions
| DailyStartScreenShare;

export interface DailyNetworkStats {
quality: number;
stats: {
Expand Down Expand Up @@ -599,14 +674,16 @@ export interface DailyCpuLoadStats {
interface DailySendSettings {
video?: DailyVideoSendSettings | DailyVideoSendSettingsPreset;
customVideoDefaults?: DailyVideoSendSettings | DailyVideoSendSettingsPreset;
screenVideo?: DailyVideoSendSettings | DailyScreenVideoSendSettingsPreset;
[customKey: string]:
| DailyVideoSendSettings
| DailyVideoSendSettingsPreset
| DailyScreenVideoSendSettingsPreset
| undefined;
}

export type DailyVideoSendSettingsPreset =
| 'default'
| 'default-video'
| 'bandwidth-optimized'
| 'bandwidth-and-quality-balanced'
| 'quality-optimized';
Expand All @@ -621,6 +698,12 @@ interface DailyVideoSendSettings {
};
}

export type DailyScreenVideoSendSettingsPreset =
| 'default-screen-video'
| 'detail-optimized'
| 'motion-optimized'
| 'motion-and-detail-balanced';

export interface DailyPendingRoomInfo {
roomUrlPendingJoin: string;
}
Expand Down Expand Up @@ -1587,7 +1670,7 @@ export interface DailyCall {
getInputDevices(): Promise<DailyDeviceInfos>;
preAuth(properties?: DailyCallOptions): Promise<{ access: DailyAccess }>;
load(properties?: DailyLoadOptions): Promise<void>;
startScreenShare(captureOptions?: DailyScreenCaptureOptions): void;
startScreenShare(properties?: DailyStartScreenShareOptions): void;
stopScreenShare(): void;
startRecording(options?: DailyStreamingOptions<'recording', 'start'>): void;
updateRecording(options: {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@daily-co/daily-js",
"private": true,
"//": "^ COMMENT OUT 'private: true' BEFORE RUNNING NPM PUBLISH",
"version": "0.45.0",
"version": "0.46.0-internal.21",
"engines": {
"node": ">=10.0.0"
},
Expand Down
28 changes: 24 additions & 4 deletions src/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ import {
LOW_BANDWIDTH_VIDEO_SEND_SETTINGS_PRESET_KEY,
HIGH_BANDWIDTH_VIDEO_SEND_SETTINGS_PRESET_KEY,
MEDIUM_BANDWIDTH_VIDEO_SEND_SETTINGS_PRESET_KEY,
DETAIL_OPTIMIZED_SCREEN_VIDEO_SEND_SETTINGS_PRESET_KEY,
MOTION_OPTIMIZED_SCREEN_VIDEO_SEND_SETTINGS_PRESET_KEY,
MOTION_AND_DETAIL_BALANCED_SCREEN_VIDEO_SEND_SETTINGS_PRESET_KEY,
DEFAULT_SCREEN_VIDEO_SEND_SETTINGS_PRESET_KEY,
} from './shared-with-pluot-core/CommonIncludes.js';
import {
isReactNative,
Expand Down Expand Up @@ -2566,6 +2570,12 @@ export default class DailyIframe extends EventEmitter {

startScreenShare(captureOptions = {}) {
methodNotSupportedInReactNative();
if (captureOptions.screenVideoSendSettings) {
this._validateVideoSendSettings(
'screenVideo',
captureOptions.screenVideoSendSettings
);
}
if (captureOptions.mediaStream) {
this._preloadCache.screenMediaStream = captureOptions.mediaStream;
captureOptions.mediaStream = DAILY_CUSTOM_TRACK;
Expand Down Expand Up @@ -2834,13 +2844,23 @@ export default class DailyIframe extends EventEmitter {
});
}

_validateVideoSendSettings(videoSendSettings) {
const supportedPresets = [
_validateVideoSendSettings(trackName, videoSendSettings) {
const videoSupportedPresets = [
DEFAULT_VIDEO_SEND_SETTINGS_PRESET_KEY,
LOW_BANDWIDTH_VIDEO_SEND_SETTINGS_PRESET_KEY,
MEDIUM_BANDWIDTH_VIDEO_SEND_SETTINGS_PRESET_KEY,
HIGH_BANDWIDTH_VIDEO_SEND_SETTINGS_PRESET_KEY,
];
const screenVideoSupportedPresets = [
DEFAULT_SCREEN_VIDEO_SEND_SETTINGS_PRESET_KEY,
DETAIL_OPTIMIZED_SCREEN_VIDEO_SEND_SETTINGS_PRESET_KEY,
MOTION_OPTIMIZED_SCREEN_VIDEO_SEND_SETTINGS_PRESET_KEY,
MOTION_AND_DETAIL_BALANCED_SCREEN_VIDEO_SEND_SETTINGS_PRESET_KEY,
];
const supportedPresets =
trackName === 'screenVideo'
? screenVideoSupportedPresets
: videoSupportedPresets;
const supportedVideoSendSettingsErrorMsg = `Video send settings should be either an object or one of the supported presets: ${supportedPresets.join()}`;
if (typeof videoSendSettings === 'string') {
if (!supportedPresets.includes(videoSendSettings)) {
Expand Down Expand Up @@ -2896,8 +2916,8 @@ export default class DailyIframe extends EventEmitter {
'Send settings must contain at least information for one track!'
);
}
Object.values(sendSettings).forEach((videoSendSettings) => {
this._validateVideoSendSettings(videoSendSettings);
Object.entries(sendSettings).forEach(([trackName, videoSendSettings]) => {
this._validateVideoSendSettings(trackName, videoSendSettings);
});
}

Expand Down
11 changes: 10 additions & 1 deletion src/shared-with-pluot-core/CommonIncludes.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,16 @@ export const LOW_BANDWIDTH_VIDEO_SEND_SETTINGS_PRESET_KEY =
'bandwidth-optimized';
export const MEDIUM_BANDWIDTH_VIDEO_SEND_SETTINGS_PRESET_KEY =
'bandwidth-and-quality-balanced';
export const DEFAULT_VIDEO_SEND_SETTINGS_PRESET_KEY = 'default';
export const DEFAULT_VIDEO_SEND_SETTINGS_PRESET_KEY = 'default-video';
export const DEFAULT_SCREEN_VIDEO_SEND_SETTINGS_PRESET_KEY =
'default-screen-video';

export const DETAIL_OPTIMIZED_SCREEN_VIDEO_SEND_SETTINGS_PRESET_KEY =
'detail-optimized';
export const MOTION_OPTIMIZED_SCREEN_VIDEO_SEND_SETTINGS_PRESET_KEY =
'motion-optimized';
export const MOTION_AND_DETAIL_BALANCED_SCREEN_VIDEO_SEND_SETTINGS_PRESET_KEY =
'motion-and-detail-balanced';

// error types

Expand Down
4 changes: 4 additions & 0 deletions src/test/CustomTracks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ describe('Custom tracks', () => {
callObject = DailyIframe.createCallObject();
});

afterEach(() => {
callObject.destroy();
});

test('Track name must not have more than 50 characters', () => {
const track = new MediaStreamTrack();
const trackName = '51_characters_string_000000000000000000000000000000';
Expand Down
4 changes: 4 additions & 0 deletions src/test/DailyConfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ describe('DailyConfig', () => {
callObject = DailyIframe.createCallObject();
});

afterEach(() => {
callObject.destroy();
});

test('Not throw error with empty config', () => {
const dailyConfig = {};
expect(() => callObject.validateDailyConfig(dailyConfig)).not.toThrow();
Expand Down
8 changes: 6 additions & 2 deletions src/test/UpdateSendSettings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ describe('UpdateSendSettings', () => {
callObject = DailyIframe.createCallObject();
});

afterEach(() => {
callObject.destroy();
});

test('updateSendSettings object must not be null or empty', () => {
let updateSendSettings = null;
expect(() =>
Expand Down Expand Up @@ -50,7 +54,7 @@ describe('UpdateSendSettings', () => {
expect(() =>
callObject.validateUpdateSendSettings(updateSendSettings)
).toThrowError(
'Video send settings should be either an object or one of the supported presets: default,bandwidth-optimized,bandwidth-and-quality-balanced,quality-optimized'
'Video send settings should be either an object or one of the supported presets: default-video,bandwidth-optimized,bandwidth-and-quality-balanced,quality-optimized'
);
updateSendSettings = {
video: DEFAULT_VIDEO_SEND_SETTINGS_PRESET_KEY,
Expand Down Expand Up @@ -85,7 +89,7 @@ describe('UpdateSendSettings', () => {
expect(() =>
callObject.validateUpdateSendSettings(updateSendSettings)
).toThrowError(
'Video send settings should be either an object or one of the supported presets: default,bandwidth-optimized,bandwidth-and-quality-balanced,quality-optimized'
'Video send settings should be either an object or one of the supported presets: default-video,bandwidth-optimized,bandwidth-and-quality-balanced,quality-optimized'
);
});

Expand Down

0 comments on commit 7c4a311

Please sign in to comment.