@stream-io/video-client 0.3.0 → 0.3.2
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.
- package/CHANGELOG.md +19 -0
- package/dist/index.browser.es.js +863 -455
- package/dist/index.browser.es.js.map +1 -1
- package/dist/index.cjs.js +867 -453
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +863 -455
- package/dist/index.es.js.map +1 -1
- package/dist/src/Call.d.ts +18 -1
- package/dist/src/devices/CameraManager.d.ts +31 -0
- package/dist/src/devices/CameraManagerState.d.ts +28 -0
- package/dist/src/devices/InputMediaDeviceManager.d.ts +47 -0
- package/dist/src/devices/InputMediaDeviceManagerState.d.ts +69 -0
- package/dist/src/devices/MicrophoneManager.d.ts +19 -0
- package/dist/src/devices/MicrophoneManagerState.d.ts +4 -0
- package/dist/src/devices/__tests__/CameraManager.test.d.ts +1 -0
- package/dist/src/devices/__tests__/InputMediaDeviceManager.test.d.ts +1 -0
- package/dist/src/devices/__tests__/MicrophoneManager.test.d.ts +1 -0
- package/dist/src/devices/__tests__/mocks.d.ts +13 -0
- package/dist/src/devices/index.d.ts +6 -0
- package/dist/src/types.d.ts +4 -0
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/Call.ts +100 -3
- package/src/__tests__/StreamVideoClient.test.ts +3 -0
- package/src/devices/CameraManager.ts +73 -0
- package/src/devices/CameraManagerState.ts +61 -0
- package/src/devices/InputMediaDeviceManager.ts +121 -0
- package/src/devices/InputMediaDeviceManagerState.ts +111 -0
- package/src/devices/MicrophoneManager.ts +45 -0
- package/src/devices/MicrophoneManagerState.ts +9 -0
- package/src/devices/__tests__/CameraManager.test.ts +150 -0
- package/src/devices/__tests__/InputMediaDeviceManager.test.ts +159 -0
- package/src/devices/__tests__/MicrophoneManager.test.ts +103 -0
- package/src/devices/__tests__/mocks.ts +98 -0
- package/src/devices/index.ts +6 -0
- package/src/rtc/Publisher.ts +11 -19
- package/src/rtc/videoLayers.ts +7 -2
- package/src/types.ts +4 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { vi } from 'vitest';
|
|
2
|
+
import { CallingState } from '../../store';
|
|
3
|
+
|
|
4
|
+
export const mockVideoDevices = [
|
|
5
|
+
{
|
|
6
|
+
deviceId:
|
|
7
|
+
'9d7b77d613cc935c023c08779a714db96e9f6d5589aae20869b5ab6e42f5b1fe',
|
|
8
|
+
kind: 'videoinput',
|
|
9
|
+
label: 'Logi Capture',
|
|
10
|
+
groupId: '81b3a3c5fec920079136100dc4b185209859077ce622a24fec747406d50cd694',
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
deviceId:
|
|
14
|
+
'af5cbd8fa1ff57b16f5f3c2c03dd9502f552cbdada3992a5c10b8d240debf1b5',
|
|
15
|
+
kind: 'videoinput',
|
|
16
|
+
label: 'HD Pro Webcam C920 (046d:08e5)',
|
|
17
|
+
groupId: 'bb0a866e4d66d493a104d7bd5a5dc2fee3d5947fab34aa0a99282386556a8f17',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
deviceId:
|
|
21
|
+
'f66cf2801fa16223e46a65be7d8d98d23670dd16fdd8961dd5c0dbb0cad372f3',
|
|
22
|
+
kind: 'videoinput',
|
|
23
|
+
label: 'FaceTime HD Camera (Built-in) (05ac:8514)',
|
|
24
|
+
groupId: '0387adca5bc7ab2850a9b9594a5622d838de4f78cbdf4d31c3506b701c58d94d',
|
|
25
|
+
},
|
|
26
|
+
] as MediaDeviceInfo[];
|
|
27
|
+
|
|
28
|
+
export const mockAudioDevices = [
|
|
29
|
+
{
|
|
30
|
+
deviceId: 'default',
|
|
31
|
+
kind: 'audioinput',
|
|
32
|
+
label: 'Default - MacBook Pro Microphone (Built-in)',
|
|
33
|
+
groupId: 'a8708545cb3969c0b7e3712d2ffdbc381992aeb5577b06cd71ba7a94ee20cf3e',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
deviceId:
|
|
37
|
+
'6ce9fde261809389d6476791d329695ea4c98bd432ac5f6a60e7017c96943d32',
|
|
38
|
+
kind: 'audioinput',
|
|
39
|
+
label: 'iPhone Microphone',
|
|
40
|
+
groupId: '65a8661fe6575d0eb180e7ab3f1ec887a285965293b9e75ceed938766f6d32bd',
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
deviceId:
|
|
44
|
+
'bb784adda6f0199966c97f8a2ca0fb93169e55cae050e8e8dd4ef76ffd1e638d',
|
|
45
|
+
kind: 'audioinput',
|
|
46
|
+
label: 'HD Pro Webcam C920 (046d:08e5)',
|
|
47
|
+
groupId: 'bb0a866e4d66d493a104d7bd5a5dc2fee3d5947fab34aa0a99282386556a8f17',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
deviceId:
|
|
51
|
+
'45b2467601574a522fe96048a5b2122ea6be0a478e04b990eaa4d93b49e2428a',
|
|
52
|
+
kind: 'audioinput',
|
|
53
|
+
label: 'MacBook Pro Microphone (Built-in)',
|
|
54
|
+
groupId: 'a8708545cb3969c0b7e3712d2ffdbc381992aeb5577b06cd71ba7a94ee20cf3e',
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
deviceId:
|
|
58
|
+
'b936c0572d3536857d646af780b8704c368a872e7ba8138ef83d72d726710975',
|
|
59
|
+
kind: 'audioinput',
|
|
60
|
+
label: 'ZoomAudioDevice (Virtual)',
|
|
61
|
+
groupId: '423bb83eab8607fe47313f2e0307600c40e03c37ad63a3b8412d3d5eb0671a55',
|
|
62
|
+
},
|
|
63
|
+
] as MediaDeviceInfo[];
|
|
64
|
+
|
|
65
|
+
export const mockCall = () => {
|
|
66
|
+
return {
|
|
67
|
+
state: {
|
|
68
|
+
callingState: CallingState.IDLE,
|
|
69
|
+
},
|
|
70
|
+
publishVideoStream: vi.fn(),
|
|
71
|
+
publishAudioStream: vi.fn(),
|
|
72
|
+
stopPublish: vi.fn(),
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export const mockAudioStream = () => {
|
|
77
|
+
const track = {
|
|
78
|
+
getSettings: () => ({
|
|
79
|
+
deviceId: mockAudioDevices[0].deviceId,
|
|
80
|
+
}),
|
|
81
|
+
enabled: true,
|
|
82
|
+
};
|
|
83
|
+
return {
|
|
84
|
+
getAudioTracks: () => [track],
|
|
85
|
+
} as MediaStream;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export const mockVideoStream = () => {
|
|
89
|
+
const track = {
|
|
90
|
+
getSettings: () => ({
|
|
91
|
+
deviceId: mockVideoDevices[0].deviceId,
|
|
92
|
+
}),
|
|
93
|
+
enabled: true,
|
|
94
|
+
};
|
|
95
|
+
return {
|
|
96
|
+
getVideoTracks: () => [track],
|
|
97
|
+
} as MediaStream;
|
|
98
|
+
};
|
package/src/devices/index.ts
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
1
|
export * from './devices';
|
|
2
|
+
export * from './InputMediaDeviceManager';
|
|
3
|
+
export * from './InputMediaDeviceManagerState';
|
|
4
|
+
export * from './CameraManager';
|
|
5
|
+
export * from './CameraManagerState';
|
|
6
|
+
export * from './MicrophoneManager';
|
|
7
|
+
export * from './MicrophoneManagerState';
|
package/src/rtc/Publisher.ts
CHANGED
|
@@ -21,14 +21,11 @@ import {
|
|
|
21
21
|
import { CallState } from '../store';
|
|
22
22
|
import { PublishOptions } from '../types';
|
|
23
23
|
import { isReactNative } from '../helpers/platforms';
|
|
24
|
-
import {
|
|
25
|
-
removeCodec,
|
|
26
|
-
setPreferredCodec,
|
|
27
|
-
toggleDtx,
|
|
28
|
-
} from '../helpers/sdp-munging';
|
|
24
|
+
import { toggleDtx } from '../helpers/sdp-munging';
|
|
29
25
|
import { Logger } from '../coordinator/connection/types';
|
|
30
26
|
import { getLogger } from '../logger';
|
|
31
27
|
import { Dispatcher } from './Dispatcher';
|
|
28
|
+
import { getOSInfo } from '../client-details';
|
|
32
29
|
|
|
33
30
|
const logger: Logger = getLogger(['Publisher']);
|
|
34
31
|
|
|
@@ -239,9 +236,17 @@ export class Publisher {
|
|
|
239
236
|
? findOptimalVideoLayers(track, targetResolution)
|
|
240
237
|
: undefined;
|
|
241
238
|
|
|
239
|
+
let preferredCodec = opts.preferredCodec;
|
|
240
|
+
if (!preferredCodec && trackType === TrackType.VIDEO) {
|
|
241
|
+
const isRNAndroid =
|
|
242
|
+
isReactNative() && getOSInfo()?.name.toLowerCase() === 'android';
|
|
243
|
+
if (isRNAndroid) {
|
|
244
|
+
preferredCodec = 'VP8';
|
|
245
|
+
}
|
|
246
|
+
}
|
|
242
247
|
const codecPreferences = this.getCodecPreferences(
|
|
243
248
|
trackType,
|
|
244
|
-
|
|
249
|
+
preferredCodec,
|
|
245
250
|
);
|
|
246
251
|
|
|
247
252
|
// listen for 'ended' event on the track as it might be ended abruptly
|
|
@@ -546,19 +551,6 @@ export class Publisher {
|
|
|
546
551
|
private mungeCodecs = (sdp?: string) => {
|
|
547
552
|
if (sdp) {
|
|
548
553
|
sdp = toggleDtx(sdp, this.isDtxEnabled);
|
|
549
|
-
if (isReactNative()) {
|
|
550
|
-
if (this.preferredVideoCodec) {
|
|
551
|
-
sdp = setPreferredCodec(sdp, 'video', this.preferredVideoCodec);
|
|
552
|
-
}
|
|
553
|
-
sdp = setPreferredCodec(
|
|
554
|
-
sdp,
|
|
555
|
-
'audio',
|
|
556
|
-
this.isRedEnabled ? 'red' : 'opus',
|
|
557
|
-
);
|
|
558
|
-
if (!this.isRedEnabled) {
|
|
559
|
-
sdp = removeCodec(sdp, 'audio', 'red');
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
554
|
}
|
|
563
555
|
return sdp;
|
|
564
556
|
};
|
package/src/rtc/videoLayers.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { getOSInfo } from '../client-details';
|
|
1
2
|
import { TargetResolution } from '../gen/coordinator';
|
|
3
|
+
import { isReactNative } from '../helpers/platforms';
|
|
2
4
|
|
|
3
5
|
export type OptimalVideoLayer = RTCRtpEncodingParameters & {
|
|
4
6
|
width: number;
|
|
@@ -27,6 +29,8 @@ export const findOptimalVideoLayers = (
|
|
|
27
29
|
const settings = videoTrack.getSettings();
|
|
28
30
|
const { width: w = 0, height: h = 0 } = settings;
|
|
29
31
|
|
|
32
|
+
const isRNIos = isReactNative() && getOSInfo()?.name.toLowerCase() === 'ios';
|
|
33
|
+
|
|
30
34
|
const maxBitrate = getComputedMaxBitrate(targetResolution, w, h);
|
|
31
35
|
let downscaleFactor = 1;
|
|
32
36
|
['f', 'h', 'q'].forEach((rid) => {
|
|
@@ -40,10 +44,11 @@ export const findOptimalVideoLayers = (
|
|
|
40
44
|
height: Math.round(h / downscaleFactor),
|
|
41
45
|
maxBitrate: Math.round(maxBitrate / downscaleFactor),
|
|
42
46
|
scaleResolutionDownBy: downscaleFactor,
|
|
47
|
+
// Simulcast on iOS React-Native requires all encodings to share the same framerate
|
|
43
48
|
maxFramerate: {
|
|
44
49
|
f: 30,
|
|
45
|
-
h: 25,
|
|
46
|
-
q: 20,
|
|
50
|
+
h: isRNIos ? 30 : 25,
|
|
51
|
+
q: isRNIos ? 30 : 20,
|
|
47
52
|
}[rid],
|
|
48
53
|
});
|
|
49
54
|
downscaleFactor *= 2;
|
package/src/types.ts
CHANGED
|
@@ -89,11 +89,15 @@ export interface StreamVideoParticipant extends Participant {
|
|
|
89
89
|
export interface StreamVideoLocalParticipant extends StreamVideoParticipant {
|
|
90
90
|
/**
|
|
91
91
|
* The device ID of the currently selected audio input device of the local participant (returned by the [MediaDevices API](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia))
|
|
92
|
+
*
|
|
93
|
+
* @deprecated use call.microphone.state.selectedDevice
|
|
92
94
|
*/
|
|
93
95
|
audioDeviceId?: string;
|
|
94
96
|
|
|
95
97
|
/**
|
|
96
98
|
* The device ID of the currently selected video input device of the local participant (returned by the [MediaDevices API](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia))
|
|
99
|
+
*
|
|
100
|
+
* @deprecated use call.camera.state.selectedDevice
|
|
97
101
|
*/
|
|
98
102
|
videoDeviceId?: string;
|
|
99
103
|
|