@decartai/sdk 0.0.13 → 0.0.14

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.
@@ -40,7 +40,9 @@ const createRealTimeClient = (opts) => {
40
40
  console.error("WebRTC error:", error);
41
41
  eventEmitter.emit("error", createWebrtcError(error));
42
42
  },
43
- customizeOffer: options.customizeOffer
43
+ customizeOffer: options.customizeOffer,
44
+ vp8MinBitrate: 200,
45
+ vp8StartBitrate: 600
44
46
  });
45
47
  await webrtcManager.connect(stream);
46
48
  const methods = realtimeMethods(webrtcManager);
@@ -11,7 +11,7 @@ var WebRTCConnection = class {
11
11
  constructor(callbacks = {}) {
12
12
  this.callbacks = callbacks;
13
13
  }
14
- async connect(url, localStream, timeout = 25e3, integration) {
14
+ async connect(url, localStream, timeout = 35e3, integration) {
15
15
  const deadline = Date.now() + timeout;
16
16
  this.localStream = localStream;
17
17
  const userAgent = encodeURIComponent(buildUserAgent(integration));
@@ -69,6 +69,7 @@ var WebRTCConnection = class {
69
69
  case "ready": {
70
70
  await this.applyCodecPreference("video/VP8");
71
71
  const offer = await this.pc.createOffer();
72
+ this.modifyVP8Bitrate(offer);
72
73
  await this.callbacks.customizeOffer?.(offer);
73
74
  await this.pc.setLocalDescription(offer);
74
75
  this.send({
@@ -187,6 +188,43 @@ var WebRTCConnection = class {
187
188
  }
188
189
  await videoTransceiver.setCodecPreferences(orderedCodecs);
189
190
  }
191
+ modifyVP8Bitrate(offer) {
192
+ if (!offer.sdp) return;
193
+ const minBitrateInKbps = this.callbacks.vp8MinBitrate;
194
+ const startBitrateInKbps = this.callbacks.vp8StartBitrate;
195
+ if (minBitrateInKbps === 0 && startBitrateInKbps === 0) return;
196
+ const bitrateParams = `x-google-min-bitrate=${minBitrateInKbps};x-google-start-bitrate=${startBitrateInKbps}`;
197
+ const sdpLines = offer.sdp.split("\r\n");
198
+ const modifiedLines = [];
199
+ for (let i = 0; i < sdpLines.length; i++) {
200
+ if (sdpLines[i].includes("VP8/90000")) {
201
+ const match = sdpLines[i].match(/a=rtpmap:(\d+) VP8/);
202
+ if (match) {
203
+ const payloadType = match[1];
204
+ let fmtpIndex = -1;
205
+ let insertAfterIndex = i;
206
+ for (let j = i + 1; j < sdpLines.length && sdpLines[j].startsWith("a="); j++) {
207
+ if (sdpLines[j].startsWith(`a=fmtp:${payloadType}`)) {
208
+ fmtpIndex = j;
209
+ break;
210
+ }
211
+ if (sdpLines[j].startsWith(`a=rtcp-fb:${payloadType}`)) insertAfterIndex = j;
212
+ if (sdpLines[j].startsWith("a=rtpmap:")) break;
213
+ }
214
+ if (fmtpIndex !== -1) {
215
+ if (!sdpLines[fmtpIndex].includes("x-google-min-bitrate")) sdpLines[fmtpIndex] += `;${bitrateParams}`;
216
+ } else {
217
+ for (let k = i; k <= insertAfterIndex; k++) modifiedLines.push(sdpLines[k]);
218
+ modifiedLines.push(`a=fmtp:${payloadType} ${bitrateParams}`);
219
+ i = insertAfterIndex;
220
+ continue;
221
+ }
222
+ }
223
+ }
224
+ modifiedLines.push(sdpLines[i]);
225
+ }
226
+ offer.sdp = modifiedLines.join("\r\n");
227
+ }
190
228
  };
191
229
 
192
230
  //#endregion
@@ -19,7 +19,9 @@ var WebRTCManager = class {
19
19
  onRemoteStream: config.onRemoteStream,
20
20
  onStateChange: config.onConnectionStateChange,
21
21
  onError: config.onError,
22
- customizeOffer: config.customizeOffer
22
+ customizeOffer: config.customizeOffer,
23
+ vp8MinBitrate: config.vp8MinBitrate,
24
+ vp8StartBitrate: config.vp8StartBitrate
23
25
  });
24
26
  }
25
27
  async connect(localStream) {
package/dist/version.js CHANGED
@@ -4,7 +4,7 @@
4
4
  * Injected at build time from package.json.
5
5
  * Falls back to '0.0.0-dev' in development.
6
6
  */
7
- const VERSION = "0.0.13";
7
+ const VERSION = "0.0.14";
8
8
 
9
9
  //#endregion
10
10
  export { VERSION };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decartai/sdk",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "description": "Decart's JavaScript SDK",
5
5
  "type": "module",
6
6
  "license": "MIT",