@reactoo/watchtogether-sdk-js 2.6.9 → 2.6.11

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.9",
3
+ "version": "2.6.11",
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,57 +106,12 @@ export default {
14
106
  channelCount = 1,
15
107
  muteAudio = false,
16
108
  muteVideo = false,
17
- stream = null
18
109
  } = {}
19
110
  ) {
20
111
 
21
- let audioOnlyConstraints = {
22
- audio: {
23
- ...(aDeviceId && {deviceId: {exact:aDeviceId}}),
24
- autoGainControl,
25
- echoCancellation,
26
- noiseSuppression,
27
- channelCount
28
- }
29
- };
30
-
31
- let videoOnlyConstraints = {
32
- video: {
33
- ...(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},
38
- }
39
- };
40
-
41
- let fullConstraints = {
42
- ...(hasAudio ? audioOnlyConstraints : {audio: false}),
43
- ...(hasVideo ? videoOnlyConstraints : {video: false})
44
- };
45
-
46
- if(stream) {
47
- let returnPromises = [];
48
- const videoTrack = stream.getVideoTracks()[0];
49
- const audioTrack = stream.getAudioTracks()[0];
50
-
51
- console.log(stream, videoOnlyConstraints.video, audioOnlyConstraints.audio)
52
-
53
- if(videoTrack) {
54
- returnPromises.push(videoTrack.applyConstraints(videoOnlyConstraints.video));
55
- }
56
-
57
- if(audioTrack) {
58
- returnPromises.push(audioTrack.applyConstraints(audioOnlyConstraints.audio));
59
- }
60
-
61
- return Promise.all(returnPromises).then(() => {
62
- stream.getAudioTracks().forEach(track => track.enabled = !muteAudio);
63
- stream.getVideoTracks().forEach(track => track.enabled = !muteVideo);
64
- return stream;
65
- });
66
- }
67
-
112
+ let fullConstraints = getConstraints({
113
+ hasVideo, hasAudio, isHd, aDeviceId, vDeviceId, lfps, autoGainControl, echoCancellation, noiseSuppression, channelCount
114
+ });
68
115
 
69
116
  return navigator.mediaDevices.getUserMedia(fullConstraints)
70
117
  .then(stream => {