Rename HLS source handler to HlsHandler
Separate out the source handler object from the HLS namespace. Now, videojs.Hls is an object that is used to organize exports from this library. The actual source handler prototype is now HlsHandler. Intended to be defensive about the backwards-compatibility concerns in https://github.com/videojs/video.js/pull/2814.
Showing
2 changed files
with
29 additions
and
28 deletions
... | @@ -23,7 +23,8 @@ keyFailed = function(key) { | ... | @@ -23,7 +23,8 @@ keyFailed = function(key) { |
23 | return key.retries && key.retries >= 2; | 23 | return key.retries && key.retries >= 2; |
24 | }; | 24 | }; |
25 | 25 | ||
26 | videojs.Hls = videojs.extend(Component, { | 26 | videojs.Hls = {}; |
27 | videojs.HlsHandler = videojs.extend(Component, { | ||
27 | constructor: function(tech, options) { | 28 | constructor: function(tech, options) { |
28 | var self = this, _player; | 29 | var self = this, _player; |
29 | 30 | ||
... | @@ -110,7 +111,7 @@ videojs.HlsSourceHandler = function(mode) { | ... | @@ -110,7 +111,7 @@ videojs.HlsSourceHandler = function(mode) { |
110 | tech.trigger('loadstart'); | 111 | tech.trigger('loadstart'); |
111 | }, 1); | 112 | }, 1); |
112 | } | 113 | } |
113 | tech.hls = new videojs.Hls(tech, { | 114 | tech.hls = new videojs.HlsHandler(tech, { |
114 | source: source, | 115 | source: source, |
115 | mode: mode | 116 | mode: mode |
116 | }); | 117 | }); |
... | @@ -129,7 +130,7 @@ videojs.getComponent('Flash').registerSourceHandler(videojs.HlsSourceHandler('fl | ... | @@ -129,7 +130,7 @@ videojs.getComponent('Flash').registerSourceHandler(videojs.HlsSourceHandler('fl |
129 | // the desired length of video to maintain in the buffer, in seconds | 130 | // the desired length of video to maintain in the buffer, in seconds |
130 | videojs.Hls.GOAL_BUFFER_LENGTH = 30; | 131 | videojs.Hls.GOAL_BUFFER_LENGTH = 30; |
131 | 132 | ||
132 | videojs.Hls.prototype.src = function(src) { | 133 | videojs.HlsHandler.prototype.src = function(src) { |
133 | var oldMediaPlaylist; | 134 | var oldMediaPlaylist; |
134 | 135 | ||
135 | // do nothing if the src is falsey | 136 | // do nothing if the src is falsey |
... | @@ -208,7 +209,7 @@ videojs.Hls.prototype.src = function(src) { | ... | @@ -208,7 +209,7 @@ videojs.Hls.prototype.src = function(src) { |
208 | this.tech_.src(videojs.URL.createObjectURL(this.mediaSource)); | 209 | this.tech_.src(videojs.URL.createObjectURL(this.mediaSource)); |
209 | }; | 210 | }; |
210 | 211 | ||
211 | videojs.Hls.prototype.handleSourceOpen = function() { | 212 | videojs.HlsHandler.prototype.handleSourceOpen = function() { |
212 | // Only attempt to create the source buffer if none already exist. | 213 | // Only attempt to create the source buffer if none already exist. |
213 | // handleSourceOpen is also called when we are "re-opening" a source buffer | 214 | // handleSourceOpen is also called when we are "re-opening" a source buffer |
214 | // after `endOfStream` has been called (in response to a seek for instance) | 215 | // after `endOfStream` has been called (in response to a seek for instance) |
... | @@ -284,7 +285,7 @@ videojs.Hls.bufferedAdditions_ = function(original, update) { | ... | @@ -284,7 +285,7 @@ videojs.Hls.bufferedAdditions_ = function(original, update) { |
284 | return result; | 285 | return result; |
285 | }; | 286 | }; |
286 | 287 | ||
287 | videojs.Hls.prototype.setupSourceBuffer_ = function() { | 288 | videojs.HlsHandler.prototype.setupSourceBuffer_ = function() { |
288 | var media = this.playlists.media(), mimeType; | 289 | var media = this.playlists.media(), mimeType; |
289 | 290 | ||
290 | // wait until a media playlist is available and the Media Source is | 291 | // wait until a media playlist is available and the Media Source is |
... | @@ -375,7 +376,7 @@ videojs.Hls.prototype.setupSourceBuffer_ = function() { | ... | @@ -375,7 +376,7 @@ videojs.Hls.prototype.setupSourceBuffer_ = function() { |
375 | * Seek to the latest media position if this is a live video and the | 376 | * Seek to the latest media position if this is a live video and the |
376 | * player and video are loaded and initialized. | 377 | * player and video are loaded and initialized. |
377 | */ | 378 | */ |
378 | videojs.Hls.prototype.setupFirstPlay = function() { | 379 | videojs.HlsHandler.prototype.setupFirstPlay = function() { |
379 | var seekable, media; | 380 | var seekable, media; |
380 | media = this.playlists.media(); | 381 | media = this.playlists.media(); |
381 | 382 | ||
... | @@ -405,7 +406,7 @@ videojs.Hls.prototype.setupFirstPlay = function() { | ... | @@ -405,7 +406,7 @@ videojs.Hls.prototype.setupFirstPlay = function() { |
405 | /** | 406 | /** |
406 | * Begin playing the video. | 407 | * Begin playing the video. |
407 | */ | 408 | */ |
408 | videojs.Hls.prototype.play = function() { | 409 | videojs.HlsHandler.prototype.play = function() { |
409 | this.loadingState_ = 'segments'; | 410 | this.loadingState_ = 'segments'; |
410 | 411 | ||
411 | if (this.tech_.ended()) { | 412 | if (this.tech_.ended()) { |
... | @@ -425,7 +426,7 @@ videojs.Hls.prototype.play = function() { | ... | @@ -425,7 +426,7 @@ videojs.Hls.prototype.play = function() { |
425 | } | 426 | } |
426 | }; | 427 | }; |
427 | 428 | ||
428 | videojs.Hls.prototype.setCurrentTime = function(currentTime) { | 429 | videojs.HlsHandler.prototype.setCurrentTime = function(currentTime) { |
429 | var | 430 | var |
430 | buffered = this.findCurrentBuffered_(); | 431 | buffered = this.findCurrentBuffered_(); |
431 | 432 | ||
... | @@ -461,7 +462,7 @@ videojs.Hls.prototype.setCurrentTime = function(currentTime) { | ... | @@ -461,7 +462,7 @@ videojs.Hls.prototype.setCurrentTime = function(currentTime) { |
461 | this.fillBuffer(this.playlists.getMediaIndexForTime_(currentTime)); | 462 | this.fillBuffer(this.playlists.getMediaIndexForTime_(currentTime)); |
462 | }; | 463 | }; |
463 | 464 | ||
464 | videojs.Hls.prototype.duration = function() { | 465 | videojs.HlsHandler.prototype.duration = function() { |
465 | var playlists = this.playlists; | 466 | var playlists = this.playlists; |
466 | if (playlists) { | 467 | if (playlists) { |
467 | return videojs.Hls.Playlist.duration(playlists.media()); | 468 | return videojs.Hls.Playlist.duration(playlists.media()); |
... | @@ -469,7 +470,7 @@ videojs.Hls.prototype.duration = function() { | ... | @@ -469,7 +470,7 @@ videojs.Hls.prototype.duration = function() { |
469 | return 0; | 470 | return 0; |
470 | }; | 471 | }; |
471 | 472 | ||
472 | videojs.Hls.prototype.seekable = function() { | 473 | videojs.HlsHandler.prototype.seekable = function() { |
473 | var media; | 474 | var media; |
474 | 475 | ||
475 | if (!this.playlists) { | 476 | if (!this.playlists) { |
... | @@ -486,7 +487,7 @@ videojs.Hls.prototype.seekable = function() { | ... | @@ -486,7 +487,7 @@ videojs.Hls.prototype.seekable = function() { |
486 | /** | 487 | /** |
487 | * Update the player duration | 488 | * Update the player duration |
488 | */ | 489 | */ |
489 | videojs.Hls.prototype.updateDuration = function(playlist) { | 490 | videojs.HlsHandler.prototype.updateDuration = function(playlist) { |
490 | var oldDuration = this.mediaSource.duration, | 491 | var oldDuration = this.mediaSource.duration, |
491 | newDuration = videojs.Hls.Playlist.duration(playlist), | 492 | newDuration = videojs.Hls.Playlist.duration(playlist), |
492 | setDuration = function() { | 493 | setDuration = function() { |
... | @@ -521,7 +522,7 @@ videojs.Hls.prototype.updateDuration = function(playlist) { | ... | @@ -521,7 +522,7 @@ videojs.Hls.prototype.updateDuration = function(playlist) { |
521 | * source. After this function is called, the tech should be in a | 522 | * source. After this function is called, the tech should be in a |
522 | * state suitable for switching to a different video. | 523 | * state suitable for switching to a different video. |
523 | */ | 524 | */ |
524 | videojs.Hls.prototype.resetSrc_ = function() { | 525 | videojs.HlsHandler.prototype.resetSrc_ = function() { |
525 | this.cancelSegmentXhr(); | 526 | this.cancelSegmentXhr(); |
526 | this.cancelKeyXhr(); | 527 | this.cancelKeyXhr(); |
527 | 528 | ||
... | @@ -530,7 +531,7 @@ videojs.Hls.prototype.resetSrc_ = function() { | ... | @@ -530,7 +531,7 @@ videojs.Hls.prototype.resetSrc_ = function() { |
530 | } | 531 | } |
531 | }; | 532 | }; |
532 | 533 | ||
533 | videojs.Hls.prototype.cancelKeyXhr = function() { | 534 | videojs.HlsHandler.prototype.cancelKeyXhr = function() { |
534 | if (this.keyXhr_) { | 535 | if (this.keyXhr_) { |
535 | this.keyXhr_.onreadystatechange = null; | 536 | this.keyXhr_.onreadystatechange = null; |
536 | this.keyXhr_.abort(); | 537 | this.keyXhr_.abort(); |
... | @@ -538,7 +539,7 @@ videojs.Hls.prototype.cancelKeyXhr = function() { | ... | @@ -538,7 +539,7 @@ videojs.Hls.prototype.cancelKeyXhr = function() { |
538 | } | 539 | } |
539 | }; | 540 | }; |
540 | 541 | ||
541 | videojs.Hls.prototype.cancelSegmentXhr = function() { | 542 | videojs.HlsHandler.prototype.cancelSegmentXhr = function() { |
542 | if (this.segmentXhr_) { | 543 | if (this.segmentXhr_) { |
543 | // Prevent error handler from running. | 544 | // Prevent error handler from running. |
544 | this.segmentXhr_.onreadystatechange = null; | 545 | this.segmentXhr_.onreadystatechange = null; |
... | @@ -552,7 +553,7 @@ videojs.Hls.prototype.cancelSegmentXhr = function() { | ... | @@ -552,7 +553,7 @@ videojs.Hls.prototype.cancelSegmentXhr = function() { |
552 | /** | 553 | /** |
553 | * Abort all outstanding work and cleanup. | 554 | * Abort all outstanding work and cleanup. |
554 | */ | 555 | */ |
555 | videojs.Hls.prototype.dispose = function() { | 556 | videojs.HlsHandler.prototype.dispose = function() { |
556 | this.stopCheckingBuffer_(); | 557 | this.stopCheckingBuffer_(); |
557 | 558 | ||
558 | if (this.playlists) { | 559 | if (this.playlists) { |
... | @@ -569,7 +570,7 @@ videojs.Hls.prototype.dispose = function() { | ... | @@ -569,7 +570,7 @@ videojs.Hls.prototype.dispose = function() { |
569 | * @return the highest bitrate playlist less than the currently detected | 570 | * @return the highest bitrate playlist less than the currently detected |
570 | * bandwidth, accounting for some amount of bandwidth variance | 571 | * bandwidth, accounting for some amount of bandwidth variance |
571 | */ | 572 | */ |
572 | videojs.Hls.prototype.selectPlaylist = function () { | 573 | videojs.HlsHandler.prototype.selectPlaylist = function () { |
573 | var | 574 | var |
574 | effectiveBitrate, | 575 | effectiveBitrate, |
575 | sortedPlaylists = this.playlists.master.playlists.slice(), | 576 | sortedPlaylists = this.playlists.master.playlists.slice(), |
... | @@ -662,7 +663,7 @@ videojs.Hls.prototype.selectPlaylist = function () { | ... | @@ -662,7 +663,7 @@ videojs.Hls.prototype.selectPlaylist = function () { |
662 | /** | 663 | /** |
663 | * Periodically request new segments and append video data. | 664 | * Periodically request new segments and append video data. |
664 | */ | 665 | */ |
665 | videojs.Hls.prototype.checkBuffer_ = function() { | 666 | videojs.HlsHandler.prototype.checkBuffer_ = function() { |
666 | // calling this method directly resets any outstanding buffer checks | 667 | // calling this method directly resets any outstanding buffer checks |
667 | if (this.checkBufferTimeout_) { | 668 | if (this.checkBufferTimeout_) { |
668 | window.clearTimeout(this.checkBufferTimeout_); | 669 | window.clearTimeout(this.checkBufferTimeout_); |
... | @@ -681,7 +682,7 @@ videojs.Hls.prototype.checkBuffer_ = function() { | ... | @@ -681,7 +682,7 @@ videojs.Hls.prototype.checkBuffer_ = function() { |
681 | * Setup a periodic task to request new segments if necessary and | 682 | * Setup a periodic task to request new segments if necessary and |
682 | * append bytes into the SourceBuffer. | 683 | * append bytes into the SourceBuffer. |
683 | */ | 684 | */ |
684 | videojs.Hls.prototype.startCheckingBuffer_ = function() { | 685 | videojs.HlsHandler.prototype.startCheckingBuffer_ = function() { |
685 | // if the player ever stalls, check if there is video data available | 686 | // if the player ever stalls, check if there is video data available |
686 | // to append immediately | 687 | // to append immediately |
687 | this.tech_.on('waiting', (this.drainBuffer).bind(this)); | 688 | this.tech_.on('waiting', (this.drainBuffer).bind(this)); |
... | @@ -693,7 +694,7 @@ videojs.Hls.prototype.startCheckingBuffer_ = function() { | ... | @@ -693,7 +694,7 @@ videojs.Hls.prototype.startCheckingBuffer_ = function() { |
693 | * Stop the periodic task requesting new segments and feeding the | 694 | * Stop the periodic task requesting new segments and feeding the |
694 | * SourceBuffer. | 695 | * SourceBuffer. |
695 | */ | 696 | */ |
696 | videojs.Hls.prototype.stopCheckingBuffer_ = function() { | 697 | videojs.HlsHandler.prototype.stopCheckingBuffer_ = function() { |
697 | if (this.checkBufferTimeout_) { | 698 | if (this.checkBufferTimeout_) { |
698 | window.clearTimeout(this.checkBufferTimeout_); | 699 | window.clearTimeout(this.checkBufferTimeout_); |
699 | this.checkBufferTimeout_ = null; | 700 | this.checkBufferTimeout_ = null; |
... | @@ -705,7 +706,7 @@ videojs.Hls.prototype.stopCheckingBuffer_ = function() { | ... | @@ -705,7 +706,7 @@ videojs.Hls.prototype.stopCheckingBuffer_ = function() { |
705 | * Attempts to find the buffered TimeRange where playback is currently | 706 | * Attempts to find the buffered TimeRange where playback is currently |
706 | * happening. Returns a new TimeRange with one or zero ranges. | 707 | * happening. Returns a new TimeRange with one or zero ranges. |
707 | */ | 708 | */ |
708 | videojs.Hls.prototype.findCurrentBuffered_ = function() { | 709 | videojs.HlsHandler.prototype.findCurrentBuffered_ = function() { |
709 | var | 710 | var |
710 | ranges, | 711 | ranges, |
711 | i, | 712 | i, |
... | @@ -743,7 +744,7 @@ videojs.Hls.prototype.findCurrentBuffered_ = function() { | ... | @@ -743,7 +744,7 @@ videojs.Hls.prototype.findCurrentBuffered_ = function() { |
743 | * @param seekToTime (optional) {number} the offset into the downloaded segment | 744 | * @param seekToTime (optional) {number} the offset into the downloaded segment |
744 | * to seek to, in seconds | 745 | * to seek to, in seconds |
745 | */ | 746 | */ |
746 | videojs.Hls.prototype.fillBuffer = function(mediaIndex) { | 747 | videojs.HlsHandler.prototype.fillBuffer = function(mediaIndex) { |
747 | var | 748 | var |
748 | tech = this.tech_, | 749 | tech = this.tech_, |
749 | currentTime = tech.currentTime(), | 750 | currentTime = tech.currentTime(), |
... | @@ -840,7 +841,7 @@ videojs.Hls.prototype.fillBuffer = function(mediaIndex) { | ... | @@ -840,7 +841,7 @@ videojs.Hls.prototype.fillBuffer = function(mediaIndex) { |
840 | this.loadSegment(segmentInfo); | 841 | this.loadSegment(segmentInfo); |
841 | }; | 842 | }; |
842 | 843 | ||
843 | videojs.Hls.prototype.playlistUriToUrl = function(segmentRelativeUrl) { | 844 | videojs.HlsHandler.prototype.playlistUriToUrl = function(segmentRelativeUrl) { |
844 | var playListUrl; | 845 | var playListUrl; |
845 | // resolve the segment URL relative to the playlist | 846 | // resolve the segment URL relative to the playlist |
846 | if (this.playlists.media().uri === this.source_.src) { | 847 | if (this.playlists.media().uri === this.source_.src) { |
... | @@ -859,7 +860,7 @@ videojs.Hls.prototype.playlistUriToUrl = function(segmentRelativeUrl) { | ... | @@ -859,7 +860,7 @@ videojs.Hls.prototype.playlistUriToUrl = function(segmentRelativeUrl) { |
859 | * * `bytesReceived` - amount of bytes downloaded | 860 | * * `bytesReceived` - amount of bytes downloaded |
860 | * `bandwidth` is the only required property. | 861 | * `bandwidth` is the only required property. |
861 | */ | 862 | */ |
862 | videojs.Hls.prototype.setBandwidth = function(xhr) { | 863 | videojs.HlsHandler.prototype.setBandwidth = function(xhr) { |
863 | // calculate the download bandwidth | 864 | // calculate the download bandwidth |
864 | this.segmentXhrTime = xhr.roundTripTime; | 865 | this.segmentXhrTime = xhr.roundTripTime; |
865 | this.bandwidth = xhr.bandwidth; | 866 | this.bandwidth = xhr.bandwidth; |
... | @@ -868,7 +869,7 @@ videojs.Hls.prototype.setBandwidth = function(xhr) { | ... | @@ -868,7 +869,7 @@ videojs.Hls.prototype.setBandwidth = function(xhr) { |
868 | this.tech_.trigger('bandwidthupdate'); | 869 | this.tech_.trigger('bandwidthupdate'); |
869 | }; | 870 | }; |
870 | 871 | ||
871 | videojs.Hls.prototype.loadSegment = function(segmentInfo) { | 872 | videojs.HlsHandler.prototype.loadSegment = function(segmentInfo) { |
872 | var | 873 | var |
873 | self = this, | 874 | self = this, |
874 | segment = segmentInfo.playlist.segments[segmentInfo.mediaIndex]; | 875 | segment = segmentInfo.playlist.segments[segmentInfo.mediaIndex]; |
... | @@ -927,7 +928,7 @@ videojs.Hls.prototype.loadSegment = function(segmentInfo) { | ... | @@ -927,7 +928,7 @@ videojs.Hls.prototype.loadSegment = function(segmentInfo) { |
927 | }); | 928 | }); |
928 | }; | 929 | }; |
929 | 930 | ||
930 | videojs.Hls.prototype.drainBuffer = function(event) { | 931 | videojs.HlsHandler.prototype.drainBuffer = function(event) { |
931 | var | 932 | var |
932 | segmentInfo, | 933 | segmentInfo, |
933 | mediaIndex, | 934 | mediaIndex, |
... | @@ -1040,7 +1041,7 @@ videojs.Hls.prototype.drainBuffer = function(event) { | ... | @@ -1040,7 +1041,7 @@ videojs.Hls.prototype.drainBuffer = function(event) { |
1040 | /** | 1041 | /** |
1041 | * Attempt to retrieve the key for a particular media segment. | 1042 | * Attempt to retrieve the key for a particular media segment. |
1042 | */ | 1043 | */ |
1043 | videojs.Hls.prototype.fetchKey_ = function(segment) { | 1044 | videojs.HlsHandler.prototype.fetchKey_ = function(segment) { |
1044 | var key, self, settings, receiveKey; | 1045 | var key, self, settings, receiveKey; |
1045 | 1046 | ||
1046 | // if there is a pending XHR or no segments, don't do anything | 1047 | // if there is a pending XHR or no segments, don't do anything | ... | ... |
... | @@ -1911,10 +1911,10 @@ test('the source handler supports HLS mime types', function() { | ... | @@ -1911,10 +1911,10 @@ test('the source handler supports HLS mime types', function() { |
1911 | 1911 | ||
1912 | ok(!(videojs.HlsSourceHandler(techName).canHandleSource({ | 1912 | ok(!(videojs.HlsSourceHandler(techName).canHandleSource({ |
1913 | type: 'video/mp4' | 1913 | type: 'video/mp4' |
1914 | }) instanceof videojs.Hls), 'does not support mp4'); | 1914 | }) instanceof videojs.HlsHandler), 'does not support mp4'); |
1915 | ok(!(videojs.HlsSourceHandler(techName).canHandleSource({ | 1915 | ok(!(videojs.HlsSourceHandler(techName).canHandleSource({ |
1916 | type: 'video/x-flv' | 1916 | type: 'video/x-flv' |
1917 | }) instanceof videojs.Hls), 'does not support flv'); | 1917 | }) instanceof videojs.HlsHandler), 'does not support flv'); |
1918 | }); | 1918 | }); |
1919 | }); | 1919 | }); |
1920 | 1920 | ... | ... |
-
Please register or sign in to post a comment