bigscreen-player
Advanced tools
Comparing version 3.13.3 to 3.14.0
{ | ||
"name": "bigscreen-player", | ||
"version": "3.13.3", | ||
"version": "3.14.0", | ||
"description": "Simplified media playback for bigscreen devices.", | ||
@@ -5,0 +5,0 @@ "main": "script/bigscreenplayer.js", |
@@ -145,2 +145,19 @@ # Bigscreen Player | ||
### Reacting to subtitles being turned on/off | ||
This is emitted on every `setSubtitlesEnabled` call. The emitted object contains an `enabled` property. | ||
This may be registered for before initialisation and will automatically be cleared upon `tearDown()` of the player. | ||
```javascript | ||
var bigscreenPlayer = BigscreenPlayer(); | ||
// The token is only required in the case where the function is anonymous, a reference to the function can be stored and used to unregister otherwise. | ||
var subtitleChangeToken = bigscreenPlayer.registerForSubtitleChanges(function (event) { | ||
console.log('Subttiles enabled: ' + event.enabled); | ||
}); | ||
bigscreenPlayer.unregisterForSubtitleChanges(subtitleChangeToken); | ||
``` | ||
### Creating a plugin | ||
@@ -147,0 +164,0 @@ |
@@ -407,2 +407,83 @@ require( | ||
describe('registerForSubtitleChanges', function () { | ||
it('should call the callback when we subtitles are turned on/off', function () { | ||
var callback = jasmine.createSpy('listener1'); | ||
initialiseBigscreenPlayer(); | ||
bigscreenPlayer.registerForSubtitleChanges(callback); | ||
expect(callback).not.toHaveBeenCalled(); | ||
bigscreenPlayer.setSubtitlesEnabled(true); | ||
expect(callback).toHaveBeenCalledWith({enabled: true}); | ||
bigscreenPlayer.setSubtitlesEnabled(false); | ||
expect(callback).toHaveBeenCalledWith({enabled: false}); | ||
}); | ||
it('should call the callback when init() is called with subtitles enabled', function () { | ||
var callback = jasmine.createSpy('listener1'); | ||
bigscreenPlayer.registerForSubtitleChanges(callback); | ||
initialiseBigscreenPlayer({ subtitlesEnabled: true }); | ||
expect(callback).toHaveBeenCalledWith({enabled: true}); | ||
}); | ||
it('should not call the callback when init() is called without subtitles enabled', function () { | ||
var callback = jasmine.createSpy('listener1'); | ||
bigscreenPlayer.registerForSubtitleChanges(callback); | ||
initialiseBigscreenPlayer(); | ||
expect(callback).not.toHaveBeenCalled(); | ||
}); | ||
it('returns a reference to the callback passed in', function () { | ||
var callback = jasmine.createSpy(); | ||
var reference = bigscreenPlayer.registerForSubtitleChanges(callback); | ||
expect(reference).toBe(callback); | ||
}); | ||
}); | ||
describe('unregisterForSubtitleChanges', function () { | ||
it('should remove callback from subtitleCallbacks', function () { | ||
initialiseBigscreenPlayer(); | ||
var listener1 = jasmine.createSpy('listener1'); | ||
var listener2 = jasmine.createSpy('listener2'); | ||
var listener3 = jasmine.createSpy('listener3'); | ||
bigscreenPlayer.registerForSubtitleChanges(listener1); | ||
bigscreenPlayer.registerForSubtitleChanges(listener2); | ||
bigscreenPlayer.registerForSubtitleChanges(listener3); | ||
bigscreenPlayer.setSubtitlesEnabled(true); | ||
bigscreenPlayer.unregisterForSubtitleChanges(listener2); | ||
bigscreenPlayer.setSubtitlesEnabled(false); | ||
expect(listener1).toHaveBeenCalledTimes(2); | ||
expect(listener2).toHaveBeenCalledTimes(1); | ||
expect(listener3).toHaveBeenCalledTimes(2); | ||
}); | ||
it('should only remove existing callbacks from subtitleCallbacks', function () { | ||
initialiseBigscreenPlayer(); | ||
var listener1 = jasmine.createSpy('listener1'); | ||
var listener2 = jasmine.createSpy('listener2'); | ||
bigscreenPlayer.registerForSubtitleChanges(listener1); | ||
bigscreenPlayer.unregisterForSubtitleChanges(listener2); | ||
bigscreenPlayer.setSubtitlesEnabled(true); | ||
expect(listener1).toHaveBeenCalledWith({enabled: true}); | ||
}); | ||
}); | ||
describe('setCurrentTime', function () { | ||
@@ -409,0 +490,0 @@ it('should setCurrentTime on the strategy/playerComponent', function () { |
@@ -21,2 +21,3 @@ define('bigscreenplayer/bigscreenplayer', | ||
var timeUpdateCallbacks = []; | ||
var subtitleCallbacks = []; | ||
@@ -118,2 +119,6 @@ var mediaKind; | ||
if (enableSubtitles) { | ||
callSubtitlesCallbacks(true); | ||
} | ||
if (successCallback) { | ||
@@ -138,2 +143,8 @@ successCallback(); | ||
function callSubtitlesCallbacks (enabled) { | ||
subtitleCallbacks.forEach(function (callback) { | ||
callback({ enabled: enabled }); | ||
}); | ||
} | ||
return { | ||
@@ -173,2 +184,3 @@ init: function (playbackElement, bigscreenPlayerData, newWindowType, enableSubtitles, newDevice, callbacks) { | ||
timeUpdateCallbacks = []; | ||
subtitleCallbacks = []; | ||
endOfStream = undefined; | ||
@@ -205,2 +217,12 @@ mediaKind = undefined; | ||
}, | ||
registerForSubtitleChanges: function (callback) { | ||
subtitleCallbacks.push(callback); | ||
return callback; | ||
}, | ||
unregisterForSubtitleChanges: function (callback) { | ||
var indexOf = subtitleCallbacks.indexOf(callback); | ||
if (indexOf !== -1) { | ||
subtitleCallbacks.splice(indexOf, 1); | ||
} | ||
}, | ||
setCurrentTime: function (time) { | ||
@@ -261,2 +283,3 @@ DebugTool.apicall('setCurrentTime'); | ||
playerComponent.setSubtitlesEnabled(value); | ||
callSubtitlesCallbacks(value); | ||
}, | ||
@@ -263,0 +286,0 @@ isSubtitlesEnabled: function () { |
define('bigscreenplayer/version', | ||
function () { | ||
return '3.13.3'; | ||
return '3.14.0'; | ||
} | ||
); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7862268
76304
242