@rive-app/webgl 2.14.1 → 2.14.3

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": "@rive-app/webgl",
3
- "version": "2.14.1",
3
+ "version": "2.14.3",
4
4
  "description": "Rive's webgl based web api.",
5
5
  "main": "rive.js",
6
6
  "homepage": "https://rive.app",
package/rive.d.ts CHANGED
@@ -117,7 +117,8 @@ export declare enum EventType {
117
117
  Draw = "draw",
118
118
  Advance = "advance",
119
119
  StateChange = "statechange",
120
- RiveEvent = "riveevent"
120
+ RiveEvent = "riveevent",
121
+ AudioStatusChange = "audiostatuschange"
121
122
  }
122
123
  export type RiveEventPayload = rc.RiveEvent | rc.OpenUrlEvent;
123
124
  export interface Event {
@@ -311,6 +312,7 @@ export declare class Rive {
311
312
  isTouchScrollEnabled: boolean;
312
313
  constructor(params: RiveParameters);
313
314
  static new(params: RiveParameters): Rive;
315
+ private onSystemAudioChanged;
314
316
  private init;
315
317
  /**
316
318
  * Setup Rive Listeners on the canvas
package/rive.js CHANGED
@@ -395,7 +395,7 @@ function Ra(a, b) {
395
395
  return Qa(c, a, b);
396
396
  }));
397
397
  }
398
- var E, F, Va = {688588:(a, b, c, d, e) => {
398
+ var E, F, Va = {688572:(a, b, c, d, e) => {
399
399
  if ("undefined" === typeof window || void 0 === (window.AudioContext || window.webkitAudioContext)) {
400
400
  return 0;
401
401
  }
@@ -458,9 +458,9 @@ var E, F, Va = {688588:(a, b, c, d, e) => {
458
458
  }
459
459
  window.h.Ea += 1;
460
460
  return 1;
461
- }, 690766:() => {
461
+ }, 690750:() => {
462
462
  "undefined" !== typeof window.h && (--window.h.Ea, 0 === window.h.Ea && delete window.h);
463
- }, 690930:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 691034:() => {
463
+ }, 690914:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 691018:() => {
464
464
  try {
465
465
  var a = new (window.AudioContext || window.webkitAudioContext)(), b = a.sampleRate;
466
466
  a.close();
@@ -468,7 +468,7 @@ var E, F, Va = {688588:(a, b, c, d, e) => {
468
468
  } catch (c) {
469
469
  return 0;
470
470
  }
471
- }, 691205:(a, b, c, d, e, f) => {
471
+ }, 691189:(a, b, c, d, e, f) => {
472
472
  if ("undefined" === typeof window.h) {
473
473
  return -1;
474
474
  }
@@ -514,7 +514,7 @@ var E, F, Va = {688588:(a, b, c, d, e) => {
514
514
  a == window.h.H.Da && g.Y.connect(g.I.destination);
515
515
  g.mb = f;
516
516
  return window.h.vc(g);
517
- }, 694082:a => window.h.ua(a).I.sampleRate, 694155:a => {
517
+ }, 694066:a => window.h.ua(a).I.sampleRate, 694139:a => {
518
518
  a = window.h.ua(a);
519
519
  void 0 !== a.Y && (a.Y.onaudioprocess = function() {
520
520
  }, a.Y.disconnect(), a.Y = void 0);
@@ -522,13 +522,13 @@ var E, F, Va = {688588:(a, b, c, d, e) => {
522
522
  a.I.close();
523
523
  a.I = void 0;
524
524
  a.mb = void 0;
525
- }, 694555:a => {
525
+ }, 694539:a => {
526
526
  window.h.yb(a);
527
- }, 694605:a => {
527
+ }, 694589:a => {
528
528
  a = window.h.ua(a);
529
529
  a.I.resume();
530
530
  a.state = window.h.ha.tb;
531
- }, 694744:a => {
531
+ }, 694728:a => {
532
532
  a = window.h.ua(a);
533
533
  a.I.suspend();
534
534
  a.state = window.h.ha.stopped;
@@ -3852,8 +3852,8 @@ m.dynCall_iiiij = (a, b, c, d, e, f) => (m.dynCall_iiiij = p.dynCall_iiiij)(a, b
3852
3852
  m.dynCall_viiij = (a, b, c, d, e, f) => (m.dynCall_viiij = p.dynCall_viiij)(a, b, c, d, e, f);
3853
3853
  m.dynCall_iiij = (a, b, c, d, e) => (m.dynCall_iiij = p.dynCall_iiij)(a, b, c, d, e);
3854
3854
  m.dynCall_viij = (a, b, c, d, e) => (m.dynCall_viij = p.dynCall_viij)(a, b, c, d, e);
3855
- m.dynCall_iiji = (a, b, c, d, e) => (m.dynCall_iiji = p.dynCall_iiji)(a, b, c, d, e);
3856
3855
  m.dynCall_iiiji = (a, b, c, d, e, f) => (m.dynCall_iiiji = p.dynCall_iiiji)(a, b, c, d, e, f);
3856
+ m.dynCall_iiji = (a, b, c, d, e) => (m.dynCall_iiji = p.dynCall_iiji)(a, b, c, d, e);
3857
3857
  m.dynCall_jiji = (a, b, c, d, e) => (m.dynCall_jiji = p.dynCall_jiji)(a, b, c, d, e);
3858
3858
  m.dynCall_iij = (a, b, c, d) => (m.dynCall_iij = p.dynCall_iij)(a, b, c, d);
3859
3859
  m.dynCall_jii = (a, b, c) => (m.dynCall_jii = p.dynCall_jii)(a, b, c);
@@ -4104,7 +4104,7 @@ Ie();
4104
4104
  /* 2 */
4105
4105
  /***/ ((module) => {
4106
4106
 
4107
- module.exports = JSON.parse('{"name":"@rive-app/webgl","version":"2.14.1","description":"Rive\'s webgl based web api.","main":"rive.js","homepage":"https://rive.app","repository":{"type":"git","url":"https://github.com/rive-app/rive-wasm/tree/master/js"},"keywords":["rive","animation"],"author":"Rive","contributors":["Luigi Rosso <luigi@rive.app> (https://rive.app)","Maxwell Talbot <max@rive.app> (https://rive.app)","Arthur Vivian <arthur@rive.app> (https://rive.app)","Umberto Sonnino <umberto@rive.app> (https://rive.app)","Matthew Sullivan <matt.j.sullivan@gmail.com> (mailto:matt.j.sullivan@gmail.com)"],"license":"MIT","files":["rive.js","rive.wasm","rive.js.map","rive.d.ts","rive_advanced.mjs.d.ts"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
4107
+ module.exports = JSON.parse('{"name":"@rive-app/webgl","version":"2.14.3","description":"Rive\'s webgl based web api.","main":"rive.js","homepage":"https://rive.app","repository":{"type":"git","url":"https://github.com/rive-app/rive-wasm/tree/master/js"},"keywords":["rive","animation"],"author":"Rive","contributors":["Luigi Rosso <luigi@rive.app> (https://rive.app)","Maxwell Talbot <max@rive.app> (https://rive.app)","Arthur Vivian <arthur@rive.app> (https://rive.app)","Umberto Sonnino <umberto@rive.app> (https://rive.app)","Matthew Sullivan <matt.j.sullivan@gmail.com> (mailto:matt.j.sullivan@gmail.com)"],"license":"MIT","files":["rive.js","rive.wasm","rive.js.map","rive.d.ts","rive_advanced.mjs.d.ts"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
4108
4108
 
4109
4109
  /***/ }),
4110
4110
  /* 3 */
@@ -4408,6 +4408,21 @@ __webpack_require__.r(__webpack_exports__);
4408
4408
  /* harmony import */ var _rive_advanced_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
4409
4409
  /* harmony import */ var package_json__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2);
4410
4410
  /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(3);
4411
+ var __extends = (undefined && undefined.__extends) || (function () {
4412
+ var extendStatics = function (d, b) {
4413
+ extendStatics = Object.setPrototypeOf ||
4414
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
4415
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
4416
+ return extendStatics(d, b);
4417
+ };
4418
+ return function (d, b) {
4419
+ if (typeof b !== "function" && b !== null)
4420
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
4421
+ extendStatics(d, b);
4422
+ function __() { this.constructor = d; }
4423
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
4424
+ };
4425
+ })();
4411
4426
  var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
4412
4427
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4413
4428
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -5251,6 +5266,7 @@ var EventType;
5251
5266
  EventType["Advance"] = "advance";
5252
5267
  EventType["StateChange"] = "statechange";
5253
5268
  EventType["RiveEvent"] = "riveevent";
5269
+ EventType["AudioStatusChange"] = "audiostatuschange";
5254
5270
  })(EventType || (EventType = {}));
5255
5271
  /**
5256
5272
  * Looping types: one-shot, loop, and ping-pong
@@ -5343,8 +5359,176 @@ var TaskQueueManager = /** @class */ (function () {
5343
5359
  };
5344
5360
  return TaskQueueManager;
5345
5361
  }());
