@webex/internal-media-core 0.0.12-beta → 0.0.14-beta

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 (32) hide show
  1. package/README.md +2 -78
  2. package/dist/cjs/index.js +22774 -0
  3. package/dist/esm/index.js +438 -125
  4. package/dist/types/MediaConnection/MediaConnection.d.ts.map +1 -1
  5. package/dist/types/MediaConnection/MultistreamRoapMediaConnection.d.ts.map +1 -1
  6. package/dist/types/MediaConnection/MultistreamRoapMediaConnection.test.d.ts +2 -0
  7. package/dist/types/MediaConnection/MultistreamRoapMediaConnection.test.d.ts.map +1 -0
  8. package/dist/types/MediaConnection/errors/IceGatheringError.d.ts +10 -0
  9. package/dist/types/MediaConnection/errors/IceGatheringError.d.ts.map +1 -0
  10. package/dist/types/MediaConnection/errors/MediaConnectionError.d.ts +10 -0
  11. package/dist/types/MediaConnection/errors/MediaConnectionError.d.ts.map +1 -0
  12. package/dist/types/MediaConnection/errors/SdpAnswerHandlingError.d.ts +10 -0
  13. package/dist/types/MediaConnection/errors/SdpAnswerHandlingError.d.ts.map +1 -0
  14. package/dist/types/MediaConnection/errors/SdpError.d.ts +10 -0
  15. package/dist/types/MediaConnection/errors/SdpError.d.ts.map +1 -0
  16. package/dist/types/MediaConnection/errors/SdpOfferCreationError.d.ts +10 -0
  17. package/dist/types/MediaConnection/errors/SdpOfferCreationError.d.ts.map +1 -0
  18. package/dist/types/MediaConnection/errors/SdpOfferHandlingError.d.ts +10 -0
  19. package/dist/types/MediaConnection/errors/SdpOfferHandlingError.d.ts.map +1 -0
  20. package/dist/types/MediaConnection/errors/constants.d.ts +9 -0
  21. package/dist/types/MediaConnection/errors/constants.d.ts.map +1 -0
  22. package/dist/types/MediaConnection/errors/index.d.ts +9 -0
  23. package/dist/types/MediaConnection/errors/index.d.ts.map +1 -0
  24. package/dist/types/MediaConnection/errors/index.test.d.ts +2 -0
  25. package/dist/types/MediaConnection/errors/index.test.d.ts.map +1 -0
  26. package/dist/types/MediaConnection/eventTypes.d.ts +2 -2
  27. package/dist/types/MediaConnection/eventTypes.d.ts.map +1 -1
  28. package/dist/types/MediaConnection/index.d.ts +3 -1
  29. package/dist/types/MediaConnection/index.d.ts.map +1 -1
  30. package/dist/types/MediaConnection/utils.d.ts +2 -2
  31. package/dist/types/MediaConnection/utils.d.ts.map +1 -1
  32. package/package.json +2 -2
package/dist/esm/index.js CHANGED
@@ -2394,6 +2394,98 @@ var off = (eventName, listener) => {
2394
2394
  eventEmitter.off(eventName, listener);
2395
2395
  };
2396
2396
 
