@fluxrtc/sdk 1.0.0 → 1.1.0

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/VideoClient.js +21 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluxrtc/sdk",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "FluxRTC Video SDK — add real-time video and audio to any web app",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -180,14 +180,20 @@ class VideoClient {
180
180
  });
181
181
  }
182
182
 
183
- async enableMedia(constraints = { video: true, audio: true }) {
183
+ async enableMedia(constraints) {
184
184
  if (this.localStream) return this.localStream;
185
185
 
186
+ const defaults = {
187
+ video: { width: { ideal: 640 }, height: { ideal: 360 }, frameRate: { ideal: 24, max: 30 } },
188
+ audio: true,
189
+ };
190
+ const merged = constraints || defaults;
191
+
186
192
  try {
187
- this.localStream = await navigator.mediaDevices.getUserMedia(constraints);
193
+ this.localStream = await navigator.mediaDevices.getUserMedia(merged);
188
194
  return this.localStream;
189
195
  } catch (err) {
190
- if (constraints.video && (err.name === 'NotReadableError' || err.name === 'NotFoundError')) {
196
+ if (merged.video && (err.name === 'NotReadableError' || err.name === 'NotFoundError')) {
191
197
  this.localStream = await navigator.mediaDevices.getUserMedia({ video: false, audio: true });
192
198
  return this.localStream;
193
199
  }
@@ -200,9 +206,20 @@ class VideoClient {
200
206
  throw new Error('Call enableMedia() and joinRoom() before produce()');
201
207
  }
202
208
 
209
+ const simulcastEncodings = [
210
+ { maxBitrate: 100000, scaleResolutionDownBy: 4 },
211
+ { maxBitrate: 300000, scaleResolutionDownBy: 2 },
212
+ { maxBitrate: 900000, scaleResolutionDownBy: 1 },
213
+ ];
214
+
203
215
  const producers = [];
204
216
  for (const track of this.localStream.getTracks()) {
205
- const producer = await this.sendTransport.produce({ track });
217
+ const params = { track };
218
+ if (track.kind === 'video') {
219
+ params.encodings = simulcastEncodings;
220
+ params.codecOptions = { videoGoogleStartBitrate: 1000 };
221
+ }
222
+ const producer = await this.sendTransport.produce(params);
206
223
  this.producers.set(producer.id, producer);
207
224
  producers.push({ id: producer.id, kind: track.kind });
208
225
  }