Skip to content

Commit 67b411c

Browse files
authored
Merge pull request #175 from SpringRoll/release/2.5.0
Release/2.5.0
2 parents d3e0040 + b4140ce commit 67b411c

16 files changed

+106
-5627
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717

1818
strategy:
1919
matrix:
20-
node-version: [14.x, 16.x, 18.x]
20+
node-version: [16.x, 18.x, 20.x]
2121

2222
steps:
2323
- uses: actions/checkout@v1

.github/workflows/npm-deploy.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- uses: actions/checkout@v1
1313
- uses: actions/setup-node@v1
1414
with:
15-
node-version: 16
15+
node-version: 18
1616
registry-url: https://registry.npmjs.org/
1717

1818
- name: install

.nvmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v16.19.1
1+
v18.15.0

CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [2.5.0] - 2023-02-21
9+
10+
### Changed
11+
12+
- Prevent SoundPlugin from sending mute state before Application is loaded.
13+
- Prevent CaptionsTogglePlugin from sending mute state before Application is loaded.
14+
- updated .nvmrc to 18
15+
16+
### Added
17+
18+
- Added a check to make sure plugin preloads are finished before opening up the application to avoid race conditions.
19+
820
## [2.4.6] - 2023-10-16
921

1022
### Fixed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,6 @@ There is no configuration required for the UserDataPlugin as it just handles req
678678

679679
## License
680680

