@vpmedia/phaser 1.0.6 → 1.0.8

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": "@vpmedia/phaser",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "@vpmedia/phaser is the modern ECMAScript port of the popular Phaser game engine v2.6.2",
5
5
  "author": "Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)",
6
6
  "license": "MIT",
@@ -137,7 +137,6 @@ export default class {
137
137
  data,
138
138
  isDecoding: false,
139
139
  decoded: false,
140
- webAudio: true,
141
140
  locked: this.game.sound.touchLocked,
142
141
  };
143
142
  this._resolveURL(url, this._cache.sound[key]);
@@ -33,7 +33,6 @@ export default class {
33
33
  this.safariVersion = 0;
34
34
  this.webApp = false;
35
35
  this.silk = false;
36
- this.webAudio = false;
37
36
  this.ogg = false;
38
37
  this.opus = false;
39
38
  this.mp3 = false;
@@ -232,7 +232,6 @@ export function checkVideo(device) {
232
232
  * @param {object} device TBD
233
233
  */
234
234
  export function checkAudio(device) {
235
- device.webAudio = !!(window.AudioContext || window.webkitAudioContext);
236
235
  const audioElement = document.createElement('audio');
237
236
  try {
238
237
  if (audioElement.canPlayType) {
@@ -211,6 +211,8 @@ export default class {
211
211
  this.parseConfigElement(config, 'clearBeforeRender', true);
212
212
  // The Renderer this game will use. Either PowerGamer.Const.RENDER_AUTO, PowerGamer.Const.RENDER_CANVAS, PowerGamer.Const.RENDER_WEBGL, or PowerGamer.Const.RENDER_HEADLESS.
213
213
  this.parseConfigElement(config, 'renderType', RENDER_AUTO);
214
+ // Force audio disabled
215
+ this.parseConfigElement(config, 'isForceDisabledAudio', false);
214
216
  if (config.renderer) {
215
217
  this.config.renderType = config.renderer;
216
218
  }
@@ -34,14 +34,13 @@ export default class {
34
34
  this.pendingPlayback = false;
35
35
  this.override = false;
36
36
  this.allowMultiple = false;
37
- this.usingWebAudio = this.game.sound.usingWebAudio;
38
37
  this.externalNode = null;
39
38
  this.masterGainNode = null;
40
39
  this.gainNode = null;
41
40
  this._sound = null;
42
41
  this._markedToDelete = false;
43
42
  this._removeFromSoundManager = false;
44
- if (this.usingWebAudio) {
43
+ if (!this.game.sound.noAudio) {
45
44
  this.context = this.game.sound.context;
46
45
  this.masterGainNode = this.game.sound.masterGain;
47
46
  if (this.context.createGain === undefined) {
@@ -147,7 +146,7 @@ export default class {
147
146
  }
148
147
  this.currentTime = this.game.time.time - this.startTime;
149
148
  if (this.currentTime >= this.durationMS) {
150
- if (this.usingWebAudio) {
149
+ if (!this.game.sound.noAudio) {
151
150
  if (this.loop) {
152
151
  // won't work with markers, needs to reset the position
153
152
  this.onLoop.dispatch(this);
@@ -193,7 +192,7 @@ export default class {
193
192
  return this;
194
193
  }
195
194
  if (this._sound && this.isPlaying && !this.allowMultiple && (this.override || forceRestart)) {
196
- if (this.usingWebAudio) {
195
+ if (!this.game.sound.noAudio) {
197
196
  if (this._sound.stop === undefined) {
198
197
  this._sound.noteOff(0);
199
198
  } else {
@@ -253,7 +252,7 @@ export default class {
253
252
  this._tempVolume = volume;
254
253
  this._tempLoop = loop;
255
254
  }
256
- if (this.usingWebAudio) {
255
+ if (!this.game.sound.noAudio) {
257
256
  // Does the sound need decoding?
258
257
  if (this.game.cache.isSoundDecoded(this.key)) {
259
258
  this._sound = this.context.createBufferSource();
@@ -340,7 +339,7 @@ export default class {
340
339
 
341
340
  resume() {
342
341
  if (this.paused && this._sound) {
343
- if (this.usingWebAudio) {
342
+ if (!this.game.sound.noAudio) {
344
343
  const p = Math.max(0, this.position + (this.pausedPosition / 1000));
345
344
  this._sound = this.context.createBufferSource();
346
345
  this._sound.buffer = this._buffer;
@@ -369,9 +368,6 @@ export default class {
369
368
  } else {
370
369
  this._sound.start(0, p, duration);
371
370
  }
372
- } else {
373
- this._sound.currentTime = this._tempPause;
374
- this._sound.play();
375
371
  }
376
372
  this.isPlaying = true;
377
373
  this.paused = false;
@@ -382,7 +378,7 @@ export default class {
382
378
 
383
379
  stop() {
384
380
  if (this.isPlaying && this._sound) {
385
- if (this.usingWebAudio) {
381
+ if (!this.game.sound.noAudio) {
386
382
  if (this._sound.stop === undefined) {
387
383
  this._sound.noteOff(0);
388
384
  } else {
@@ -475,12 +471,12 @@ export default class {
475
471
  if (value) {
476
472
  this._muted = true;
477
473
  this._muteVolume = this._tempVolume;
478
- if (this.usingWebAudio) {
474
+ if (!this.game.sound.noAudio) {
479
475
  this.gainNode.gain.value = 0;
480
476
  }
481
477
  } else {
482
478
  this._muted = false;
483
- if (this.usingWebAudio) {
479
+ if (!this.game.sound.noAudio) {
484
480
  this.gainNode.gain.value = this._muteVolume;
485
481
  }
486
482
  }
@@ -498,7 +494,7 @@ export default class {
498
494
  }
499
495
  this._tempVolume = value;
500
496
  this._volume = value;
501
- if (this.usingWebAudio) {
497
+ if (!this.game.sound.noAudio) {
502
498
  this.gainNode.gain.value = value;
503
499
  }
504
500
  }
@@ -17,7 +17,6 @@ export default class {
17
17
  this.onUnMute = new Signal();
18
18
  this.context = null;
19
19
  this.baseLatency = 0; // https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/baseLatency
20
- this.usingWebAudio = false;
21
20
  this.noAudio = false;
22
21
  this.connectToMaster = true;
23
22
  this.touchLocked = false;
@@ -34,6 +33,10 @@ export default class {
34
33
  }
35
34
 
36
35
  boot() {
36
+ if (this.game.config.isForceDisabledAudio) {
37
+ this.noAudio = true;
38
+ return;
39
+ }
37
40
  if (window.PhaserRegistry && window.PhaserRegistry.audioContext) {
38
41
  this.context = window.PhaserRegistry.audioContext;
39
42
  } else if (window.AudioContext) {
@@ -41,22 +44,23 @@ export default class {
41
44
  this.context = new window.AudioContext();
42
45
  } catch (e) {
43
46
  this.context = null;
44
- this.usingWebAudio = false;
47
+ this.noAudio = true;
45
48
  this.touchLocked = false;
49
+ this.game.exceptionHandler(e);
46
50
  }
47
51
  } else if (window.webkitAudioContext) {
48
52
  try {
49
53
  this.context = new window.webkitAudioContext();
50
54
  } catch (e) {
51
55
  this.context = null;
52
- this.usingWebAudio = false;
56
+ this.noAudio = true;
53
57
  this.touchLocked = false;
58
+ this.game.exceptionHandler(e);
54
59
  }
55
60
  }
56
61
  if (this.context === null || (this.context && this.context.createGain === undefined && this.context.createGainNode === undefined)) {
57
62
  this.noAudio = true;
58
63
  } else {
59
- this.usingWebAudio = true;
60
64
  this.baseLatency = this.context.baseLatency || (256 / (this.context.sampleRate || 44100));
61
65
  if (this.context.createGain === undefined) {
62
66
  this.masterGain = this.context.createGainNode();
@@ -66,22 +70,31 @@ export default class {
66
70
  this.masterGain.gain.value = 1;
67
71
  this.masterGain.connect(this.context.destination);
68
72
  }
69
- if (this.usingWebAudio && (this.game.device.iOS || this.game.device.android)) {
73
+ if (this.noAudio) {
74
+ return;
75
+ }
76
+ if (this.game.device.iOS || this.game.device.android) {
70
77
  this.game.input.addTouchLockCallback(this.unlock, this, true);
71
78
  this.touchLocked = true;
72
79
  }
73
80
  }
74
81
 
75
82
  checkContextState() {
76
- if (this.usingWebAudio && this.context.state === 'suspended') {
77
- this.game.input.onUp.addOnce(this.resumeWebAudio, this);
83
+ if (this.noAudio) {
84
+ return false;
85
+ }
86
+ if (this.context.state === 'suspended') {
87
+ this.game.input.onUp.addOnce(this.resumeAudioContext, this);
78
88
  return true;
79
89
  }
80
90
  return false;
81
91
  }
82
92
 
83
- resumeWebAudio() {
84
- if (this.usingWebAudio && this.context.state === 'suspended') {
93
+ resumeAudioContext() {
94
+ if (this.noAudio) {
95
+ return;
96
+ }
97
+ if (this.context.state === 'suspended') {
85
98
  this.context.resume();
86
99
  }
87
100
  }
@@ -101,7 +114,7 @@ export default class {
101
114
  } else {
102
115
  this._unlockSource.start(0);
103
116
  }
104
- this.resumeWebAudio();
117
+ this.resumeAudioContext();
105
118
  return true;
106
119
  }
107
120
 
@@ -190,8 +203,8 @@ export default class {
190
203
  if (this.touchLocked && this._unlockSource !== null && (this._unlockSource.playbackState === this._unlockSource.PLAYING_STATE || this._unlockSource.playbackState === this._unlockSource.FINISHED_STATE)) {
191
204
  this.touchLocked = false;
192
205
  this._unlockSource = null;
193
- this.resumeWebAudio();
194
- } else if (this.usingWebAudio && this.context.state === 'interrupted') {
206
+ this.resumeAudioContext();
207
+ } else if (this.context.state === 'interrupted') {
195
208
  this.context.resume();
196
209
  }
197
210
  for (let i = 0; i < this._sounds.length; i += 1) {
@@ -259,7 +272,7 @@ export default class {
259
272
  return;
260
273
  }
261
274
  this._muted = true;
262
- if (this.usingWebAudio) {
275
+ if (!this.noAudio) {
263
276
  this._muteVolume = this.masterGain.gain.value;
264
277
  this.masterGain.gain.value = 0;
265
278
  }
@@ -271,7 +284,7 @@ export default class {
271
284
  return;
272
285
  }
273
286
  this._muted = false;
274
- if (this.usingWebAudio) {
287
+ if (!this.noAudio) {
275
288
  this.masterGain.gain.value = this._muteVolume;
276
289
  }
277
290
  this.onUnMute.dispatch();
@@ -327,7 +340,7 @@ export default class {
327
340
  }
328
341
  if (this._volume !== value) {
329
342
  this._volume = value;
330
- if (this.usingWebAudio) {
343
+ if (!this.noAudio) {
331
344
  this.masterGain.gain.value = value;
332
345
  }
333
346
  this.onVolumeChange.dispatch(value);