5362
+ // #endregion
5363
+ // #region Audio
5364
+ var SystemAudioStatus;
5365
+ (function (SystemAudioStatus) {
5366
+ SystemAudioStatus[SystemAudioStatus["AVAILABLE"] = 0] = "AVAILABLE";
5367
+ SystemAudioStatus[SystemAudioStatus["UNAVAILABLE"] = 1] = "UNAVAILABLE";
5368
+ })(SystemAudioStatus || (SystemAudioStatus = {}));
5369
+ // Class to handle audio context availability and status changes
5370
+ var AudioManager = /** @class */ (function (_super) {
5371
+ __extends(AudioManager, _super);
5372
+ function AudioManager() {
5373
+ var _this = _super !== null && _super.apply(this, arguments) || this;
5374
+ _this._started = false;
5375
+ _this._enabled = false;
5376
+ _this._status = SystemAudioStatus.UNAVAILABLE;
5377
+ return _this;
5378
+ }
5379
+ AudioManager.prototype.delay = function (time) {
5380
+ return __awaiter(this, void 0, void 0, function () {
5381
+ return __generator(this, function (_a) {
5382
+ return [2 /*return*/, new Promise(function (resolve) { return setTimeout(resolve, time); })];
5383
+ });
5384
+ });
5385
+ };
5386
+ AudioManager.prototype.timeout = function () {
5387
+ return __awaiter(this, void 0, void 0, function () {
5388
+ return __generator(this, function (_a) {
5389
+ return [2 /*return*/, new Promise(function (_, reject) { return setTimeout(reject, 50); })];
5390
+ });
5391
+ });
5392
+ };
5393
+ // Alerts animations on status changes and removes the listeners to avoid alerting twice.
5394
+ AudioManager.prototype.reportToListeners = function () {
5395
+ this.fire({ type: EventType.AudioStatusChange });
5396
+ this.removeAll();
5397
+ };
5398
+ /**
5399
+ * The audio context has been resolved.
5400
+ * Alert any listeners that we can now play audio.
5401
+ * Rive will now play audio at the configured volume.
5402
+ */
5403
+ AudioManager.prototype.enableAudio = function () {
5404
+ return __awaiter(this, void 0, void 0, function () {
5405
+ return __generator(this, function (_a) {
5406
+ if (!this._enabled) {
5407
+ this._enabled = true;
5408
+ this._status = SystemAudioStatus.AVAILABLE;
5409
+ this.reportToListeners();
5410
+ }
5411
+ return [2 /*return*/];
5412
+ });
5413
+ });
5414
+ };
5415
+ /**
5416
+ * Check if we are able to play audio.
5417
+ *
5418
+ * We currently check the audio context, when resume() returns before a timeout we know that the
5419
+ * audio context is running and we can enable audio.
5420
+ */
5421
+ AudioManager.prototype.testAudio = function () {
5422
+ return __awaiter(this, void 0, void 0, function () {
5423
+ var _a;
5424
+ return __generator(this, function (_b) {
5425
+ switch (_b.label) {
5426
+ case 0:
5427
+ if (!(this._status === SystemAudioStatus.UNAVAILABLE &&
5428
+ this._audioContext !== null)) return [3 /*break*/, 4];
5429
+ _b.label = 1;
5430
+ case 1:
5431
+ _b.trys.push([1, 3, , 4]);
5432
+ return [4 /*yield*/, Promise.race([this._audioContext.resume(), this.timeout()])];
5433
+ case 2:
5434
+ _b.sent();
5435
+ this.enableAudio();
5436
+ return [3 /*break*/, 4];
5437
+ case 3:
5438
+ _a = _b.sent();
5439
+ return [3 /*break*/, 4];
5440
+ case 4: return [2 /*return*/];
5441
+ }
5442
+ });
5443
+ });
5444
+ };
5445
+ /**
5446
+ * Establish audio for use with rive.
5447
+ * We both test if we can use audio intermittently and listen for user interaction.
5448
+ * The aim is to enable audio playback as soon as the browser allows this.
5449
+ */
5450
+ AudioManager.prototype._establishAudio = function () {
5451
+ return __awaiter(this, void 0, void 0, function () {
5452
+ return __generator(this, function (_a) {
5453
+ switch (_a.label) {
5454
+ case 0:
5455
+ if (!!this._started) return [3 /*break*/, 5];
5456
+ this._started = true;
5457
+ if (!(typeof window == "undefined")) return [3 /*break*/, 1];
5458
+ this.enableAudio();
5459
+ return [3 /*break*/, 5];
5460
+ case 1:
5461
+ this._audioContext = new AudioContext();
5462
+ this.listenForUserAction();
5463
+ _a.label = 2;
5464
+ case 2:
5465
+ if (!(this._status === SystemAudioStatus.UNAVAILABLE)) return [3 /*break*/, 5];
5466
+ return [4 /*yield*/, this.testAudio()];
5467
+ case 3:
5468
+ _a.sent();
5469
+ return [4 /*yield*/, this.delay(1000)];
5470
+ case 4:
5471
+ _a.sent();
5472
+ return [3 /*break*/, 2];
5473
+ case 5: return [2 /*return*/];
5474
+ }
5475
+ });
5476
+ });
5477
+ };
5478
+ AudioManager.prototype.listenForUserAction = function () {
5479
+ var _this = this;
5480
+ // NOTE: AudioContexts are ready immediately if requested in a ui callback
5481
+ // we *could* re request one in this listener.
5482
+ var _clickListener = function () { return __awaiter(_this, void 0, void 0, function () {
5483
+ return __generator(this, function (_a) {
5484
+ // note this has "better" results than calling `await this.testAudio()`
5485
+ // as we force audio to be enabled in the current thread, rather than chancing
5486
+ // the thread to be passed over for some other async context
5487
+ this.enableAudio();
5488
+ return [2 /*return*/];
5489
+ });
5490
+ }); };
5491
+ // NOTE: we should test this on mobile/pads
5492
+ document.addEventListener("pointerdown", _clickListener, {
5493
+ once: true,
5494
+ });
5495
+ };
5496
+ /**
5497
+ * Establish the audio context for rive, this lets rive know that we can play audio.
5498
+ */
5499
+ AudioManager.prototype.establishAudio = function () {
5500
+ return __awaiter(this, void 0, void 0, function () {
5501
+ return __generator(this, function (_a) {
5502
+ this._establishAudio();
5503
+ return [2 /*return*/];
5504
+ });
5505
+ });
5506
+ };
5507
+ Object.defineProperty(AudioManager.prototype, "systemVolume", {
5508
+ get: function () {
5509
+ if (this._status === SystemAudioStatus.UNAVAILABLE) {
5510
+ // We do an immediate test to avoid depending on the delay of the running test
5511
+ this.testAudio();
5512
+ return 0;
5513
+ }
5514
+ return 1;
5515
+ },
5516
+ enumerable: false,
5517
+ configurable: true
5518
+ });
5519
+ Object.defineProperty(AudioManager.prototype, "status", {
5520
+ get: function () {
5521
+ return this._status;
5522
+ },
5523
+ enumerable: false,
5524
+ configurable: true
5525
+ });
5526
+ return AudioManager;
5527
+ }(EventManager));
5528
+ var audioManager = new AudioManager();
5346
5529
  var Rive = /** @class */ (function () {
5347
5530
  function Rive(params) {
5531
+ var _this = this;
5348
5532
  var _a;
5349
5533
  // Tracks if a Rive file is loaded
5350
5534
  this.loaded = false;
@@ -5429,6 +5613,14 @@ var Rive = /** @class */ (function () {
5429
5613
  this.assetLoader = params.assetLoader;
5430
5614
  // Hook up the task queue
5431
5615
  this.taskQueue = new TaskQueueManager(this.eventManager);
5616
+ // Initialize audio
5617
+ if (audioManager.status == SystemAudioStatus.UNAVAILABLE) {
5618
+ audioManager.add({
5619
+ type: EventType.AudioStatusChange,
5620
+ callback: function () { return _this.onSystemAudioChanged(); },
5621
+ });
5622
+ audioManager.establishAudio();
5623
+ }
5432
5624
  this.init({
5433
5625
  src: this.src,
5434
5626
  buffer: this.buffer,
@@ -5444,6 +5636,10 @@ var Rive = /** @class */ (function () {
5444
5636
  console.warn("This function is deprecated: please use `new Rive({})` instead");
5445
5637
  return new Rive(params);
5446
5638
  };
5639
+ // Event handler for when audio context becomes available
5640
+ Rive.prototype.onSystemAudioChanged = function () {
5641
+ this.volume = this._volume;
5642
+ };
5447
5643
  // Initializes the Rive object either from constructor or load()
5448
5644
  Rive.prototype.init = function (_a) {
5449
5645
  var _this = this;
@@ -5587,7 +5783,7 @@ var Rive = /** @class */ (function () {
5587
5783
  return;
5588
5784
  }
5589
5785
  this.artboard = rootArtboard;
5590
- rootArtboard.volume = this._volume;
5786
+ rootArtboard.volume = this._volume * audioManager.systemVolume;
5591
5787
  // Check that the artboard has at least 1 animation
5592
5788
  if (this.artboard.animationCount() < 1) {
5593
5789
  var msg = "Artboard has no animations";
@@ -6328,7 +6524,7 @@ var Rive = /** @class */ (function () {
6328
6524
  set: function (value) {
6329
6525
  this._volume = value;
6330
6526
  if (this.artboard) {
6331
- this.artboard.volume = value;
6527
+ this.artboard.volume = value * audioManager.systemVolume;
6332
6528
  }
6333
6529
  },
6334
6530
  enumerable: false,