2397
+ var ErrorCode;
2398
+ (function (ErrorCode) {
2399
+ ErrorCode[ErrorCode["MediaConnectionError"] = 30001] = "MediaConnectionError";
2400
+ ErrorCode[ErrorCode["SdpError"] = 30002] = "SdpError";
2401
+ ErrorCode[ErrorCode["IceGatheringError"] = 30003] = "IceGatheringError";
2402
+ ErrorCode[ErrorCode["SdpAnswerHandlingError"] = 30004] = "SdpAnswerHandlingError";
2403
+ ErrorCode[ErrorCode["SdpOfferCreationError"] = 30005] = "SdpOfferCreationError";
2404
+ ErrorCode[ErrorCode["SdpOfferHandlingError"] = 30006] = "SdpOfferHandlingError";
2405
+ })(ErrorCode || (ErrorCode = {}));
2406
+
2407
+ class MediaConnectionError extends Error {
2408
+ constructor(message) {
2409
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2410
+ super(message);
2411
+ _defineProperty(this, "code", void 0);
2412
+ this.name = options.name || 'MediaConnectionError';
2413
+ this.cause = options.cause;
2414
+ this.code = options.code || ErrorCode.MediaConnectionError;
2415
+ }
2416
+ }
2417
+
2418
+ function ownKeys$6(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2419
+ function _objectSpread$6(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$6(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$6(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
2420
+ class SdpError extends MediaConnectionError {
2421
+ constructor(message) {
2422
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2423
+ super(message, _objectSpread$6({
2424
+ code: ErrorCode.SdpError,
2425
+ name: 'SdpError'
2426
+ }, options));
2427
+ }
2428
+ }
2429
+
2430
+ function ownKeys$5(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2431
+ function _objectSpread$5(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$5(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$5(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
2432
+ class IceGatheringError extends SdpError {
2433
+ constructor(message) {
2434
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2435
+ super(message, _objectSpread$5({
2436
+ code: ErrorCode.IceGatheringError,
2437
+ name: 'IceGatheringError'
2438
+ }, options));
2439
+ }
2440
+ }
2441
+
2442
+ function ownKeys$4(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2443
+ function _objectSpread$4(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$4(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$4(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
2444
+ class SdpAnswerHandlingError extends SdpError {
2445
+ constructor(message) {
2446
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2447
+ super(message, _objectSpread$4({
2448
+ code: ErrorCode.SdpAnswerHandlingError,
2449
+ name: 'SdpAnswerHandlingError'
2450
+ }, options));
2451
+ }
2452
+ }
2453
+
2454
+ function ownKeys$3(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2455
+ function _objectSpread$3(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$3(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$3(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
2456
+ class SdpOfferCreationError extends SdpError {
2457
+ constructor(message) {
2458
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2459
+ super(message, _objectSpread$3({
2460
+ code: ErrorCode.SdpOfferCreationError,
2461
+ name: 'SdpOfferCreationError'
2462
+ }, options));
2463
+ }
2464
+ }
2465
+
2466
+ function ownKeys$2(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2467
+ function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$2(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$2(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
2468
+ class SdpOfferHandlingError extends SdpError {
2469
+ constructor(message) {
2470
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2471
+ super(message, _objectSpread$2({
2472
+ code: ErrorCode.SdpOfferHandlingError,
2473
+ name: 'SdpOfferHandlingError'
2474
+ }, options));
2475
+ }
2476
+ }
2477
+
2478
+ var Error$1 = /*#__PURE__*/Object.freeze({
2479
+ __proto__: null,
2480
+ get ErrorCode () { return ErrorCode; },
2481
+ IceGatheringError: IceGatheringError,
2482
+ MediaConnectionError: MediaConnectionError,
2483
+ SdpAnswerHandlingError: SdpAnswerHandlingError,
2484
+ SdpError: SdpError,
2485
+ SdpOfferCreationError: SdpOfferCreationError,
2486
+ SdpOfferHandlingError: SdpOfferHandlingError
2487
+ });
2488
+
2397
2489
  class EventEmitter$3 extends EventEmitter$4 {}
2398
2490
 
2399
2491
  var defaultLogger = {
@@ -2430,7 +2522,8 @@ var getErrorDescription = error => {
2430
2522
  };
2431
2523
 
2432
2524
  var NUM$1 = '\\d+';
2433
- var TOKEN$1 = '\\S+';
2525
+ var SDP_TOKEN = "[!#$%&'*+\\-.^_`{|}~a-zA-Z0-9]+";
2526
+ var ANY_NON_WS = '\\S+';
2434
2527
  var SP$1 = '\\s';
2435
2528
  var REST$1 = '.+';
2436
2529
  class Line$1 {}
@@ -2524,7 +2617,7 @@ class CandidateLine$1 extends Line$1 {
2524
2617
  }
2525
2618
  _a$4$1 = CandidateLine$1;
2526
2619
  CandidateLine$1.ICE_CHARS = "[a-zA-Z0-9+/]+";
2527
- CandidateLine$1.regex = new RegExp("^candidate:(".concat(_a$4$1.ICE_CHARS, ") (").concat(NUM$1, ") (").concat(TOKEN$1, ") (").concat(NUM$1, ") (").concat(TOKEN$1, ") (").concat(NUM$1, ") typ (").concat(TOKEN$1, ")(?: raddr (").concat(TOKEN$1, "))?(?: rport (").concat(NUM$1, "))?(?: (").concat(REST$1, "))?"));
2620
+ CandidateLine$1.regex = new RegExp("^candidate:(".concat(_a$4$1.ICE_CHARS, ") (").concat(NUM$1, ") (").concat(ANY_NON_WS, ") (").concat(NUM$1, ") (").concat(ANY_NON_WS, ") (").concat(NUM$1, ") typ (").concat(ANY_NON_WS, ")(?: raddr (").concat(ANY_NON_WS, "))?(?: rport (").concat(NUM$1, "))?(?: (").concat(REST$1, "))?"));
2528
2621
  class ConnectionLine$1 extends Line$1 {
2529
2622
  constructor(netType, addrType, ipAddr) {
2530
2623
  super();
@@ -2546,7 +2639,7 @@ class ConnectionLine$1 extends Line$1 {
2546
2639
  return "c=".concat(this.netType, " ").concat(this.addrType, " ").concat(this.ipAddr);
2547
2640
  }
2548
2641
  }
2549
- ConnectionLine$1.regex = new RegExp("^(".concat(TOKEN$1, ") (").concat(TOKEN$1, ") (").concat(TOKEN$1, ")"));
2642
+ ConnectionLine$1.regex = new RegExp("^(".concat(ANY_NON_WS, ") (").concat(ANY_NON_WS, ") (").concat(ANY_NON_WS, ")"));
2550
2643
  class ContentLine$1 extends Line$1 {
2551
2644
  constructor(values) {
2552
2645
  super();
@@ -2618,7 +2711,7 @@ class ExtMapLine$1 extends Line$1 {
2618
2711
  }
2619
2712
  _a$3$1 = ExtMapLine$1;
2620
2713
  ExtMapLine$1.EXTMAP_DIRECTION = "sendonly|recvonly|sendrecv|inactive";
2621
- ExtMapLine$1.regex = new RegExp("^extmap:(".concat(NUM$1, ")(?:/(").concat(_a$3$1.EXTMAP_DIRECTION, "))? (").concat(TOKEN$1, ")(?: (").concat(REST$1, "))?"));
2714
+ ExtMapLine$1.regex = new RegExp("^extmap:(".concat(NUM$1, ")(?:/(").concat(_a$3$1.EXTMAP_DIRECTION, "))? (").concat(ANY_NON_WS, ")(?: (").concat(REST$1, "))?"));
2622
2715
  class FingerprintLine$1 extends Line$1 {
2623
2716
  constructor(fingerprint) {
2624
2717
  super();
@@ -2692,7 +2785,7 @@ class IcePwdLine$1 extends Line$1 {
2692
2785
  return "a=ice-pwd:".concat(this.pwd);
2693
2786
  }
2694
2787
  }
2695
- IcePwdLine$1.regex = new RegExp("^ice-pwd:(".concat(TOKEN$1, ")$"));
2788
+ IcePwdLine$1.regex = new RegExp("^ice-pwd:(".concat(ANY_NON_WS, ")$"));
2696
2789
  class IceUfragLine$1 extends Line$1 {
2697
2790
  constructor(ufrag) {
2698
2791
  super();
@@ -2710,7 +2803,7 @@ class IceUfragLine$1 extends Line$1 {
2710
2803
  return "a=ice-ufrag:".concat(this.ufrag);
2711
2804
  }
2712
2805
  }
2713
- IceUfragLine$1.regex = new RegExp("^ice-ufrag:(".concat(TOKEN$1, ")$"));
2806
+ IceUfragLine$1.regex = new RegExp("^ice-ufrag:(".concat(ANY_NON_WS, ")$"));
2714
2807
  class MaxMessageSizeLine$1 extends Line$1 {
2715
2808
  constructor(maxMessageSize) {
2716
2809
  super();
@@ -2755,7 +2848,7 @@ class MediaLine$1 extends Line$1 {
2755
2848
  }
2756
2849
  _a$2$1 = MediaLine$1;
2757
2850
  MediaLine$1.MEDIA_TYPE = 'audio|video|application';
2758
- MediaLine$1.regex = new RegExp("^(".concat(_a$2$1.MEDIA_TYPE, ") (").concat(NUM$1, ") (").concat(TOKEN$1, ") (").concat(REST$1, ")"));
2851
+ MediaLine$1.regex = new RegExp("^(".concat(_a$2$1.MEDIA_TYPE, ") (").concat(NUM$1, ") (").concat(ANY_NON_WS, ") (").concat(REST$1, ")"));
2759
2852
  class MidLine$1 extends Line$1 {
2760
2853
  constructor(mid) {
2761
2854
  super();
@@ -2773,7 +2866,7 @@ class MidLine$1 extends Line$1 {
2773
2866
  return "a=mid:".concat(this.mid);
2774
2867
  }
2775
2868
  }
2776
- MidLine$1.regex = new RegExp("^mid:(".concat(TOKEN$1, ")$"));
2869
+ MidLine$1.regex = new RegExp("^mid:(".concat(ANY_NON_WS, ")$"));
2777
2870
  class OriginLine$1 extends Line$1 {
2778
2871
  constructor(username, sessionId, sessionVersion, netType, addrType, ipAddr) {
2779
2872
  super();
@@ -2801,7 +2894,7 @@ class OriginLine$1 extends Line$1 {
2801
2894
  return "o=".concat(this.username, " ").concat(this.sessionId, " ").concat(this.sessionVersion, " ").concat(this.netType, " ").concat(this.addrType, " ").concat(this.ipAddr);
2802
2895
  }
2803
2896
  }
2804
- OriginLine$1.regex = new RegExp("^(".concat(TOKEN$1, ") (").concat(TOKEN$1, ") (").concat(NUM$1, ") (").concat(TOKEN$1, ") (").concat(TOKEN$1, ") (").concat(TOKEN$1, ")"));
2897
+ OriginLine$1.regex = new RegExp("^(".concat(ANY_NON_WS, ") (").concat(ANY_NON_WS, ") (").concat(NUM$1, ") (").concat(ANY_NON_WS, ") (").concat(ANY_NON_WS, ") (").concat(ANY_NON_WS, ")"));
2805
2898
  var _a$1$1;
2806
2899
  class RidLine$1 extends Line$1 {
2807
2900
  constructor(id, direction, params) {
@@ -3069,7 +3162,60 @@ class SimulcastLine$1 extends Line$1 {
3069
3162
  return str;
3070
3163
  }
3071
3164
  }
3072
- SimulcastLine$1.regex = new RegExp("^simulcast:(send|recv) (".concat(TOKEN$1, ")(?: (send|recv) (").concat(TOKEN$1, "))?"));
3165
+ SimulcastLine$1.regex = new RegExp("^simulcast:(send|recv) (".concat(ANY_NON_WS, ")(?: (send|recv) (").concat(ANY_NON_WS, "))?"));
3166
+ class SsrcLine extends Line$1 {
3167
+ constructor(ssrcId, attribute) {
3168
+ var attributeValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
3169
+ var attributeData = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : undefined;
3170
+ super();
3171
+ this.ssrcId = ssrcId;
3172
+ this.attribute = attribute;
3173
+ this.attributeValue = attributeValue;
3174
+ this.attributeData = attributeData;
3175
+ }
3176
+ static fromSdpLine(line) {
3177
+ if (!SsrcLine.regex.test(line)) {
3178
+ return undefined;
3179
+ }
3180
+ var tokens = line.match(SsrcLine.regex);
3181
+ var ssrcId = parseInt(tokens[1], 10);
3182
+ var attribute = tokens[2];
3183
+ var attributeValue = tokens[3];
3184
+ var attributeData = tokens[4];
3185
+ return new SsrcLine(ssrcId, attribute, attributeValue, attributeData);
3186
+ }
3187
+ toSdpLine() {
3188
+ var str = "a=ssrc:".concat(this.ssrcId, " ").concat(this.attribute);
3189
+ if (this.attributeValue) {
3190
+ str += ":".concat(this.attributeValue);
3191
+ }
3192
+ if (this.attributeData) {
3193
+ str += " ".concat(this.attributeData);
3194
+ }
3195
+ return str;
3196
+ }
3197
+ }
3198
+ SsrcLine.regex = new RegExp("^ssrc:(".concat(NUM$1, ") (").concat(SDP_TOKEN, ")(?::(").concat(SDP_TOKEN, ")?(?: (").concat(ANY_NON_WS, "))?)?$"));
3199
+ class SsrcGroupLine extends Line$1 {
3200
+ constructor(semantics, ssrcs) {
3201
+ super();
3202
+ this.semantics = semantics;
3203
+ this.ssrcs = ssrcs;
3204
+ }
3205
+ static fromSdpLine(line) {
3206
+ if (!SsrcGroupLine.regex.test(line)) {
3207
+ return undefined;
3208
+ }
3209
+ var tokens = line.match(SsrcGroupLine.regex);
3210
+ var semantics = tokens[1];
3211
+ var ssrcs = tokens[2].split(' ').map(ssrcStr => parseInt(ssrcStr, 10));
3212
+ return new SsrcGroupLine(semantics, ssrcs);
3213
+ }
3214
+ toSdpLine() {
3215
+ return "a=ssrc-group:".concat(this.semantics, " ").concat(this.ssrcs.join(' '));
3216
+ }
3217
+ }
3218
+ SsrcGroupLine.regex = new RegExp("^ssrc-group:(SIM|FID|FEC) ((?:".concat(NUM$1).concat(SP$1, "*)+)"));
3073
3219
  class TimingLine$1 extends Line$1 {
3074
3220
  constructor(startTime, stopTime) {
3075
3221
  super();
@@ -3306,6 +3452,8 @@ class AvMediaDescription$1 extends MediaDescription$1 {
3306
3452
  this.rids = [];
3307
3453
  this.codecs = new Map();
3308
3454
  this.rtcpMux = false;
3455
+ this.ssrcs = [];
3456
+ this.ssrcGroups = [];
3309
3457
  this.pts = mediaLine.formats.map(fmt => {
3310
3458
  return parseInt(fmt, 10);
3311
3459
  });
@@ -3345,6 +3493,8 @@ class AvMediaDescription$1 extends MediaDescription$1 {
3345
3493
  lines.push(new DirectionLine$1(this.direction));
3346
3494
  }
3347
3495
  this.codecs.forEach(codec => lines.push(...codec.toLines()));
3496
+ lines.push(...this.ssrcs);
3497
+ lines.push(...this.ssrcGroups);
3348
3498
  lines.push(...this.otherLines);
3349
3499
  return lines;
3350
3500
  }
@@ -3383,6 +3533,14 @@ class AvMediaDescription$1 extends MediaDescription$1 {
3383
3533
  codec.addLine(line);
3384
3534
  return true;
3385
3535
  }
3536
+ if (line instanceof SsrcLine) {
3537
+ this.ssrcs.push(line);
3538
+ return true;
3539
+ }
3540
+ if (line instanceof SsrcGroupLine) {
3541
+ this.ssrcGroups.push(line);
3542
+ return true;
3543
+ }
3386
3544
  this.otherLines.push(line);
3387
3545
  return true;
3388
3546
  }
@@ -3527,6 +3685,8 @@ class SdpGrammar$1 extends Grammar$1 {
3527
3685
  this.addParser('a', RidLine$1.fromSdpLine);
3528
3686
  this.addParser('a', CandidateLine$1.fromSdpLine);
3529
3687
  this.addParser('a', SimulcastLine$1.fromSdpLine);
3688
+ this.addParser('a', SsrcLine.fromSdpLine);
3689
+ this.addParser('a', SsrcGroupLine.fromSdpLine);
3530
3690
  }
3531
3691
  }
3532
3692
  var DefaultSdpGrammar$1 = new SdpGrammar$1();
@@ -3601,30 +3761,26 @@ function hasH264Codec(mediaLine) {
3601
3761
  }
3602
3762
  return false;
3603
3763
  }
3604
- function isSdpInvalid(options, errorLog, sdp) {
3764
+ function checkSdpForErrors(options, sdp) {
3605
3765
  if (!sdp) {
3606
- return 'iceCandidate: SDP missing';
3766
+ return new Error('SDP is missing');
3607
3767
  }
3608
3768
  var parsedSdp = parse$2(sdp);
3609
3769
  for (var mediaLine of parsedSdp.avMedia) {
3610
3770
  if (!mediaLine.iceInfo.candidates.length) {
3611
- errorLog('isSdpInvalid', "ice candidates missing for m-line with mid=".concat(mediaLine.mid));
3612
- return 'isSdpInvalid: ice candidates missing';
3771
+ return new IceGatheringError("ice candidates missing for m-line with mid=".concat(mediaLine.mid));
3613
3772
  }
3614
3773
  if (!options.allowPort0 && mediaLine.port === 0) {
3615
- errorLog('isSdpInvalid', "Found invalid port number 0 at m-line with mid=".concat(mediaLine.mid));
3616
- return 'isSdpInvalid: Found invalid port number 0';
3774
+ return new SdpError("Found invalid port number 0 at m-line with mid=".concat(mediaLine.mid));
3617
3775
  }
3618
3776
  if (!mediaLine.iceInfo.pwd || !mediaLine.iceInfo.ufrag) {
3619
- errorLog('isSdpInvalid', "ice ufrag and password not found for m-line with mid=".concat(mediaLine.mid));
3620
- return 'isSdpInvalid: ice ufrag and password not found';
3777
+ return new IceGatheringError("ice ufrag and password not found for m-line with mid=".concat(mediaLine.mid));
3621
3778
  }
3622
3779
  if (options.requireH264 && mediaLine.type === 'video' && !hasH264Codec(mediaLine)) {
3623
- errorLog('isSdpInvalid', "H264 codec is missing for video media description with mid=".concat(mediaLine.mid));
3624
- return 'isSdpInvalid: H264 codec is missing';
3780
+ return new SdpError("H264 codec is missing for video media description with mid=".concat(mediaLine.mid));
3625
3781
  }
3626
3782
  }
3627
- return '';
3783
+ return false;
3628
3784
  }
3629
3785
  function convertCLineToIPv4(sdp) {
3630
3786
  var convertConnectionProp = connection => {
@@ -4232,12 +4388,20 @@ class MediaConnection$1 extends EventEmitter$3 {
4232
4388
  return {
4233
4389
  sdp: mungedSdp
4234
4390
  };
4391
+ }).catch(error => {
4392
+ if (error instanceof IceGatheringError || error instanceof SdpError) {
4393
+ throw error;
4394
+ } else {
4395
+ throw new SdpOfferCreationError("createLocalOffer() failure: ".concat(error.message), {
4396
+ cause: error
4397
+ });
4398
+ }
4235
4399
  });
4236
4400
  }
4237
4401
  handleRemoteOffer(sdp) {
4238
4402
  this.log('handleRemoteOffer', 'called');
4239
4403
  if (!sdp) {
4240
- return Promise.reject(new Error('SDP missing'));
4404
+ return Promise.reject(new SdpOfferHandlingError('SDP missing'));
4241
4405
  }
4242
4406
  var mungedRemoteSdp = mungeRemoteSdp(this.config.sdpMunging, sdp);
4243
4407
  var sdpMungingConfig = this.createSdpMungingConfig();
@@ -4256,37 +4420,50 @@ class MediaConnection$1 extends EventEmitter$3 {
4256
4420
  return {
4257
4421
  sdp: mungedLocalSdp
4258
4422
  };
4423
+ }).catch(error => {
4424
+ if (error instanceof IceGatheringError || error instanceof SdpError) {
4425
+ throw error;
4426
+ } else {
4427
+ throw new SdpOfferHandlingError("handleRemoteOffer() failure: ".concat(error.message), {
4428
+ cause: error
4429
+ });
4430
+ }
4259
4431
  });
4260
4432
  }
4261
4433
  handleRemoteAnswer(sdp) {
4262
4434
  this.log('handleRemoteAnswer', 'called');
4263
4435
  if (!sdp) {
4264
- return Promise.reject(new Error('SDP missing'));
4436
+ return Promise.reject(new SdpAnswerHandlingError('SDP answer missing'));
4265
4437
  }
4266
4438
  var mungedRemoteSdp = mungeRemoteSdp(this.config.sdpMunging, sdp);
4267
4439
  return this.pc.setRemoteDescription(new window.RTCSessionDescription({
4268
4440
  type: 'answer',
4269
4441
  sdp: mungedRemoteSdp
4270
- }));
4442
+ })).catch(error => {
4443
+ throw new SdpAnswerHandlingError("handleRemoteAnswer() failure: ".concat(error.message), {
4444
+ cause: error
4445
+ });
4446
+ });
4271
4447
  }
4272
4448
  waitForIceCandidates() {
4273
4449
  return new Promise((resolve, reject) => {
4274
4450
  var startTime = performance.now();
4275
4451
  var done = false;
4276
- var isLocalSdpValid = () => {
4452
+ var runSdpCheckForErrors = () => {
4277
4453
  var _this$pc$localDescrip3;
4278
- return !isSdpInvalid({
4454
+ return checkSdpForErrors({
4279
4455
  allowPort0: !!this.config.sdpMunging.convertPort9to0,
4280
4456
  requireH264: !!this.config.requireH264
4281
- }, this.error.bind(this), (_this$pc$localDescrip3 = this.pc.localDescription) === null || _this$pc$localDescrip3 === void 0 ? void 0 : _this$pc$localDescrip3.sdp);
4457
+ }, (_this$pc$localDescrip3 = this.pc.localDescription) === null || _this$pc$localDescrip3 === void 0 ? void 0 : _this$pc$localDescrip3.sdp);
4282
4458
  };
4283
4459
  var doneGatheringIceCandidates = () => {
4284
4460
  if (!done) {
4285
4461
  var milliseconds = performance.now() - startTime;
4286
4462
  this.log('waitForIceCandidates()', "checking SDP...");
4287
- if (!isLocalSdpValid()) {
4288
- this.error('waitForIceCandidates()', 'SDP not valid after waiting.');
4289
- reject(new Error('SDP not valid'));
4463
+ var sdpError = runSdpCheckForErrors();
4464
+ if (sdpError) {
4465
+ this.error('waitForIceCandidates()', "SDP not valid after waiting: ".concat(sdpError.message));
4466
+ reject(sdpError);
4290
4467
  }
4291
4468
  this.log('waitForIceCandidates()', "It took ".concat(milliseconds, " milliseconds to gather ice candidates"));
4292
4469
  done = true;
@@ -4296,7 +4473,7 @@ class MediaConnection$1 extends EventEmitter$3 {
4296
4473
  resolve();
4297
4474
  }
4298
4475
  };
4299
- if (this.pc.iceGatheringState === 'complete' && isLocalSdpValid()) {
4476
+ if (this.pc.iceGatheringState === 'complete' && runSdpCheckForErrors() === false) {
4300
4477
  this.log('waitForIceCandidates()', 'iceGatheringState is already "complete" and local SDP is valid');
4301
4478
  resolve();
4302
4479
  return;
@@ -6910,6 +7087,29 @@ function shimRTCIceCandidate$1(window) {
6910
7087
  return e;
6911
7088
  });
6912
7089
  }
7090
+ function shimRTCIceCandidateRelayProtocol(window) {
7091
+ if (!window.RTCIceCandidate || window.RTCIceCandidate && 'relayProtocol' in window.RTCIceCandidate.prototype) {
7092
+ return;
7093
+ }
7094
+
7095
+ // Hook up the augmented candidate in onicecandidate and
7096
+ // addEventListener('icecandidate', ...)
7097
+ wrapPeerConnectionEvent$1(window, 'icecandidate', e => {
7098
+ if (e.candidate) {
7099
+ var parsedCandidate = SDPUtils$1.parseCandidate(e.candidate.candidate);
7100
+ if (parsedCandidate.type === 'relay') {
7101
+ // This is a libwebrtc-specific mapping of local type preference
7102
+ // to relayProtocol.
7103
+ e.candidate.relayProtocol = {
7104
+ 0: 'tls',
7105
+ 1: 'tcp',
7106
+ 2: 'udp'
7107
+ }[parsedCandidate.priority >> 24];
7108
+ }
7109
+ }
7110
+ return e;
7111
+ });
7112
+ }
6913
7113
  function shimMaxMessageSize$1(window, browserDetails) {
6914
7114
  if (!window.RTCPeerConnection) {
6915
7115
  return;
@@ -7246,6 +7446,7 @@ function shimParameterlessSetLocalDescription$1(window, browserDetails) {
7246
7446
  var commonShim$1 = /*#__PURE__*/Object.freeze({
7247
7447
  __proto__: null,
7248
7448
  shimRTCIceCandidate: shimRTCIceCandidate$1,
7449
+ shimRTCIceCandidateRelayProtocol: shimRTCIceCandidateRelayProtocol,
7249
7450
  shimMaxMessageSize: shimMaxMessageSize$1,
7250
7451
  shimSendThrowTypeError: shimSendThrowTypeError$1,
7251
7452
  shimConnectionState: shimConnectionState$1,
@@ -7313,6 +7514,7 @@ function adapterFactory$1() {
7313
7514
  shimSenderReceiverGetStats$1(window);
7314
7515
  fixNegotiationNeeded$1(window, browserDetails);
7315
7516
  shimRTCIceCandidate$1(window);
7517
+ shimRTCIceCandidateRelayProtocol(window);
7316
7518
  shimConnectionState$1(window);
7317
7519
  shimMaxMessageSize$1(window, browserDetails);
7318
7520
  shimSendThrowTypeError$1(window);
@@ -7367,6 +7569,7 @@ function adapterFactory$1() {
7367
7569
  shimGetUserMedia$3(window);
7368
7570
  shimAudioContext$1(window);
7369
7571
  shimRTCIceCandidate$1(window);
7572
+ shimRTCIceCandidateRelayProtocol(window);
7370
7573
  shimMaxMessageSize$1(window, browserDetails);
7371
7574
  shimSendThrowTypeError$1(window);
7372
7575
  removeExtmapAllowMixed$1(window, browserDetails);
@@ -8285,18 +8488,44 @@ function error(id, data) {
8285
8488
  };
8286
8489
  return eventObject;
8287
8490
  }
8288
- function resolveActions(machine, currentState, currentContext, _event, actions, predictableExec, preserveActionOrder) {
8491
+ var pluckAssigns = function pluckAssigns(actionBlocks) {
8492
+ var e_1, _a;
8493
+ var assignActions = [];
8494
+ try {
8495
+ for (var actionBlocks_1 = __values(actionBlocks), actionBlocks_1_1 = actionBlocks_1.next(); !actionBlocks_1_1.done; actionBlocks_1_1 = actionBlocks_1.next()) {
8496
+ var block = actionBlocks_1_1.value;
8497
+ var i = 0;
8498
+ while (i < block.length) {
8499
+ if (block[i].type === assign$2) {
8500
+ assignActions.push(block[i]);
8501
+ block.splice(i, 1);
8502
+ continue;
8503
+ }
8504
+ i++;
8505
+ }
8506
+ }
8507
+ } catch (e_1_1) {
8508
+ e_1 = {
8509
+ error: e_1_1
8510
+ };
8511
+ } finally {
8512
+ try {
8513
+ if (actionBlocks_1_1 && !actionBlocks_1_1.done && (_a = actionBlocks_1.return)) _a.call(actionBlocks_1);
8514
+ } finally {
8515
+ if (e_1) throw e_1.error;
8516
+ }
8517
+ }
8518
+ return assignActions;
8519
+ };
8520
+ function resolveActions(machine, currentState, currentContext, _event, actionBlocks, predictableExec, preserveActionOrder) {
8289
8521
  if (preserveActionOrder === void 0) {
8290
8522
  preserveActionOrder = false;
8291
8523
  }
8292
- var _a = __read(preserveActionOrder ? [[], actions] : partition(actions, function (action) {
8293
- return action.type === assign$2;
8294
- }), 2),
8295
- assignActions = _a[0],
8296
- otherActions = _a[1];
8524
+ var assignActions = preserveActionOrder ? [] : pluckAssigns(actionBlocks);
8297
8525
  var updatedContext = assignActions.length ? updateContext(currentContext, _event, assignActions, currentState) : currentContext;
8298
8526
  var preservedContexts = preserveActionOrder ? [currentContext] : undefined;
8299
- var resolvedActions = flatten(otherActions.map(function (actionObject) {
8527
+ var deferredToBlockEnd = [];
8528
+ function handleAction(actionObject) {
8300
8529
  var _a;
8301
8530
  switch (actionObject.type) {
8302
8531
  case raise$1:
@@ -8312,8 +8541,8 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
8312
8541
  // tslint:disable-next-line:max-line-length
8313
8542
  "No delay reference for delay expression '".concat(actionObject.delay, "' was found on machine '").concat(machine.id, "'"));
8314
8543
  }
8315
- if (sendAction.to !== SpecialTargets.Internal) {
8316
- predictableExec === null || predictableExec === void 0 ? void 0 : predictableExec(sendAction, updatedContext, _event);
8544
+ if (predictableExec && sendAction.to !== SpecialTargets.Internal) {
8545
+ deferredToBlockEnd.push(sendAction);
8317
8546
  }
8318
8547
  return sendAction;
8319
8548
  case log$2:
@@ -8332,7 +8561,7 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
8332
8561
  if (!matchedActions) {
8333
8562
  return [];
8334
8563
  }
8335
- var _b = __read(resolveActions(machine, currentState, updatedContext, _event, toActionObjects(toArray(matchedActions), machine.options.actions), predictableExec, preserveActionOrder), 2),
8564
+ var _b = __read(resolveActions(machine, currentState, updatedContext, _event, [toActionObjects(toArray(matchedActions), machine.options.actions)], predictableExec, preserveActionOrder), 2),
8336
8565
  resolvedActionsFromChoose = _b[0],
8337
8566
  resolvedContextFromChoose = _b[1];
8338
8567
  updatedContext = resolvedContextFromChoose;
@@ -8345,7 +8574,7 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
8345
8574
  if (!matchedActions) {
8346
8575
  return [];
8347
8576
  }
8348
- var _c = __read(resolveActions(machine, currentState, updatedContext, _event, toActionObjects(toArray(matchedActions), machine.options.actions), predictableExec, preserveActionOrder), 2),
8577
+ var _c = __read(resolveActions(machine, currentState, updatedContext, _event, [toActionObjects(toArray(matchedActions), machine.options.actions)], predictableExec, preserveActionOrder), 2),
8349
8578
  resolvedActionsFromPure = _c[0],
8350
8579
  resolvedContext = _c[1];
8351
8580
  updatedContext = resolvedContext;
@@ -8355,7 +8584,7 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
8355
8584
  case stop$1:
8356
8585
  {
8357
8586
  var resolved = resolveStop(actionObject, updatedContext, _event);
8358
- predictableExec === null || predictableExec === void 0 ? void 0 : predictableExec(resolved, updatedContext, _event);
8587
+ predictableExec === null || predictableExec === void 0 ? void 0 : predictableExec(resolved, currentContext, _event);
8359
8588
  return resolved;
8360
8589
  }
8361
8590
  case assign$2:
@@ -8383,9 +8612,36 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
8383
8612
  }
8384
8613
  return resolvedActionObject;
8385
8614
  }
8386
- }).filter(function (a) {
8387
- return !!a;
8388
- }));
8615
+ }
8616
+ function processBlock(block) {
8617
+ var e_2, _a;
8618
+ var resolvedActions = [];
8619
+ try {
8620
+ for (var block_1 = __values(block), block_1_1 = block_1.next(); !block_1_1.done; block_1_1 = block_1.next()) {
8621
+ var action = block_1_1.value;
8622
+ var resolved = handleAction(action);
8623
+ if (resolved) {
8624
+ resolvedActions = resolvedActions.concat(resolved);
8625
+ }
8626
+ }
8627
+ } catch (e_2_1) {
8628
+ e_2 = {
8629
+ error: e_2_1
8630
+ };
8631
+ } finally {
8632
+ try {
8633
+ if (block_1_1 && !block_1_1.done && (_a = block_1.return)) _a.call(block_1);
8634
+ } finally {
8635
+ if (e_2) throw e_2.error;
8636
+ }
8637
+ }
8638
+ deferredToBlockEnd.forEach(function (action) {
8639
+ predictableExec(action, updatedContext, _event);
8640
+ });
8641
+ deferredToBlockEnd.length = 0;
8642
+ return resolvedActions;
8643
+ }
8644
+ var resolvedActions = flatten(actionBlocks.map(processBlock));
8389
8645
  return [resolvedActions, updatedContext];
8390
8646
  }
8391
8647
 
@@ -9134,10 +9390,10 @@ function () {
9134
9390
  * @param options Interpreter options
9135
9391
  */
9136
9392
  function Interpreter(machine, options) {
9137
- var _this = this;
9138
9393
  if (options === void 0) {
9139
9394
  options = Interpreter.defaultOptions;
9140
9395
  }
9396
+ var _this = this;
9141
9397
  this.machine = machine;
9142
9398
  this.delayedEventsMap = {};
9143
9399
  this.listeners = new Set();
@@ -9154,6 +9410,7 @@ function () {
9154
9410
  this.status = InterpreterStatus.NotStarted;
9155
9411
  this.children = new Map();
9156
9412
  this.forwardTo = new Set();
9413
+ this._outgoingQueue = [];
9157
9414
  /**
9158
9415
  * Alias for Interpreter.prototype.start
9159
9416
  */
@@ -9189,14 +9446,14 @@ function () {
9189
9446
  _this.scheduler.schedule(function () {
9190
9447
  // Forward copy of event to child actors
9191
9448
  _this.forward(_event);
9192
- var nextState = _this.nextState(_event);
9449
+ var nextState = _this._nextState(_event);
9193
9450
  _this.update(nextState, _event);
9194
9451
  });
9195
9452
  return _this._state; // TODO: deprecate (should return void)
9196
9453
  // tslint:disable-next-line:semicolon
9197
9454
  };
9198
9455
 
9199
- this.sendTo = function (event, to) {
9456
+ this.sendTo = function (event, to, immediate) {
9200
9457
  var isParent = _this.parent && (to === SpecialTargets.Parent || _this.parent.id === to);
9201
9458
  var target = isParent ? _this.parent : isString(to) ? _this.children.get(to) || registry.get(to) : isActor$1(to) ? to : undefined;
9202
9459
  if (!target) {
@@ -9216,14 +9473,23 @@ function () {
9216
9473
  // we need to send events to the parent from exit handlers of a machine that reached its final state
9217
9474
  _this.state.done) {
9218
9475
  // Send SCXML events to machines
9219
- target.send(_assign(_assign({}, event), {
9476
+ var scxmlEvent = _assign(_assign({}, event), {
9220
9477
  name: event.name === error$1 ? "".concat(error(_this.id)) : event.name,
9221
9478
  origin: _this.sessionId
9222
- }));
9479
+ });
9480
+ if (!immediate && _this.machine.config.predictableActionArguments) {
9481
+ _this._outgoingQueue.push([target, scxmlEvent]);
9482
+ } else {
9483
+ target.send(scxmlEvent);
9484
+ }
9223
9485
  }
9224
9486
  } else {
9225
9487
  // Send normal events to other targets
9226
- target.send(event.data);
9488
+ if (!immediate && _this.machine.config.predictableActionArguments) {
9489
+ _this._outgoingQueue.push([target, event.data]);
9490
+ } else {
9491
+ target.send(event.data);
9492
+ }
9227
9493
  }
9228
9494
  };
9229
9495
  this._exec = function (action, context, _event, actionFunctionMap) {
@@ -9260,7 +9526,7 @@ function () {
9260
9526
  return;
9261
9527
  } else {
9262
9528
  if (sendAction.to) {
9263
- _this.sendTo(sendAction._event, sendAction.to);
9529
+ _this.sendTo(sendAction._event, sendAction.to, _event === initEvent);
9264
9530
  } else {
9265
9531
  _this.send(sendAction._event);
9266
9532
  }
@@ -9381,6 +9647,9 @@ function () {
9381
9647
  configurable: true
9382
9648
  });
9383
9649
  Object.defineProperty(Interpreter.prototype, "state", {
9650
+ /**
9651
+ * @deprecated Use `.getSnapshot()` instead.
9652
+ */
9384
9653
  get: function get() {
9385
9654
  if (!IS_PRODUCTION) {
9386
9655
  warn(this.status !== InterpreterStatus.NotStarted, "Attempted to read state from uninitialized service '".concat(this.id, "'. Make sure the service is started first."));
@@ -9429,6 +9698,11 @@ function () {
9429
9698
  // we can't just recompute it (and execute actions while doing so) because we try to preserve identity of actors created within initial assigns
9430
9699
  _event === initEvent) && this.options.execute) {
9431
9700
  this.execute(this.state);
9701
+ } else {
9702
+ var item = void 0;
9703
+ while (item = this._outgoingQueue.shift()) {
9704
+ item[0].send(item[1]);
9705
+ }
9432
9706
  } // Update children
9433
9707
 
9434
9708
  this.children.forEach(function (child) {
@@ -9512,6 +9786,7 @@ function () {
9512
9786
  }
9513
9787
  }
9514
9788
  this._stop();
9789
+ this._stopChildren();
9515
9790
  }
9516
9791
  };
9517
9792
  /*
@@ -9647,6 +9922,15 @@ function () {
9647
9922
  });
9648
9923
  return this;
9649
9924
  };
9925
+ Interpreter.prototype._stopChildren = function () {
9926
+ // TODO: think about converting those to actions
9927
+ this.children.forEach(function (child) {
9928
+ if (isFunction(child.stop)) {
9929
+ child.stop();
9930
+ }
9931
+ });
9932
+ this.children.clear();
9933
+ };
9650
9934
  Interpreter.prototype._stop = function () {
9651
9935
  var e_6, _a, e_7, _b, e_8, _c, e_9, _d, e_10, _e;
9652
9936
  try {
@@ -9770,7 +10054,7 @@ function () {
9770
10054
  }).map(function (stateNode) {
9771
10055
  return toActionObjects(stateNode.onExit, _this.machine.options.actions);
9772
10056
  }));
9773
- var _a = __read(resolveActions(_this.machine, _this.state, _this.state.context, _event, exitActions, _this.machine.config.predictableActionArguments ? _this._exec : undefined, _this.machine.config.predictableActionArguments || _this.machine.config.preserveActionOrder), 2),
10057
+ var _a = __read(resolveActions(_this.machine, _this.state, _this.state.context, _event, [exitActions], _this.machine.config.predictableActionArguments ? _this._exec : undefined, _this.machine.config.predictableActionArguments || _this.machine.config.preserveActionOrder), 2),
9774
10058
  resolvedActions = _a[0],
9775
10059
  updatedContext = _a[1];
9776
10060
  var newState = new State({
@@ -9795,15 +10079,8 @@ function () {
9795
10079
  newState.changed = true;
9796
10080
  return newState;
9797
10081
  });
9798
- _this.update(nextState, _event); // TODO: think about converting those to actions
9799
- // Stop all children
9800
-
9801
- _this.children.forEach(function (child) {
9802
- if (isFunction(child.stop)) {
9803
- child.stop();
9804
- }
9805
- });
9806
- _this.children.clear();
10082
+ _this.update(nextState, _event);
10083
+ _this._stopChildren();
9807
10084
  registry.free(_this.sessionId);
9808
10085
  });
9809
10086
  return this;
@@ -9820,6 +10097,10 @@ function () {
9820
10097
  // tslint:disable-next-line:max-line-length
9821
10098
  "".concat(events.length, " event(s) were sent to uninitialized service \"").concat(this.machine.id, "\". Make sure .start() is called for this service, or set { deferEvents: true } in the service options."));
9822
10099
  }
10100
+ if (!events.length) {
10101
+ return;
10102
+ }
10103
+ var exec = !!this.machine.config.predictableActionArguments && this._exec;
9823
10104
  this.scheduler.schedule(function () {
9824
10105
  var e_11, _a;
9825
10106
  var nextState = _this.state;
@@ -9829,9 +10110,9 @@ function () {
9829
10110
  var _event = toSCXMLEvent(event_1);
9830
10111
  _this.forward(_event);
9831
10112
  nextState = provide(_this, function () {
9832
- return _this.machine.transition(nextState, _event);
10113
+ return _this.machine.transition(nextState, _event, undefined, exec || undefined);
9833
10114
  });
9834
- batchedActions.push.apply(batchedActions, __spreadArray([], __read(nextState.actions.map(function (a) {
10115
+ batchedActions.push.apply(batchedActions, __spreadArray([], __read(_this.machine.config.predictableActionArguments ? nextState.actions : nextState.actions.map(function (a) {
9835
10116
  return bindActionToState(a, nextState);
9836
10117
  })), false));
9837
10118
  batchChanged = batchChanged || !!nextState.changed;
@@ -9866,8 +10147,11 @@ function () {
9866
10147
  Interpreter.prototype.sender = function (event) {
9867
10148
  return this.send.bind(this, event);
9868
10149
  };
9869
- Interpreter.prototype._nextState = function (event) {
10150
+ Interpreter.prototype._nextState = function (event, exec) {
9870
10151
  var _this = this;
10152
+ if (exec === void 0) {
10153
+ exec = !!this.machine.config.predictableActionArguments && this._exec;
10154
+ }
9871
10155
  var _event = toSCXMLEvent(event);
9872
10156
  if (_event.name.indexOf(errorPlatform) === 0 && !this.state.nextEvents.some(function (nextEvent) {
9873
10157
  return nextEvent.indexOf(errorPlatform) === 0;
@@ -9875,7 +10159,7 @@ function () {
9875
10159
  throw _event.data.data;
9876
10160
  }
9877
10161
  var nextState = provide(this, function () {
9878
- return _this.machine.transition(_this.state, _event, undefined, _this.machine.config.predictableActionArguments ? _this._exec : undefined);
10162
+ return _this.machine.transition(_this.state, _event, undefined, exec || undefined);
9879
10163
  });
9880
10164
  return nextState;
9881
10165
  };
@@ -9888,7 +10172,7 @@ function () {
9888
10172
  */
9889
10173
 
9890
10174
  Interpreter.prototype.nextState = function (event) {
9891
- return this._nextState(event);
10175
+ return this._nextState(event, false);
9892
10176
  };
9893
10177
  Interpreter.prototype.forward = function (event) {
9894
10178
  var e_12, _a;
@@ -9917,7 +10201,7 @@ function () {
9917
10201
  var _this = this;
9918
10202
  this.delayedEventsMap[sendAction.id] = this.clock.setTimeout(function () {
9919
10203
  if (sendAction.to) {
9920
- _this.sendTo(sendAction._event, sendAction.to);
10204
+ _this.sendTo(sendAction._event, sendAction.to, true);
9921
10205
  } else {
9922
10206
  _this.send(sendAction._event);
9923
10207
  }
@@ -10412,10 +10696,10 @@ function () {
10412
10696
  _context,
10413
10697
  // TODO: this is unsafe, but we're removing it in v5 anyway
10414
10698
  _stateInfo) {
10415
- var _this = this;
10416
10699
  if (_context === void 0) {
10417
10700
  _context = 'context' in config ? config.context : undefined;
10418
10701
  }
10702
+ var _this = this;
10419
10703
  var _a;
10420
10704
  this.config = config;
10421
10705
  this._context = _context;
@@ -10954,13 +11238,14 @@ function () {
10954
11238
  nodes.push(possibleAncestor);
10955
11239
  return nodes;
10956
11240
  };
10957
- StateNode.prototype.getActions = function (resolvedConfig, isDone, transition, currentContext, _event, prevState) {
11241
+ StateNode.prototype.getActions = function (resolvedConfig, isDone, transition, currentContext, _event, prevState, predictableExec) {
10958
11242
  var e_4, _a, e_5, _b;
11243
+ var _this = this;
10959
11244
  var prevConfig = getConfiguration([], prevState ? this.getStateNodes(prevState.value) : [this]);
10960
11245
  try {
10961
11246
  for (var resolvedConfig_1 = __values(resolvedConfig), resolvedConfig_1_1 = resolvedConfig_1.next(); !resolvedConfig_1_1.done; resolvedConfig_1_1 = resolvedConfig_1.next()) {
10962
11247
  var sn = resolvedConfig_1_1.value;
10963
- if (!has(prevConfig, sn) || has(transition.entrySet, sn.parent)) {
11248
+ if (!has(prevConfig, sn) || has(transition.entrySet, sn.parent) && !has(transition.entrySet, sn)) {
10964
11249
  transition.entrySet.push(sn);
10965
11250
  }
10966
11251
  }
@@ -11023,18 +11308,19 @@ function () {
11023
11308
  });
11024
11309
  var entryStates = new Set(transition.entrySet);
11025
11310
  var exitStates = new Set(transition.exitSet);
11026
- var _c = __read([flatten(Array.from(entryStates).map(function (stateNode) {
11027
- return __spreadArray(__spreadArray([], __read(stateNode.activities.map(function (activity) {
11028
- return start(activity);
11029
- })), false), __read(stateNode.onEntry), false);
11030
- })).concat(doneEvents.map(raise)), flatten(Array.from(exitStates).map(function (stateNode) {
11031
- return __spreadArray(__spreadArray([], __read(stateNode.onExit), false), __read(stateNode.activities.map(function (activity) {
11032
- return stop(activity);
11033
- })), false);
11034
- }))], 2),
11035
- entryActions = _c[0],
11036
- exitActions = _c[1];
11037
- var actions = toActionObjects(exitActions.concat(transition.actions).concat(entryActions), this.machine.options.actions);
11311
+ var entryActions = Array.from(entryStates).map(function (stateNode) {
11312
+ var entryActions = stateNode.onEntry;
11313
+ var invokeActions = stateNode.activities.map(function (activity) {
11314
+ return start(activity);
11315
+ });
11316
+ return toActionObjects(predictableExec ? __spreadArray(__spreadArray([], __read(entryActions), false), __read(invokeActions), false) : __spreadArray(__spreadArray([], __read(invokeActions), false), __read(entryActions), false), _this.machine.options.actions);
11317
+ }).concat([doneEvents.map(raise)]);
11318
+ var exitActions = Array.from(exitStates).map(function (stateNode) {
11319
+ return toActionObjects(__spreadArray(__spreadArray([], __read(stateNode.onExit), false), __read(stateNode.activities.map(function (activity) {
11320
+ return stop(activity);
11321
+ })), false), _this.machine.options.actions);
11322
+ });
11323
+ var actions = exitActions.concat([toActionObjects(transition.actions, this.machine.options.actions)]).concat(entryActions);
11038
11324
  if (isDone) {
11039
11325
  var stopActions = toActionObjects(flatten(__spreadArray([], __read(resolvedConfig), false).sort(function (a, b) {
11040
11326
  return b.order - a.order;
@@ -11043,7 +11329,7 @@ function () {
11043
11329
  })), this.machine.options.actions).filter(function (action) {
11044
11330
  return action.type !== raise$1 && (action.type !== send$1 || !!action.to && action.to !== SpecialTargets.Internal);
11045
11331
  });
11046
- return actions.concat(stopActions);
11332
+ return actions.concat([stopActions]);
11047
11333
  }
11048
11334
  return actions;
11049
11335
  };
@@ -11101,7 +11387,7 @@ function () {
11101
11387
  return state;
11102
11388
  };
11103
11389
  StateNode.prototype.resolveTransition = function (stateTransition, currentState, context, predictableExec, _event) {
11104
- var e_6, _a;
11390
+ var e_6, _a, e_7, _b;
11105
11391
  var _this = this;
11106
11392
  if (_event === void 0) {
11107
11393
  _event = initEvent;
@@ -11115,15 +11401,30 @@ function () {
11115
11401
  var isDone = isInFinalState(resolvedConfiguration, this);
11116
11402
  var resolvedStateValue = willTransition ? getValue(this.machine, configuration) : undefined;
11117
11403
  var historyValue = currentState ? currentState.historyValue ? currentState.historyValue : stateTransition.source ? this.machine.historyValue(currentState.value) : undefined : undefined;
11118
- var actions = this.getActions(new Set(resolvedConfiguration), isDone, stateTransition, context, _event, currentState);
11404
+ var actionBlocks = this.getActions(new Set(resolvedConfiguration), isDone, stateTransition, context, _event, currentState, predictableExec);
11119
11405
  var activities = currentState ? _assign({}, currentState.activities) : {};
11120
11406
  try {
11121
- for (var actions_1 = __values(actions), actions_1_1 = actions_1.next(); !actions_1_1.done; actions_1_1 = actions_1.next()) {
11122
- var action = actions_1_1.value;
11123
- if (action.type === start$1) {
11124
- activities[action.activity.id || action.activity.type] = action;
11125
- } else if (action.type === stop$1) {
11126
- activities[action.activity.id || action.activity.type] = false;
11407
+ for (var actionBlocks_1 = __values(actionBlocks), actionBlocks_1_1 = actionBlocks_1.next(); !actionBlocks_1_1.done; actionBlocks_1_1 = actionBlocks_1.next()) {
11408
+ var block = actionBlocks_1_1.value;
11409
+ try {
11410
+ for (var block_1 = (e_7 = void 0, __values(block)), block_1_1 = block_1.next(); !block_1_1.done; block_1_1 = block_1.next()) {
11411
+ var action = block_1_1.value;
11412
+ if (action.type === start$1) {
11413
+ activities[action.activity.id || action.activity.type] = action;
11414
+ } else if (action.type === stop$1) {
11415
+ activities[action.activity.id || action.activity.type] = false;
11416
+ }
11417
+ }
11418
+ } catch (e_7_1) {
11419
+ e_7 = {
11420
+ error: e_7_1
11421
+ };
11422
+ } finally {
11423
+ try {
11424
+ if (block_1_1 && !block_1_1.done && (_b = block_1.return)) _b.call(block_1);
11425
+ } finally {
11426
+ if (e_7) throw e_7.error;
11427
+ }
11127
11428
  }
11128
11429
  }
11129
11430
  } catch (e_6_1) {
@@ -11132,19 +11433,19 @@ function () {
11132
11433
  };
11133
11434
  } finally {
11134
11435
  try {
11135
- if (actions_1_1 && !actions_1_1.done && (_a = actions_1.return)) _a.call(actions_1);
11436
+ if (actionBlocks_1_1 && !actionBlocks_1_1.done && (_a = actionBlocks_1.return)) _a.call(actionBlocks_1);
11136
11437
  } finally {
11137
11438
  if (e_6) throw e_6.error;
11138
11439
  }
11139
11440
  }
11140
- var _b = __read(resolveActions(this, currentState, context, _event, actions, predictableExec, this.machine.config.predictableActionArguments || this.machine.config.preserveActionOrder), 2),
11141
- resolvedActions = _b[0],
11142
- updatedContext = _b[1];
11143
- var _c = __read(partition(resolvedActions, function (action) {
11441
+ var _c = __read(resolveActions(this, currentState, context, _event, actionBlocks, predictableExec, this.machine.config.predictableActionArguments || this.machine.config.preserveActionOrder), 2),
11442
+ resolvedActions = _c[0],
11443
+ updatedContext = _c[1];
11444
+ var _d = __read(partition(resolvedActions, function (action) {
11144
11445
  return action.type === raise$1 || action.type === send$1 && action.to === SpecialTargets.Internal;
11145
11446
  }), 2),
11146
- raisedEvents = _c[0],
11147
- nonRaisedActions = _c[1];
11447
+ raisedEvents = _d[0],
11448
+ nonRaisedActions = _d[1];
11148
11449
  var invokeActions = resolvedActions.filter(function (action) {
11149
11450
  var _a;
11150
11451
  return action.type === start$1 && ((_a = action.activity) === null || _a === void 0 ? void 0 : _a.type) === invoke;
@@ -11352,7 +11653,7 @@ function () {
11352
11653
  var configuration = this.getStateNodes(stateValue);
11353
11654
  return this.resolveTransition({
11354
11655
  configuration: configuration,
11355
- entrySet: __spreadArray([], __read(configuration), false),
11656
+ entrySet: configuration,
11356
11657
  exitSet: [],
11357
11658
  transitions: [],
11358
11659
  source: undefined,
@@ -11518,7 +11819,7 @@ function () {
11518
11819
  * All the event types accepted by this state node and its descendants.
11519
11820
  */
11520
11821
  get: function get() {
11521
- var e_7, _a, e_8, _b;
11822
+ var e_8, _a, e_9, _b;
11522
11823
  if (this.__cache.events) {
11523
11824
  return this.__cache.events;
11524
11825
  }
@@ -11531,32 +11832,32 @@ function () {
11531
11832
  var state = states[stateId];
11532
11833
  if (state.states) {
11533
11834
  try {
11534
- for (var _e = (e_8 = void 0, __values(state.events)), _f = _e.next(); !_f.done; _f = _e.next()) {
11835
+ for (var _e = (e_9 = void 0, __values(state.events)), _f = _e.next(); !_f.done; _f = _e.next()) {
11535
11836
  var event_1 = _f.value;
11536
11837
  events.add("".concat(event_1));
11537
11838
  }
11538
- } catch (e_8_1) {
11539
- e_8 = {
11540
- error: e_8_1
11839
+ } catch (e_9_1) {
11840
+ e_9 = {
11841
+ error: e_9_1
11541
11842
  };
11542
11843
  } finally {
11543
11844
  try {
11544
11845
  if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
11545
11846
  } finally {
11546
- if (e_8) throw e_8.error;
11847
+ if (e_9) throw e_9.error;
11547
11848
  }
11548
11849
  }
11549
11850
  }
11550
11851
  }
11551
- } catch (e_7_1) {
11552
- e_7 = {
11553
- error: e_7_1
11852
+ } catch (e_8_1) {
11853
+ e_8 = {
11854
+ error: e_8_1
11554
11855
  };
11555
11856
  } finally {
11556
11857
  try {
11557
11858
  if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
11558
11859
  } finally {
11559
- if (e_7) throw e_7.error;
11860
+ if (e_8) throw e_8.error;
11560
11861
  }
11561
11862
  }
11562
11863
  }
@@ -11638,7 +11939,7 @@ function () {
11638
11939
  return transition;
11639
11940
  };
11640
11941
  StateNode.prototype.formatTransitions = function () {
11641
- var e_9, _a;
11942
+ var e_10, _a;
11642
11943
  var _this = this;
11643
11944
  var onConfig;
11644
11945
  if (!this.config.on) {
@@ -11688,15 +11989,15 @@ function () {
11688
11989
  var delayedTransition = delayedTransitions_1_1.value;
11689
11990
  formattedTransitions.push(delayedTransition);
11690
11991
  }
11691
- } catch (e_9_1) {
11692
- e_9 = {
11693
- error: e_9_1
11992
+ } catch (e_10_1) {
11993
+ e_10 = {
11994
+ error: e_10_1
11694
11995
  };
11695
11996
  } finally {
11696
11997
  try {
11697
11998
  if (delayedTransitions_1_1 && !delayedTransitions_1_1.done && (_a = delayedTransitions_1.return)) _a.call(delayedTransitions_1);
11698
11999
  } finally {
11699
- if (e_9) throw e_9.error;
12000
+ if (e_10) throw e_10.error;
11700
12001
  }
11701
12002
  }
11702
12003
  return formattedTransitions;
@@ -11753,13 +12054,13 @@ class Roap extends EventEmitter$3 {
11753
12054
  browserError: {
11754
12055
  onEntry: (context, event) => {
11755
12056
  this.error('FSM', "browserError state onEntry: context=".concat(JSON.stringify(context), ":"), event.data);
11756
- this.emit(Event$1.ROAP_FAILURE);
12057
+ this.emit(Event$1.ROAP_FAILURE, event.data);
11757
12058
  }
11758
12059
  },
11759
12060
  remoteError: {
11760
- onEntry: () => {
12061
+ onEntry: (_, event) => {
11761
12062
  this.log('FSM', 'remoteError state onEntry called, emitting Event.ROAP_FAILURE');
11762
- this.emit(Event$1.ROAP_FAILURE);
12063
+ this.emit(Event$1.ROAP_FAILURE, event.data);
11763
12064
  }
11764
12065
  },
11765
12066
  idle: {
@@ -12266,7 +12567,7 @@ class RoapMediaConnection extends EventEmitter$3 {
12266
12567
  roap.on(Event$1.ROAP_MESSAGE_TO_SEND, event => this.emit(Event$1.ROAP_MESSAGE_TO_SEND, event));
12267
12568
  roap.on(Event$1.ROAP_STARTED, () => this.emit(Event$1.ROAP_STARTED));
12268
12569
  roap.on(Event$1.ROAP_DONE, () => this.emit(Event$1.ROAP_DONE));
12269
- roap.on(Event$1.ROAP_FAILURE, () => this.emit(Event$1.ROAP_FAILURE));
12570
+ roap.on(Event$1.ROAP_FAILURE, error => this.emit(Event$1.ROAP_FAILURE, error));
12270
12571
  return roap;
12271
12572
  }
12272
12573
  initiateOffer() {
@@ -22113,7 +22414,7 @@ class MultistreamRoapMediaConnection extends EventEmitter$4 {
22113
22414
  roap.on(Event$1.ROAP_MESSAGE_TO_SEND, event => this.emit(Event$1.ROAP_MESSAGE_TO_SEND, event));
22114
22415
  roap.on(Event$1.ROAP_STARTED, () => this.emit(Event$1.ROAP_STARTED));
22115
22416
  roap.on(Event$1.ROAP_DONE, () => this.emit(Event$1.ROAP_DONE));
22116
- roap.on(Event$1.ROAP_FAILURE, () => this.emit(Event$1.ROAP_FAILURE));
22417
+ roap.on(Event$1.ROAP_FAILURE, error => this.emit(Event$1.ROAP_FAILURE, error));
22117
22418
  return roap;
22118
22419
  }
22119
22420
  initiateOffer() {
@@ -22185,26 +22486,38 @@ class MultistreamRoapMediaConnection extends EventEmitter$4 {
22185
22486
  sdp: result.sdp
22186
22487
  };
22187
22488
  }
22188
- return Promise.reject(new Error('empty local SDP'));
22489
+ return Promise.reject(new SdpOfferCreationError('empty local SDP'));
22490
+ }).catch(error => {
22491
+ throw new SdpOfferCreationError("createLocalOffer() failure: ".concat(error.message), {
22492
+ cause: error
22493
+ });
22189
22494
  });
22190
22495
  }
22191
22496
  handleRemoteOffer() {
22192
- return Promise.reject(new Error('remote offers not supported by WCME'));
22497
+ return Promise.reject(new SdpOfferHandlingError('remote offers not supported by WCME'));
22193
22498
  }
22194
22499
  handleRemoteAnswer(sdp) {
22195
22500
  if (sdp) {
22196
22501
  var mungedSdp = sdp;
22197
22502
  mungedSdp = mungedSdp.replace(/\r\nb=TIAS:.*\r\n/g, '\r\n');
22198
- return this.multistreamConnection.setAnswer(mungedSdp);
22503
+ return this.multistreamConnection.setAnswer(mungedSdp).catch(error => {
22504
+ throw new SdpAnswerHandlingError("handleRemoteAnswer() failure: ".concat(error.message), {
22505
+ cause: error
22506
+ });
22507
+ });
22199
22508
  }
22200
- return Promise.reject(new Error('empty answer'));
22509
+ return Promise.reject(new SdpAnswerHandlingError('empty answer'));
22201
22510
  }
22202
22511
  }
22203
22512
 
22513
+ var Errors = Error$1;
22514
+
22204
22515
  var MediaConnections = /*#__PURE__*/Object.freeze({
22205
22516
  __proto__: null,
22517
+ Errors: Errors,
22206
22518
  get Event () { return Event$1; },
22207
22519
  get ConnectionState () { return ConnectionState; },
22520
+ get ErrorType () { return ErrorType; },
22208
22521
  get RemoteTrackType () { return RemoteTrackType; },
22209
22522
  RoapMediaConnection: RoapMediaConnection,
22210
22523
  MediaRequest: MediaRequest,