89601c9c by Gary Katsevman

Remove event handlers in dispose.

Test that segmentXhr gets nulled out in dispose.
1 parent bd709446
...@@ -234,6 +234,13 @@ videojs.Hls.prototype.updateDuration = function(playlist) { ...@@ -234,6 +234,13 @@ videojs.Hls.prototype.updateDuration = function(playlist) {
234 * Abort all outstanding work and cleanup. 234 * Abort all outstanding work and cleanup.
235 */ 235 */
236 videojs.Hls.prototype.dispose = function() { 236 videojs.Hls.prototype.dispose = function() {
237 var player = this.player();
238
239 // remove event handlers
240 player.off('timeupdate', this.fillBuffer);
241 player.off('timeupdate', this.drainBuffer);
242 player.off('waiting', this.drainBuffer);
243
237 if (this.segmentXhr_) { 244 if (this.segmentXhr_) {
238 this.segmentXhr_.onreadystatechange = null; 245 this.segmentXhr_.onreadystatechange = null;
239 this.segmentXhr_.abort(); 246 this.segmentXhr_.abort();
......
...@@ -745,6 +745,44 @@ test('when outstanding XHRs are cancelled, they get aborted properly', function( ...@@ -745,6 +745,44 @@ test('when outstanding XHRs are cancelled, they get aborted properly', function(
745 strictEqual(readystatechanges, 0, 'onreadystatechange was not called'); 745 strictEqual(readystatechanges, 0, 'onreadystatechange was not called');
746 }); 746 });
747 747
748 test('segmentXhr is properly nulled out when dispose is called', function() {
749 var readystatechanges = 0,
750 oldDispose = videojs.Flash.prototype.dispose;
751 videojs.Flash.prototype.dispose = function() {};
752
753 player.src({
754 src: 'manifest/media.m3u8',
755 type: 'application/vnd.apple.mpegurl'
756 });
757 openMediaSource(player);
758 standardXHRResponse(requests[0]);
759 player.hls.media = {
760 segments: [{
761 uri: '0.ts',
762 duration: 10
763 }, {
764 uri: '1.ts',
765 duration: 10
766 }]
767 };
768
769 // trigger a segment download request
770 player.trigger('timeupdate');
771
772 player.hls.segmentXhr_.onreadystatechange = function() {
773 readystatechanges++;
774 };
775
776 player.hls.dispose();
777
778 ok(requests[1].aborted, 'XHR aborted');
779 strictEqual(requests.length, 2, 'did not open a new XHR');
780 equal(player.hls.segmentXhr_, null, 'the segment xhr is nulled out');
781 strictEqual(readystatechanges, 0, 'onreadystatechange was not called');
782
783 videojs.Flash.prototype.dispose = oldDispose;
784 });
785
748 test('flushes the parser after each segment', function() { 786 test('flushes the parser after each segment', function() {
749 var flushes = 0; 787 var flushes = 0;
750 // mock out the segment parser 788 // mock out the segment parser
......