werift 0.14.2 → 0.14.5

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 (36) hide show
  1. package/lib/dtls/src/transport.js +10 -1
  2. package/lib/dtls/src/transport.js.map +1 -1
  3. package/lib/ice/src/ice.js +1 -1
  4. package/lib/ice/src/ice.js.map +1 -1
  5. package/lib/ice/src/stun/protocol.js +8 -1
  6. package/lib/ice/src/stun/protocol.js.map +1 -1
  7. package/lib/ice/src/transport.js +9 -12
  8. package/lib/ice/src/transport.js.map +1 -1
  9. package/lib/rtp/src/srtp/cipher/ctr.js +1 -5
  10. package/lib/rtp/src/srtp/cipher/ctr.js.map +1 -1
  11. package/lib/sctp/src/helper.d.ts +1 -1
  12. package/lib/sctp/src/helper.js.map +1 -1
  13. package/lib/sctp/src/sctp.d.ts +7 -2
  14. package/lib/sctp/src/sctp.js +109 -41
  15. package/lib/sctp/src/sctp.js.map +1 -1
  16. package/lib/sctp/src/transport.js +8 -1
  17. package/lib/sctp/src/transport.js.map +1 -1
  18. package/lib/webrtc/src/media/rtpSender.d.ts +1 -1
  19. package/lib/webrtc/src/media/rtpSender.js +6 -6
  20. package/lib/webrtc/src/media/rtpSender.js.map +1 -1
  21. package/lib/webrtc/src/nonstandard/recorder/writer/webm.js +1 -1
  22. package/lib/webrtc/src/nonstandard/recorder/writer/webm.js.map +1 -1
  23. package/lib/webrtc/src/peerConnection.js +11 -3
  24. package/lib/webrtc/src/peerConnection.js.map +1 -1
  25. package/lib/webrtc/src/transport/dtls.d.ts +1 -1
  26. package/lib/webrtc/src/transport/dtls.js +7 -8
  27. package/lib/webrtc/src/transport/dtls.js.map +1 -1
  28. package/lib/webrtc/src/transport/sctp.d.ts +1 -0
  29. package/lib/webrtc/src/transport/sctp.js +32 -15
  30. package/lib/webrtc/src/transport/sctp.js.map +1 -1
  31. package/package.json +18 -19
  32. package/src/media/rtpSender.ts +9 -6
  33. package/src/nonstandard/recorder/writer/webm.ts +1 -1
  34. package/src/peerConnection.ts +11 -5
  35. package/src/transport/dtls.ts +7 -7
  36. package/src/transport/sctp.ts +34 -22
