Skip to content

Commit

Permalink
Create an error setter on the base tech
Browse files Browse the repository at this point in the history
Source Handlers may need to trigger player errors if they encounter unrecoverable playback issues. Provide a base implementation of an error setter they can use to do so at the tech level. The setter is overridden for HTML since Source Handlers should probably use something like MediaSource.endOfStream('network') to signal errors in that case. Update Flash error handling to take advantage of the new mechanism.
  • Loading branch information
dmlap committed Aug 26, 2015
1 parent d663dbf commit 4ad58a2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 20 deletions.
24 changes: 4 additions & 20 deletions src/js/tech/flash.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,18 +267,6 @@ class Flash extends Tech {
return createTimeRange(0, this.el_.vjs_getProperty('buffered'));
}

/**
* Get the last error object
*
* @return {Object}
* @method error
*/
error() {
let error = this.error_;
this.error_ = null;
return error || null;
}

/**
* Get fullscreen support -
* Flash does not allow fullscreen through javascript
Expand Down Expand Up @@ -449,18 +437,14 @@ Flash.onEvent = function(swfID, eventName){
// Log errors from the swf
Flash.onError = function(swfID, err){
const tech = Dom.getEl(swfID).tech;
const msg = 'FLASH: '+err;
const errorObj = {
message: msg
};

tech.error_ = errorObj;

// trigger MEDIA_ERR_SRC_NOT_SUPPORTED
if (err === 'srcnotfound') {
errorObj.code = 4;
return tech.error(4);
}

tech.trigger('error', errorObj);
// trigger a custom error
tech.error('FLASH: ' + err);
};

// Flash Version Check
Expand Down
22 changes: 22 additions & 0 deletions src/js/tech/tech.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as Fn from '../utils/fn.js';
import log from '../utils/log.js';
import { createTimeRange } from '../utils/time-ranges.js';
import { bufferedPercent } from '../utils/buffer.js';
import MediaError from '../media-error.js';
import window from 'global/window';
import document from 'global/document';

Expand Down Expand Up @@ -265,6 +266,27 @@ class Tech extends Component {
super.dispose();
}

/**
* When invoked without an argument, returns a MediaError object
* representing the current error state of the player or null if
* there is no error. When invoked with an argument, set the current
* error state of the player.
* @param {MediaError=} err Optional an error object
* @return {MediaError} the current error object or null
* @method error
*/
error(err) {
if (err !== undefined) {
if (err instanceof MediaError) {
this.error_ = err;
} else {
this.error_ = new MediaError(err);
}
this.trigger('error');
}
return this.error_;
}

/**
* Return the time ranges that have been played through for the
* current source. This implementation is incomplete. It does not
Expand Down
19 changes: 19 additions & 0 deletions test/unit/tech/tech.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var noop = function() {}, clock, oldTextTracks;
import Tech from '../../../src/js/tech/tech.js';
import { createTimeRange } from '../../../src/js/utils/time-ranges.js';
import extendsFn from '../../../src/js/extends.js';
import MediaError from '../../../src/js/media-error.js';

q.module('Media Tech', {
'setup': function() {
Expand Down Expand Up @@ -195,6 +196,24 @@ test('should handle unsupported sources with the source handler API', function()
ok(usedNative, 'native source handler was used when an unsupported source was set');
});

test('should allow custom error events to be set', function() {
let tech = new Tech();
let errors = [];
tech.on('error', function() {
errors.push(tech.error());
});

equal(tech.error(), null, 'error is null by default');

tech.error(new MediaError(1));
equal(errors.length, 1, 'triggered an error event');
equal(errors[0].code, 1, 'set the proper code');

tech.error(2);
equal(errors.length, 2, 'triggered an error event');
equal(errors[1].code, 2, 'wrapped the error code');
});

test('should track whether a video has played', function() {
let tech = new Tech();

Expand Down

0 comments on commit 4ad58a2

Please sign in to comment.