681-
Copyright (c) 2022 [SpringRoll](http://github.com/SpringRoll)
681+
Copyright (c) 2024 [SpringRoll](http://github.com/SpringRoll)
682682

683683
Released under the MIT License.

dist/SpringRoll-Container-umd.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/SpringRoll-Container-umd.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

+25-5,592
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "springroll-container",
3-
"version": "2.4.6",
3+
"version": "2.5.0",
44
"description": "The iframe controller for interacting with SpringRoll applications",
55
"main": "./dist/index.js",
66
"license": "MIT",

src/Container.js

+10
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export class Container extends PluginManager {
2828
super({ plugins });
2929

3030
this.iframe = iframeOrSelector instanceof HTMLIFrameElement ? iframeOrSelector : document.querySelector(iframeOrSelector);
31+
this.iframe.style.backgroundColor = 'black';
3132

3233
if (null === this.iframe) {
3334
throw new Error('No iframe was found with the provided selector');
@@ -141,6 +142,15 @@ export class Container extends PluginManager {
141142
* @memberof Container
142143
*/
143144
_internalOpen(userPath, { singlePlay = false, playOptions = null } = {}) {
145+
// If plugin preloads are still going wait for them to finish before opening the Application
146+
if (this.preloading) {
147+
this.client.on('preloadsFinished', () => {
148+
this._internalOpen(userPath, { singlePlay, playOptions });
149+
});
150+
151+
return;
152+
}
153+
144154
const options = { singlePlay, playOptions };
145155
this.reset();
146156

src/PluginManager.js

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default class PluginManager {
1515
*/
1616
constructor({ plugins = [] }) {
1717
this.client = new Bellhop();
18+
this.preloading = true;
1819
// @ts-ignore
1920
this.client.hidden = this.client.receive.bind(this.client);
2021
// @ts-ignore
@@ -57,6 +58,9 @@ export default class PluginManager {
5758
plugin => plugin.preloadFailed !== true
5859
);
5960

61+
this.preloading = false;
62+
this.client.trigger('preloadsFinished');
63+
6064
//init
6165
this.plugins.forEach(plugin => {
6266
if (!plugin.init) {

src/base-plugins/ButtonPlugin.js

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export class ButtonPlugin extends BasePlugin {
6262
* @memberof ButtonPlugin
6363
*/
6464
_setMuteProp(prop, button, muted, disableSend = false) {
65+
console.log('_setmuteprop', prop, muted, disableSend);
6566
if (Array.isArray(button)) {
6667
button.forEach(b => this.changeMutedState(b, muted));
6768
} else {

src/plugins/CaptionsTogglePlugin.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ export class CaptionsTogglePlugin extends ButtonPlugin {
6565
return;
6666
}
6767

68-
this.captionsMuted = !!SavedData.read(CaptionsTogglePlugin.captionsToggleKey);
68+
const captionsMuted = !!SavedData.read(CaptionsTogglePlugin.captionsToggleKey);
69+
70+
this._setMuteProp('captionsMuted', captionsMuted, this._captionsButtons, true);
6971

7072
}.bind(this)
7173
);
@@ -74,8 +76,9 @@ export class CaptionsTogglePlugin extends ButtonPlugin {
7476
* @memberof CaptionsTogglePlugin
7577
*/
7678
start() {
77-
this.captionsMuted = !!SavedData.read(CaptionsTogglePlugin.captionsToggleKey);
78-
79+
for (let i = 0; i < this.captionsButtonsLength; i++) {
80+
this.captionsButtons[i].enableButton();
81+
}
7982
this.client.on('loaded', this.sendAllProperties);
8083
this.client.on('loadDone', this.sendAllProperties);
8184
}

src/plugins/SoundPlugin.js

+39-23
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ export class SoundPlugin extends ButtonPlugin {
4444
this._sfxMutedByUser = false;
4545
this._voMutedByUser = false;
4646

47-
this.soundMuteEnabled = false;
48-
this.musicMuteEnabled = false;
49-
this.sfxMuteEnabled = false;
50-
this.voMuteEnabled = false;
47+
this.soundMutedEnabled = false;
48+
this.musicMutedEnabled = false;
49+
this.sfxMutedEnabled = false;
50+
this.voMutedEnabled = false;
5151

5252
this.soundVolume = 1;
5353
this.musicVolume = 1;
@@ -401,7 +401,8 @@ export class SoundPlugin extends ButtonPlugin {
401401
/**
402402
* @memberof SoundPlugin
403403
*/
404-
init() {
404+
async preload({ client }) {
405+
this.client = client;
405406
this.client.on(
406407
'features',
407408
function(features) {
@@ -410,10 +411,10 @@ export class SoundPlugin extends ButtonPlugin {
410411
}
411412

412413
// Confirm that the mute features are supported
413-
this.soundMuteEnabled = !!features.data.sound;
414-
this.musicMuteEnabled = !!features.data.music;
415-
this.sfxMuteEnabled = !!features.data.sfx;
416-
this.voMuteEnabled = !!features.data.vo;
414+
this.soundMutedEnabled = !!features.data.sound;
415+
this.musicMutedEnabled = !!features.data.music;
416+
this.sfxMutedEnabled = !!features.data.sfx;
417+
this.voMutedEnabled = !!features.data.vo;
417418

418419
this.soundVolumeEnabled = !!features.data.soundVolume;
419420
this.musicVolumeEnabled = !!features.data.musicVolume;
@@ -444,6 +445,18 @@ export class SoundPlugin extends ButtonPlugin {
444445
for (let i = 0; i < this.voSlidersLength; i++) {
445446
this.voSliders[i].displaySlider(features.data);
446447
}
448+
449+
const soundMuted = !!SavedData.read(SoundPlugin.soundMutedKey);
450+
const musicMuted = !!SavedData.read(SoundPlugin.musicMutedKey);
451+
const sfxMuted = !!SavedData.read(SoundPlugin.sfxMutedKey);
452+
const voMuted = !!SavedData.read(SoundPlugin.voMutedKey);
453+
454+
// set the property in case buttons exist but disable the send here
455+
// properties will be sent in sendAllProperties
456+
this.setMuteProp('soundMuted', soundMuted, this.soundButtons, true);
457+
this.setMuteProp('musicMuted', musicMuted, this.musicButtons, true);
458+
this.setMuteProp('sfxMuted', sfxMuted, this.sfxButtons, true);
459+
this.setMuteProp('voMuted', voMuted, this.voButtons, true);
447460
}.bind(this)
448461
);
449462
}
@@ -452,7 +465,6 @@ export class SoundPlugin extends ButtonPlugin {
452465
* @memberof SoundPlugin
453466
*/
454467
start() {
455-
456468
for (let i = 0; i < this.soundButtonsLength; i++) {
457469
this.soundButtons[i].enableButton();
458470
}
@@ -466,11 +478,6 @@ export class SoundPlugin extends ButtonPlugin {
466478
this.voButtons[i].enableButton();
467479
}
468480

469-
this.soundMuted = !!SavedData.read(SoundPlugin.soundMutedKey);
470-
this.musicMuted = !!SavedData.read(SoundPlugin.musicMutedKey);
471-
this.sfxMuted = !!SavedData.read(SoundPlugin.sfxMutedKey);
472-
this.voMuted = !!SavedData.read(SoundPlugin.voMutedKey);
473-
474481
this.client.on('loaded', this.sendAllProperties);
475482
this.client.on('loadDone', this.sendAllProperties);
476483
}
@@ -481,23 +488,32 @@ export class SoundPlugin extends ButtonPlugin {
481488
* @memberof SoundPlugin
482489
*/
483490
sendAllProperties() {
484-
this.sendProperty(SoundPlugin.soundVolumeKey, this.soundVolume);
485-
this.sendProperty(SoundPlugin.musicVolumeKey, this.musicVolume);
486-
this.sendProperty(SoundPlugin.voVolumeKey, this.voVolume);
487-
this.sendProperty(SoundPlugin.sfxVolumeKey, this.sfxVolume);
491+
492+
if ( this.soundVolumeEnabled && this.soundSlidersLength > 0 ) {
493+
this.sendProperty(SoundPlugin.soundVolumeKey, this.soundVolume);
494+
}
495+
if ( this.musicVolumeEnabled && this.musicSlidersLength > 0 ) {
496+
this.sendProperty(SoundPlugin.musicVolumeKey, this.musicVolume);
497+
}
498+
if ( this.voVolumeEnabled && this.voSlidersLength > 0 ) {
499+
this.sendProperty(SoundPlugin.voVolumeKey, this.voVolume);
500+
}
501+
if ( this.sfxVolumeEnabled && this.sfxSlidersLength > 0 ) {
502+
this.sendProperty(SoundPlugin.sfxVolumeKey, this.sfxVolume);
503+
}
488504

489505
// to avoid the mute property overwriting the volume on startup, mutes should only send if they're true
490506
// or the volume channel isn't enabled
491-
if ( this.soundMuteEnabled && (this.soundMuted || !this.soundVolumeEnabled )) {
507+
if ( (this.soundButtonsLength > 0 && this.soundMutedEnabled) && (this.soundMuted || !this.soundVolumeEnabled )) {
492508
this.sendProperty(SoundPlugin.soundMutedKey, this.soundMuted);
493509
}
494-
if ( this.musicMuteEnabled && (this.musicMuted || !this.musicVolumeEnabled )) {
510+
if ( (this.musicButtonsLength > 0 && this.musicMutedEnabled) && (this.musicMuted || !this.musicVolumeEnabled )) {
495511
this.sendProperty(SoundPlugin.musicMutedKey, this.musicMuted);
496512
}
497-
if ( this.voMuteEnabled && ( this.voMuted || !this.voVolumeEnabled )) {
513+
if ( (this.voButtonsLength > 0 && this.voMutedEnabled) && ( this.voMuted || !this.voVolumeEnabled )) {
498514
this.sendProperty(SoundPlugin.voMutedKey, this.voMuted);
499515
}
500-
if ( this.sfxMuteEnabled && (this.sfxMuted || !this.sfxVolumeEnabled )) {
516+
if ( (this.sfxButtonsLength > 0 && this.sfxMutedEnabled) && (this.sfxMuted || !this.sfxVolumeEnabled )) {
501517
this.sendProperty(SoundPlugin.sfxMutedKey, this.sfxMuted);
502518
}
503519
}

0 commit comments

Comments
 (0)