@reactoo/watchtogether-sdk-js 2.6.10 → 2.6.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactoo/watchtogether-sdk-js",
3
- "version": "2.6.10",
3
+ "version": "2.6.12",
4
4
  "description": "Javascript SDK for Reactoo",
5
5
  "main": "src/index.js",
6
6
  "unpkg": "dist/watchtogether-sdk.min.js",
@@ -1,12 +1,104 @@
1
1
  'use strict';
2
2
 
3
+
4
+ const getConstraints = ({
5
+
6
+ hasVideo,
7
+ hasAudio = true,
8
+ isHd,
9
+ aDeviceId,
10
+ vDeviceId,
11
+ lfps,
12
+ autoGainControl = false,
13
+ echoCancellation = true,
14
+ noiseSuppression = true,
15
+ channelCount = 1
16
+
17
+ }) => {
18
+
19
+ // optional: Array (6)
20
+ // • 0: {googEchoCancellation: true}
21
+ // • 1: {googEchoCancellation2: true}
22
+ // • 2: {googAutoGainControl: true}
23
+ // • 3: {googNoiseSuppression: true}
24
+ // » 4: {googHighpassFilter: true}
25
+ // • 5: {googAudioMirroring: true}
26
+ // googTypingNoiseDetection
27
+
28
+
29
+ let audioOnlyConstraints = {
30
+ audio: {
31
+ ...(aDeviceId && {deviceId: {exact:aDeviceId}}),
32
+ autoGainControl,
33
+ echoCancellation,
34
+ noiseSuppression,
35
+ channelCount
36
+ }
37
+ };
38
+
39
+ let videoOnlyConstraints = {
40
+ video: {
41
+ ...(vDeviceId && {deviceId: {exact:vDeviceId}}),
42
+ facingMode: {ideal: "user"},
43
+ ...(lfps ? {frameRate: { ideal: 10, max: 30 }} : {frameRate: { ideal: 30, max: 30 }}),
44
+ width: {ideal: isHd ? 1280 : 320},
45
+ height: {ideal: isHd ? 720 : 240},
46
+ }
47
+ };
48
+
49
+ return {
50
+ ...(hasAudio ? audioOnlyConstraints : {audio: false}),
51
+ ...(hasVideo ? videoOnlyConstraints : {video: false})
52
+ };
53
+
54
+ };
55
+
3
56
  export default {
57
+ //TODO: add more constraints
58
+ applyConstraints({
59
+ isHd,
60
+ lfps,
61
+ autoGainControl = false,
62
+ echoCancellation = true,
63
+ noiseSuppression = true,
64
+ channelCount = 1,
65
+ stream = null
66
+ }) {
67
+
68
+ if(stream) {
69
+
70
+ let fullConstraints = getConstraints({
71
+ hasVideo: true,
72
+ hasAudio: true,
73
+ autoGainControl, echoCancellation, noiseSuppression, channelCount, isHd, lfps
74
+ });
75
+ let returnPromises = [];
76
+
77
+ // const videoTrack = stream.getVideoTracks()[0];
78
+ // if(videoTrack) {
79
+ // returnPromises.push(videoTrack.applyConstraints(fullConstraints.video));
80
+ // }
81
+
82
+ const audioTrack = stream.getAudioTracks()[0];
83
+ if(audioTrack) {
84
+ returnPromises.push(audioTrack.applyConstraints(fullConstraints.audio));
85
+ }
86
+
87
+ return Promise.all(returnPromises).then(() => {
88
+ return stream;
89
+ });
90
+ }
91
+
92
+ else return Promise.resolve(null);
93
+
94
+
95
+ },
4
96
  getUserStream({
5
97
  hasVideo,
6
98
  hasAudio = true,
7
- isHd,
8
99
  aDeviceId,
9
100
  vDeviceId,
101
+ isHd,
10
102
  lfps,
11
103
  autoGainControl = false,
12
104
  echoCancellation = true,
@@ -14,16 +106,32 @@ export default {
14
106
  channelCount = 1,
15
107
  muteAudio = false,
16
108
  muteVideo = false,
17
- stream = null
18
109
  } = {}
19
110
  ) {
20
111
 
112
+ let fullConstraints = getConstraints({
113
+ hasVideo, hasAudio, isHd, aDeviceId, vDeviceId, lfps, autoGainControl, echoCancellation, noiseSuppression, channelCount
114
+ });
115
+
116
+ return navigator.mediaDevices.getUserMedia(fullConstraints)
117
+ .then(stream => {
118
+ stream.getAudioTracks().forEach(track => track.enabled = !muteAudio);
119
+ stream.getVideoTracks().forEach(track => track.enabled = !muteVideo);
120
+ return stream;
121
+ });
122
+ },
123
+
124
+ getHostStream({
125
+ hasAudio,
126
+ hasVideo,
127
+ aDeviceId,
128
+ vDeviceId,
129
+ channelCount = 1} = {}
130
+ ) {
131
+
21
132
  let audioOnlyConstraints = {
22
133
  audio: {
23
134
  ...(aDeviceId && {deviceId: {exact:aDeviceId}}),
24
- autoGainControl,
25
- echoCancellation,
26
- noiseSuppression,
27
135
  channelCount
28
136
  }
29
137
  };
@@ -31,10 +139,9 @@ export default {
31
139
  let videoOnlyConstraints = {
32
140
  video: {
33
141
  ...(vDeviceId && {deviceId: {exact:vDeviceId}}),
34
- facingMode: {ideal: "user"},
35
- ...(lfps ? {frameRate: { ideal: 10, max: 30 }} : {frameRate: { ideal: 30, max: 30 }}),
36
- width: {ideal: isHd ? 1280 : 320},
37
- height: {ideal: isHd ? 720 : 240},
142
+ frameRate: {ideal: 30, max: 30},
143
+ width: {min: 1280, ideal: 1920},
144
+ height: {min: 720, ideal: 1080},
38
145
  }
39
146
  };
40
147
 
@@ -43,32 +150,6 @@ export default {
43
150
  ...(hasVideo ? videoOnlyConstraints : {video: false})
44
151
  };
45
152
 
46
- if(stream) {
47
- let returnPromises = [];
48
- const videoTrack = stream.getVideoTracks()[0];
49
- const audioTrack = stream.getAudioTracks()[0];
50
-
51
- if(videoTrack) {
52
- returnPromises.push(videoTrack.applyConstraints(videoOnlyConstraints.video));
53
- }
54
-
55
- if(audioTrack) {
56
- returnPromises.push(audioTrack.applyConstraints(audioOnlyConstraints.audio));
57
- }
58
-
59
- return Promise.all(returnPromises).then(() => {
60
- stream.getAudioTracks().forEach(track => track.enabled = !muteAudio);
61
- stream.getVideoTracks().forEach(track => track.enabled = !muteVideo);
62
- return stream;
63
- });
64
- }
65
-
66
-
67
- return navigator.mediaDevices.getUserMedia(fullConstraints)
68
- .then(stream => {
69
- stream.getAudioTracks().forEach(track => track.enabled = !muteAudio);
70
- stream.getVideoTracks().forEach(track => track.enabled = !muteVideo);
71
- return stream;
72
- });
153
+ return navigator.mediaDevices.getUserMedia(fullConstraints);
73
154
  }
74
155
  }
@@ -1370,6 +1370,7 @@ class RoomSession {
1370
1370
 
1371
1371
  let transceiver = config.pc?.getTransceivers()?.find(
1372
1372
  t => t.receiver.track === ev.target);
1373
+
1373
1374
  let mid = transceiver?.mid || ev.target.id;
1374
1375
 
1375
1376
  if (config.stream) {
@@ -1850,9 +1851,9 @@ class RoomSession {
1850
1851
  direction: 'sendonly',
1851
1852
  streams: [config.stream],
1852
1853
  sendEncodings: [
1853
- { rid: 'h', active: true, maxBitrate: bitRates.high },
1854
- { rid: 'm', active: true, maxBitrate: bitRates.medium, scaleResolutionDownBy: 2 },
1855
- { rid: 'l', active: true, maxBitrate: bitRates.low, scaleResolutionDownBy: 4 }
1854
+ { rid: 'h', active: true, scalabilityMode: 'L1T2', maxBitrate: bitRates.high },
1855
+ { rid: 'm', active: true, scalabilityMode: 'L1T2', maxBitrate: bitRates.medium, scaleResolutionDownBy: 2 },
1856
+ { rid: 'l', active: true, scalabilityMode: 'L1T2', maxBitrate: bitRates.low, scaleResolutionDownBy: 4 }
1856
1857
  ]
1857
1858
  })
1858
1859
  }