dash-shaka-playback
Advanced tools
Comparing version 2.0.0-beta to 2.0.0
117
index.js
@@ -6,2 +6,3 @@ import {HTML5Video, Log, Events} from 'clappr' | ||
const AUTO = -1 | ||
const SHAKA_READY = 'shaka:ready' | ||
@@ -21,3 +22,6 @@ export default class DashShakaPlayback extends HTML5Video { | ||
this.trigger(Events.PLAYBACK_LEVEL_SWITCH_START) | ||
!isAuto && this.selectTrack(this._player.getTracks().filter((t) => t.id === this._currentLevelId)[0]) | ||
if (!isAuto) { | ||
this.selectTrack(this.videoTracks.filter((t) => t.id === this._currentLevelId)[0]) | ||
} | ||
this.trigger(Events.PLAYBACK_LEVEL_SWITCH_END) | ||
} | ||
@@ -28,22 +32,3 @@ get currentLevel() { return this._currentLevelId || AUTO } | ||
super(options) | ||
this.isReadyState = false | ||
this._levels = [] | ||
var checkIfIsReady = (fn) => { | ||
return (arg) => { | ||
if (this.isReady) return fn(arg) | ||
} | ||
} | ||
this.textTracks = checkIfIsReady(() => this._player.getTracks().filter((t) => t.type === "text")) | ||
this.audioTracks = checkIfIsReady(() => this._player.getTracks().filter((t) => t.type === "audio")) | ||
this.videoTracks = checkIfIsReady(() => this._player.getTracks().filter((t) => t.type === "video")) | ||
this.selectTrack = checkIfIsReady((track) => { | ||
this._player.selectTrack(track) | ||
this.trigger(Events.PLAYBACK_LEVEL_SWITCH_END) | ||
}) | ||
this.getPlaybackType = checkIfIsReady(() => (this._player.isLive()?'live':'vod')) | ||
options.autoPlay && this.play() | ||
@@ -56,3 +41,3 @@ } | ||
if (!this.isReady) { | ||
this.once(Events.PLAYBACK_READY, this.play) | ||
this.once(SHAKA_READY, this.play) | ||
return | ||
@@ -69,6 +54,8 @@ } | ||
get isReady() {return this.isReadyState} | ||
get isReady() {return this._isShakaReadyState} | ||
// skipping error handling on video tag in favor of error on shaka | ||
error(event) { Log.error('an error was raised by the video tag', event, this.el.error)} | ||
error(event) { | ||
Log.error('an error was raised by the video tag', event, this.el.error) | ||
} | ||
@@ -79,3 +66,2 @@ isHighDefinitionInUse() { return !!this.highDefinition } | ||
clearInterval(this.sendStatsId) | ||
this.trigger(Events.PLAYBACK_STOP, this.name) | ||
this._sendStats() | ||
@@ -85,4 +71,5 @@ | ||
then(() => { | ||
super.stop() | ||
this._player = null | ||
this.isReadyState = false | ||
this._isShakaReadyState = false | ||
}). | ||
@@ -92,11 +79,25 @@ catch(() => { Log.error('shaka could not be unloaded') }) | ||
get textTracks() {return this._player && this._player.getTracks().filter((t) => t.type === 'text')} | ||
get audioTracks() {return this._player && this._player.getTracks().filter((t) => t.type === 'audio')} | ||
get videoTracks() {return this._player && this._player.getTracks().filter((t) => t.type === 'video')} | ||
getPlaybackType() {return (this._player && this._player.isLive()?'live':'vod') || ''} | ||
selectTrack(track) { | ||
this._player.selectTrack(track) | ||
this._onAdaptation() | ||
} | ||
destroy() { | ||
clearInterval(this.sendStatsId) | ||
this._player.destroy(). | ||
then(() => this._destroy()). | ||
catch(() => { | ||
this._destroy() | ||
Log.error('shaka could not be destroyed') | ||
}) | ||
if (this._player) { | ||
this._destroy() | ||
} else { | ||
this._player.destroy(). | ||
then(() => this._destroy()). | ||
catch(() => { | ||
this._destroy() | ||
Log.error('shaka could not be destroyed') | ||
}) | ||
} | ||
} | ||
@@ -106,6 +107,7 @@ | ||
_setup() { | ||
this._isShakaReadyState = false | ||
this._player = this._createPlayer() | ||
this.options.shakaConfiguration && this._player.configure(this.options.shakaConfiguration) | ||
this._options.shakaConfiguration && this._player.configure(this._options.shakaConfiguration) | ||
var playerLoaded = this._player.load(this.options.src) | ||
var playerLoaded = this._player.load(this._options.src) | ||
playerLoaded.then(() => this._loaded()) | ||
@@ -118,13 +120,27 @@ .catch((e) => this._setupError(e)) | ||
player.addEventListener('error', (type, shakaError) => this._error(type, shakaError)) | ||
player.addEventListener('adaptation', (e) => this._onAdaptation(e)) | ||
player.addEventListener('adaptation', () => this._onAdaptation()) | ||
player.addEventListener('buffering', (e) => this._onBuffering(e)) | ||
return player | ||
} | ||
_onBuffering(e) { | ||
var event = e.buffering ? Events.PLAYBACK_BUFFERING : Events.PLAYBACK_BUFFERFULL | ||
this.trigger(event) | ||
} | ||
_loaded() { | ||
this._isShakaReadyState = true | ||
this.trigger(SHAKA_READY) | ||
this._ready() | ||
this._startToSendStats() | ||
this._levels = this.videoTracks().map((videoTrack) => { return {id: videoTrack.id, label: `${videoTrack.height}p`}}).reverse() | ||
this.trigger(Events.PLAYBACK_LEVELS_AVAILABLE, this.levels) | ||
this._fillLevels() | ||
} | ||
_fillLevels(){ | ||
if (this._levels.length === 0) { | ||
this._levels = this.videoTracks.map((videoTrack) => { return {id: videoTrack.id, label: `${videoTrack.height}p`}}).reverse() | ||
this.trigger(Events.PLAYBACK_LEVELS_AVAILABLE, this.levels) | ||
} | ||
} | ||
_startToSendStats() { | ||
@@ -139,2 +155,3 @@ this.sendStatsId = setInterval(() => this._sendStats(), SEND_STATS_AT) | ||
_error(type, shakaError) { | ||
Log.error('an error was raised support=', DashShakaPlayback.support) | ||
Log.error('an error was raised by shaka player', shakaError.detail) | ||
@@ -144,13 +161,15 @@ this.trigger(Events.PLAYBACK_ERROR, shakaError.detail, this.name) | ||
_onAdaptation(event) { | ||
if (!event.size) return | ||
_onAdaptation() { | ||
var activeVideo = this.videoTracks.filter((t) => t.active === true)[0] | ||
Log.debug('an adaptation has happened:', event) | ||
this.highDefinition = (event.size.height >= 720) | ||
this._fillLevels() | ||
Log.debug('an adaptation has happened:', activeVideo) | ||
this.highDefinition = (activeVideo.height >= 720) | ||
this.trigger(Events.PLAYBACK_HIGHDEFINITIONUPDATE, this.highDefinition) | ||
this.trigger(Events.PLAYBACK_BITRATE, { | ||
bandwidth: event.bandwidth, | ||
width: event.size.width, | ||
height: event.size.height, | ||
level: event.size.number | ||
bandwidth: activeVideo.bandwidth, | ||
width: activeVideo.width, | ||
height: activeVideo.height, | ||
level: activeVideo.id | ||
}) | ||
@@ -161,3 +180,3 @@ } | ||
super.destroy() | ||
this.isReadyState = false | ||
this._isShakaReadyState = false | ||
Log.debug('shaka was destroyed') | ||
@@ -167,3 +186,3 @@ } | ||
_ready() { | ||
super.ready() | ||
super._ready() | ||
} | ||
@@ -174,8 +193,6 @@ } | ||
shaka.polyfill.installAll() | ||
var browserSupported = shaka.Player.isBrowserSupported() | ||
shaka.Player.support().then((support) => { Log.debug(`TODO: Clappr is sync -> #{support.supported}`) }) | ||
var resourceParts = resource.split('?')[0].match(/.*\.(.*)$/) || [] | ||
return ('mpd' === resourceParts[1]) || mimeType.indexOf('application/dash+xml') > -1 | ||
return browserSupported && (('mpd' === resourceParts[1]) || mimeType.indexOf('application/dash+xml') > -1) | ||
} | ||
{ | ||
"name": "dash-shaka-playback", | ||
"version": "2.0.0-beta", | ||
"version": "2.0.0", | ||
"description": "clappr dash playback based on shaka player", | ||
@@ -18,4 +18,4 @@ "main": "index.js", | ||
"dependencies": { | ||
"shaka-player": "v2.0.0-beta", | ||
"clappr": "latest" | ||
"shaka-player": "v2.0.0", | ||
"clappr": "0.2.61" | ||
}, | ||
@@ -22,0 +22,0 @@ "devDependencies": { |
[](https://badge.fury.io/js/dash-shaka-playback) | ||
[](https://img.shields.io/badge/license-BSD--3--Clause-blue.svg) | ||
# For the latest stable version [check](https://github.com/clappr/dash-shaka-playback/tree/1.0.12) | ||
# For the latest stable version [check](https://github.com/clappr/dash-shaka-playback/tree/releases) | ||
@@ -14,3 +14,3 @@ # dash-shaka-playback | ||
[](https://jsfiddle.net/m8ndduLo/) | ||
[](https://jsfiddle.net/m8ndduLo/16/) | ||
@@ -31,6 +31,4 @@ # Usage | ||
{ | ||
source: 'https://shaka-player-demo.appspot.com/assets/angel_one.mpd?_=1446383792251', | ||
plugins: { | ||
playback: [DashShakaPlayback] | ||
}, | ||
source: '//storage.googleapis.com/shaka-demo-assets/angel-one/dash.mpd', | ||
plugins: [DashShakaPlayback], | ||
shakaConfiguration: { | ||
@@ -78,5 +76,1 @@ preferredAudioLanguage: 'pt-BR', | ||
# observations | ||
This playback supports the [browsers that shaka does](https://shaka-player-demo.appspot.com/docs/tutorial-porting.html) and it also has the same [content restrictions](https://shaka-player-demo.appspot.com/docs/tutorial-caveats.html). | ||
Sorry, the diff of this file is too big to display
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
291316
11
695
2
74
+ Addedclappr@0.2.61(transitive)
- Removedclappr@0.3.13(transitive)
Updatedclappr@0.2.61
Updatedshaka-player@v2.0.0