@@ -96,7 +96,7 @@ class SCTP {
96
96
  this.timer1Failures = 0;
97
97
  this.timer2Failures = 0;
98
98
  this.timerReconfigFailures = 0;
99
- this.send = async (streamId, ppId, userData, expiry = undefined, maxRetransmits = undefined, ordered = true) => {
99
+ this.send = async (streamId, ppId, userData, { expiry, maxRetransmits, ordered, } = { expiry: undefined, maxRetransmits: undefined, ordered: true }) => {
100
100
  const streamSeqNum = ordered ? this.outboundStreamSeq[streamId] || 0 : 0;
101
101
  const fragments = Math.ceil(userData.length / USERDATA_MAX_LENGTH);
102
102
  let pos = 0;
@@ -145,7 +145,11 @@ class SCTP {
145
145
  this.setState(const_1.SCTP_STATE.CLOSED);
146
146
  }
147
147
  else {
148
- setImmediate(() => this.sendChunk(this.timer1Chunk));
148
+ setImmediate(() => {
149
+ this.sendChunk(this.timer1Chunk).catch((err) => {
150
+ log("send timer1 chunk failed", err.message);
151
+ });
152
+ });
149
153
  this.timer1Handle = setTimeout(this.timer1Expired, this.rto * 1000);
150
154
  }
151
155
  };
@@ -156,7 +160,11 @@ class SCTP {
156
160
  this.setState(const_1.SCTP_STATE.CLOSED);
157
161
  }
158
162
  else {
159
- setImmediate(() => this.sendChunk(this.timer2Chunk));
163
+ setImmediate(() => {
164
+ this.sendChunk(this.timer2Chunk).catch((err) => {
165
+ log("send timer2Chunk failed", err.message);
166
+ });
167
+ });
160
168
  this.timer2Handle = setTimeout(this.timer2Expired, this.rto * 1000);
161
169
  }
162
170
  };
@@ -252,18 +260,24 @@ class SCTP {
252
260
  sack.advertisedRwnd = Math.max(0, this.advertisedRwnd);
253
261
  sack.duplicates = [...this.sackDuplicates];
254
262
  sack.gaps = gaps;
255
- await this.sendChunk(sack);
263
+ await this.sendChunk(sack).catch((err) => {
264
+ log("send sack failed", err.message);
265
+ });
256
266
  this.sackDuplicates = [];
257
267
  this.sackNeeded = false;
258
268
  }
259
269
  async receiveChunk(chunk) {
260
270
  switch (chunk.type) {
261
271
  case chunk_1.DataChunk.type:
262
- this.receiveDataChunk(chunk);
272
+ {
273
+ this.receiveDataChunk(chunk);
274
+ }
263
275
  break;
264
276
  case chunk_1.InitChunk.type:
265
- const init = chunk;
266
- if (this.isServer) {
277
+ {
278
+ if (!this.isServer)
279
+ return;
280
+ const init = chunk;
267
281
  log("receive init", init);
268
282
  this.lastReceivedTsn = tsnMinusOne(init.initialTsn);
269
283
  this.reconfigResponseSeq = tsnMinusOne(init.initialTsn);
@@ -287,11 +301,15 @@ class SCTP {
287
301
  ]);
288
302
  ack.params.push([SCTP_STATE_COOKIE, cookie]);
289
303
  log("send initAck", ack);
290
- await this.sendChunk(ack);
304
+ await this.sendChunk(ack).catch((err) => {
305
+ log("send initAck failed", err.message);
306
+ });
291
307
  }
292
308
  break;
293
309
  case chunk_1.InitAckChunk.type:
294
- if (this.associationState === const_1.SCTP_STATE.COOKIE_WAIT) {
310
+ {
311
+ if (this.associationState != const_1.SCTP_STATE.COOKIE_WAIT)
312
+ return;
295
313
  const initAck = chunk;
296
314
  this.timer1Cancel();
297
315
  this.lastReceivedTsn = tsnMinusOne(initAck.initialTsn);
@@ -308,42 +326,58 @@ class SCTP {
308
326
  break;
309
327
  }
310
328
  }
311
- await this.sendChunk(echo);
329
+ await this.sendChunk(echo).catch((err) => {
330
+ log("send echo failed", err.message);
331
+ });
312
332
  this.timer1Start(echo);
313
333
  this.setState(const_1.SCTP_STATE.COOKIE_ECHOED);
314
334
  }
315
335
  break;
316
336
  case chunk_1.SackChunk.type:
317
- await this.receiveSackChunk(chunk);
337
+ {
338
+ await this.receiveSackChunk(chunk);
339
+ }
318
340
  break;
319
341
  case chunk_1.HeartbeatChunk.type:
320
- const ack = new chunk_1.HeartbeatAckChunk();
321
- ack.params = chunk.params;
322
- await this.sendChunk(ack);
342
+ {
343
+ const ack = new chunk_1.HeartbeatAckChunk();
344
+ ack.params = chunk.params;
345
+ await this.sendChunk(ack).catch((err) => {
346
+ log("send heartbeat ack failed", err.message);
347
+ });
348
+ }
323
349
  break;
324
350
  case chunk_1.AbortChunk.type:
325
- this.setState(const_1.SCTP_STATE.CLOSED);
351
+ {
352
+ this.setState(const_1.SCTP_STATE.CLOSED);
353
+ }
326
354
  break;
327
355
  case chunk_1.ShutdownChunk.type:
328
356
  {
329
357
  this.timer2Cancel();
330
358
  this.setState(const_1.SCTP_STATE.SHUTDOWN_RECEIVED);
331
359
  const ack = new chunk_1.ShutdownAckChunk();
332
- await this.sendChunk(ack);
360
+ await this.sendChunk(ack).catch((err) => {
361
+ log("send shutdown ack failed", err.message);
362
+ });
333
363
  this.t2Start(ack);
334
364
  this.setState(const_1.SCTP_STATE.SHUTDOWN_SENT);
335
365
  }
336
366
  break;
337
367
  case chunk_1.ErrorChunk.type:
338
- // 3.3.10. Operation Error (ERROR) (9)
339
- // An Operation Error is not considered fatal in and of itself, but may be
340
- // used with an ABORT chunk to report a fatal condition. It has the
341
- // following parameters:
342
- log("ErrorChunk", chunk.descriptions);
368
+ {
369
+ // 3.3.10. Operation Error (ERROR) (9)
370
+ // An Operation Error is not considered fatal in and of itself, but may be
371
+ // used with an ABORT chunk to report a fatal condition. It has the
372
+ // following parameters:
373
+ log("ErrorChunk", chunk.descriptions);
374
+ }
343
375
  break;
344
376
  case chunk_1.CookieEchoChunk.type:
345
- const data = chunk;
346
- if (this.isServer) {
377
+ {
378
+ if (!this.isServer)
379
+ return;
380
+ const data = chunk;
347
381
  const cookie = data.body;
348
382
  const digest = (0, crypto_1.createHmac)("sha1", this.hmacKey)
349
383
  .update(cookie.slice(0, 4))
@@ -361,29 +395,39 @@ class SCTP {
361
395
  chunk_1.ErrorChunk.CODE.StaleCookieError,
362
396
  Buffer.concat([...Array(8)].map(() => Buffer.from("\x00"))),
363
397
  ]);
364
- await this.sendChunk(error);
398
+ await this.sendChunk(error).catch((err) => {
399
+ log("send errorChunk failed", err.message);
400
+ });
365
401
  return;
366
402
  }
367
403
  const ack = new chunk_1.CookieAckChunk();
368
- await this.sendChunk(ack);
404
+ await this.sendChunk(ack).catch((err) => {
405
+ log("send cookieAck failed", err.message);
406
+ });
369
407
  this.setState(const_1.SCTP_STATE.ESTABLISHED);
370
408
  }
371
409
  break;
372
410
  case chunk_1.CookieAckChunk.type:
373
- if (this.associationState === const_1.SCTP_STATE.COOKIE_ECHOED) {
411
+ {
412
+ if (this.associationState != const_1.SCTP_STATE.COOKIE_ECHOED)
413
+ return;
374
414
  this.timer1Cancel();
375
415
  this.setState(const_1.SCTP_STATE.ESTABLISHED);
376
416
  }
377
417
  break;
378
418
  case chunk_1.ShutdownCompleteChunk.type:
379
- if (this.associationState === const_1.SCTP_STATE.SHUTDOWN_ACK_SENT) {
419
+ {
420
+ if (this.associationState != const_1.SCTP_STATE.SHUTDOWN_ACK_SENT)
421
+ return;
380
422
  this.timer2Cancel();
381
423
  this.setState(const_1.SCTP_STATE.CLOSED);
382
424
  }
383
425
  break;
384
426
  // extensions
385
427
  case chunk_1.ReconfigChunk.type:
386
- if (this.associationState === const_1.SCTP_STATE.ESTABLISHED) {
428
+ {
429
+ if (this.associationState != const_1.SCTP_STATE.ESTABLISHED)
430
+ return;
387
431
  const reconfig = chunk;
388
432
  for (const [type, body] of reconfig.params) {
389
433
  const target = param_1.RECONFIG_PARAM_BY_TYPES[type];
@@ -394,7 +438,9 @@ class SCTP {
394
438
  }
395
439
  break;
396
440
  case chunk_1.ForwardTsnChunk.type:
397
- this.receiveForwardTsnChunk(chunk);
441
+ {
442
+ this.receiveForwardTsnChunk(chunk);
443
+ }
398
444
  break;
399
445
  }
400
446
  }
@@ -654,7 +700,9 @@ class SCTP {
654
700
  // """
655
701
  // # send FORWARD TSN
656
702
  if (this.forwardTsnChunk) {
657
- await this.sendChunk(this.forwardTsnChunk);
703
+ await this.sendChunk(this.forwardTsnChunk).catch((err) => {
704
+ log("send forwardTsn failed", err.message);
705
+ });
658
706
  this.forwardTsnChunk = undefined;
659
707
  if (!this.timer3Handle) {
660
708
  this.timer3Start();
@@ -677,7 +725,9 @@ class SCTP {
677
725
  dataChunk.misses = 0;
678
726
  dataChunk.retransmit = false;
679
727
  dataChunk.sentCount++;
680
- await this.sendChunk(dataChunk);
728
+ await this.sendChunk(dataChunk).catch((err) => {
729
+ log("send data failed", err.message);
730
+ });
681
731
  if (retransmitEarliest) {
682
732
  this.timer3Restart();
683
733
  }
@@ -694,7 +744,9 @@ class SCTP {
694
744
  // # update counters
695
745
  chunk.sentCount++;
696
746
  chunk.sentTime = Date.now() / 1000;
697
- await this.sendChunk(chunk);
747
+ await this.sendChunk(chunk).catch((err) => {
748
+ log("send data outboundQueue failed", err.message);
749
+ });
698
750
  if (!this.timer3Handle) {
699
751
  this.timer3Start();
700
752
  }
@@ -717,7 +769,9 @@ class SCTP {
717
769
  log("sendReconfigParam", param);
718
770
  const chunk = new chunk_1.ReconfigChunk();
719
771
  chunk.params.push([param.type, param.bytes]);
720
- await this.sendChunk(chunk);
772
+ await this.sendChunk(chunk).catch((err) => {
773
+ log("send reconfig failed", err.message);
774
+ });
721
775
  }
722
776
  // https://github.com/pion/sctp/pull/44/files
723
777
  async sendResetRequest(streamId) {
@@ -850,11 +904,16 @@ class SCTP {
850
904
  static getCapabilities() {
851
905
  return new RTCSctpCapabilities(65536);
852
906
  }
907
+ setRemotePort(port) {
908
+ this.remotePort = port;
909
+ }
853
910
  async start(remotePort) {
854
911
  if (!this.started) {
855
912
  this.started = true;
856
913
  this.setConnectionState("connecting");
857
- this.remotePort = remotePort;
914
+ if (remotePort) {
915
+ this.setRemotePort(remotePort);
916
+ }
858
917
  if (!this.isServer) {
859
918
  await this.init();
860
919
  }
@@ -869,10 +928,15 @@ class SCTP {
869
928
  init.initialTsn = this.localTsn;
870
929
  this.setExtensions(init.params);
871
930
  log("send init", init);
872
- await this.sendChunk(init);
873
- // # start T1 timer and enter COOKIE-WAIT state
874
- this.timer1Start(init);
875
- this.setState(const_1.SCTP_STATE.COOKIE_WAIT);
931
+ try {
932
+ await this.sendChunk(init);
933
+ // # start T1 timer and enter COOKIE-WAIT state
934
+ this.timer1Start(init);
935
+ this.setState(const_1.SCTP_STATE.COOKIE_WAIT);
936
+ }
937
+ catch (error) {
938
+ log("send init failed", error.message);
939
+ }
876
940
  }
877
941
  setExtensions(params) {
878
942
  const extensions = [];
@@ -884,10 +948,11 @@ class SCTP {
884
948
  params.push([SCTP_SUPPORTED_CHUNK_EXT, Buffer.from(extensions)]);
885
949
  }
886
950
  async sendChunk(chunk) {
887
- if (this.remotePort === undefined)
888
- throw new Error("invalid remote port");
889
951
  if (this.state === "closed")
890
952
  return;
953
+ if (this.remotePort === undefined) {
954
+ throw new Error("invalid remote port");
955
+ }
891
956
  const packet = (0, chunk_1.serializePacket)(this.localPort, this.remotePort, this.remoteVerificationTag, chunk);
892
957
  await this.transport.send(packet);
893
958
  }
@@ -908,6 +973,7 @@ class SCTP {
908
973
  }
909
974
  setConnectionState(state) {
910
975
  this.state = state;
976
+ log("setConnectionState", state);
911
977
  this.stateChanged[state].execute();
912
978
  }
913
979
  async stop() {
@@ -921,7 +987,9 @@ class SCTP {
921
987
  }
922
988
  async abort() {
923
989
  const abort = new chunk_1.AbortChunk();
924
- await this.sendChunk(abort);
990
+ await this.sendChunk(abort).catch((err) => {
991
+ log("send abort failed", err.message);
992
+ });
925
993
  }
926
994
  removeAllListeners() {
927
995
  Object.values(this.stateChanged).forEach((v) => v.allUnsubscribe());