Skip to content

Commit

Permalink
Use arrow functions for callbacks.
Browse files Browse the repository at this point in the history
This is an automated change to convert use of "function" functions
to arrow functions.  This doesn't change all uses of bind() that
could be converted.  This also doesn't remove all "function" functions.

Change-Id: I40ac7d086bcef947a1be083359c8fd1d4499a9c3
  • Loading branch information
TheModMaker committed May 9, 2019
1 parent f5701e7 commit 47daf49
Show file tree
Hide file tree
Showing 129 changed files with 2,307 additions and 2,306 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ module.exports = {
}],
"no-useless-constructor": "error",
"operator-assignment": "error",
"prefer-arrow-callback": "error",
// }}}
},
"overrides": [
Expand Down
4 changes: 2 additions & 2 deletions demo/cast_receiver/receiver_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ ShakaReceiver.prototype.onPlayStateChange_ = function() {
} else {
// Show controls for 3 seconds.
this.controlsElement_.style.opacity = 1;
this.controlsTimerId_ = window.setTimeout(function() {
this.controlsTimerId_ = window.setTimeout(() => {
this.controlsElement_.style.opacity = 0;
}.bind(this), 3000);
}, 3000);
}
};

Expand Down
2 changes: 1 addition & 1 deletion demo/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ class ShakaDemoMain {
elem.removeAttribute('disabled');
elem.addEventListener('click', () => {
const rawParams = location.hash.substr(1).split(';');
const newParams = rawParams.filter(function(param) {
const newParams = rawParams.filter((param) => {
// Remove current build type param(s).
return param != 'compiled' && param.split('=')[0] != 'build';
});
Expand Down
4 changes: 2 additions & 2 deletions demo/service_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,9 @@ async function fetchAndCache(cache, request) {
function timeout(seconds, asyncProcess) {
return Promise.race([
asyncProcess,
new Promise(function(_, reject) {
new Promise(((_, reject) => {
setTimeout(reject, seconds * 1000);
}),
})),
]);
}

Expand Down
40 changes: 20 additions & 20 deletions lib/cast/cast_proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,15 @@ shaka.cast.CastProxy.prototype.cast = function() {
// TODO: transfer manually-selected tracks?
// TODO: transfer side-loaded text tracks?

return this.sender_.cast(initState).then(function() {
return this.sender_.cast(initState).then(() => {
if (!this.localPlayer_) {
// We've already been destroyed.
return;
}

// Unload the local manifest when casting succeeds.
return this.localPlayer_.unload();
}.bind(this));
});
};


Expand Down Expand Up @@ -246,15 +246,15 @@ shaka.cast.CastProxy.prototype.init_ = function() {

this.eventManager_ = new shaka.util.EventManager();

shaka.cast.CastUtils.VideoEvents.forEach(function(name) {
shaka.cast.CastUtils.VideoEvents.forEach((name) => {
this.eventManager_.listen(this.localVideo_, name,
this.videoProxyLocalEvent_.bind(this));
}.bind(this));
});

shaka.cast.CastUtils.PlayerEvents.forEach(function(name) {
shaka.cast.CastUtils.PlayerEvents.forEach((name) => {
this.eventManager_.listen(this.localPlayer_, name,
this.playerProxyLocalEvent_.bind(this));
}.bind(this));
});

// We would like to use Proxy here, but it is not supported on IE11 or Safari.
this.videoProxy_ = {};
Expand Down Expand Up @@ -303,31 +303,31 @@ shaka.cast.CastProxy.prototype.getInitState_ = function() {
// Pause local playback before capturing state.
this.localVideo_.pause();

shaka.cast.CastUtils.VideoInitStateAttributes.forEach(function(name) {
shaka.cast.CastUtils.VideoInitStateAttributes.forEach((name) => {
initState['video'][name] = this.localVideo_[name];
}.bind(this));
});

// If the video is still playing, set the startTime.
// Has no effect if nothing is loaded.
if (!this.localVideo_.ended) {
initState['startTime'] = this.localVideo_.currentTime;
}

shaka.cast.CastUtils.PlayerInitState.forEach(function(pair) {
shaka.cast.CastUtils.PlayerInitState.forEach((pair) => {
const getter = pair[0];
const setter = pair[1];
const value = /** @type {Object} */(this.localPlayer_)[getter]();

initState['player'][setter] = value;
}.bind(this));
});

shaka.cast.CastUtils.PlayerInitAfterLoadState.forEach(function(pair) {
shaka.cast.CastUtils.PlayerInitAfterLoadState.forEach((pair) => {
const getter = pair[0];
const setter = pair[1];
const value = /** @type {Object} */(this.localPlayer_)[getter]();

initState['playerAfterLoad'][setter] = value;
}.bind(this));
});

return initState;
};
Expand Down Expand Up @@ -361,12 +361,12 @@ shaka.cast.CastProxy.prototype.onFirstCastStateUpdate_ = function() {
*/
shaka.cast.CastProxy.prototype.onResumeLocal_ = function() {
// Transfer back the player state.
shaka.cast.CastUtils.PlayerInitState.forEach(function(pair) {
shaka.cast.CastUtils.PlayerInitState.forEach((pair) => {
const getter = pair[0];
const setter = pair[1];
const value = this.sender_.get('player', getter)();
/** @type {Object} */(this.localPlayer_)[setter](value);
}.bind(this));
});

// Get the most recent manifest URI and ended state.
const assetUri = this.sender_.get('player', 'getAssetUri')();
Expand All @@ -392,9 +392,9 @@ shaka.cast.CastProxy.prototype.onResumeLocal_ = function() {

// Get the video state into a temp variable since we will apply it async.
const videoState = {};
shaka.cast.CastUtils.VideoInitStateAttributes.forEach(function(name) {
shaka.cast.CastUtils.VideoInitStateAttributes.forEach((name) => {
videoState[name] = this.sender_.get('video', name);
}.bind(this));
});

// Finally, take on video state and player's "after load" state.
manifestReady.then(() => {
Expand All @@ -403,16 +403,16 @@ shaka.cast.CastProxy.prototype.onResumeLocal_ = function() {
return;
}

shaka.cast.CastUtils.VideoInitStateAttributes.forEach(function(name) {
shaka.cast.CastUtils.VideoInitStateAttributes.forEach((name) => {
this.localVideo_[name] = videoState[name];
}.bind(this));
});

shaka.cast.CastUtils.PlayerInitAfterLoadState.forEach(function(pair) {
shaka.cast.CastUtils.PlayerInitAfterLoadState.forEach((pair) => {
const getter = pair[0];
const setter = pair[1];
const value = this.sender_.get('player', getter)();
/** @type {Object} */(this.localPlayer_)[setter](value);
}.bind(this));
});

// Restore the original autoplay setting.
this.localVideo_.autoplay = autoplay;
Expand Down
54 changes: 27 additions & 27 deletions lib/cast/cast_receiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,15 @@ shaka.cast.CastReceiver.prototype.init_ = function() {
manager.start();
}

shaka.cast.CastUtils.VideoEvents.forEach(function(name) {
shaka.cast.CastUtils.VideoEvents.forEach((name) => {
this.eventManager_.listen(
this.video_, name, this.proxyEvent_.bind(this, 'video'));
}.bind(this));
});

shaka.cast.CastUtils.PlayerEvents.forEach(function(name) {
shaka.cast.CastUtils.PlayerEvents.forEach((name) => {
this.eventManager_.listen(
this.player_, name, this.proxyEvent_.bind(this, 'player'));
}.bind(this));
});

// In our tests, the original Chromecast seems to have trouble decoding above
// 1080p. It would be a waste to select a higher res anyway, given that the
Expand All @@ -216,32 +216,32 @@ shaka.cast.CastReceiver.prototype.init_ = function() {

// Do not start excluding values from update messages until the video is
// fully loaded.
this.eventManager_.listen(this.video_, 'loadeddata', function() {
this.eventManager_.listen(this.video_, 'loadeddata', () => {
this.startUpdatingUpdateNumber_ = true;
}.bind(this));
});

// Maintain idle state.
this.eventManager_.listen(this.player_, 'loading', function() {
this.eventManager_.listen(this.player_, 'loading', () => {
// No longer idle once loading. This allows us to show the spinner during
// the initial buffering phase.
this.isIdle_ = false;
this.onCastStatusChanged_();
}.bind(this));
this.eventManager_.listen(this.video_, 'playing', function() {
});
this.eventManager_.listen(this.video_, 'playing', () => {
// No longer idle once playing. This allows us to replay a video without
// reloading.
this.isIdle_ = false;
this.onCastStatusChanged_();
}.bind(this));
this.eventManager_.listen(this.video_, 'pause', function() {
});
this.eventManager_.listen(this.video_, 'pause', () => {
this.onCastStatusChanged_();
}.bind(this));
this.eventManager_.listen(this.player_, 'unloading', function() {
});
this.eventManager_.listen(this.player_, 'unloading', () => {
// Go idle when unloading content.
this.isIdle_ = true;
this.onCastStatusChanged_();
}.bind(this));
this.eventManager_.listen(this.video_, 'ended', function() {
});
this.eventManager_.listen(this.video_, 'ended', () => {
// Go idle 5 seconds after 'ended', assuming we haven't started again or
// been destroyed.
const timer = new shaka.util.Timer(() => {
Expand All @@ -252,7 +252,7 @@ shaka.cast.CastReceiver.prototype.init_ = function() {
});

timer.tickAfter(/* seconds= */ 5);
}.bind(this));
});

// Do not start polling until after the sender's 'init' message is handled.
};
Expand Down Expand Up @@ -281,7 +281,7 @@ shaka.cast.CastReceiver.prototype.onCastStatusChanged_ = function() {
// Do this asynchronously so that synchronous changes to idle state (such as
// Player calling unload() as part of load()) are coalesced before the event
// goes out.
Promise.resolve().then(function() {
Promise.resolve().then(() => {
if (!this.player_) {
// We've already been destroyed.
return;
Expand All @@ -293,7 +293,7 @@ shaka.cast.CastReceiver.prototype.onCastStatusChanged_ = function() {
if (!this.maybeSendMediaInfoMessage_()) {
this.sendMediaStatus_(0);
}
}.bind(this));
});
};


Expand Down Expand Up @@ -397,9 +397,9 @@ shaka.cast.CastReceiver.prototype.pollAttributes_ = function() {
'player': {},
};

shaka.cast.CastUtils.VideoAttributes.forEach(function(name) {
shaka.cast.CastUtils.VideoAttributes.forEach((name) => {
update['video'][name] = this.video_[name];
}.bind(this));
});

// TODO: Instead of this variable frequency update system, instead cache the
// previous player state and only send over changed values, with complete
Expand Down Expand Up @@ -589,9 +589,9 @@ shaka.cast.CastReceiver.prototype.onShakaMessage_ = function(event) {
if (targetName == 'player' && methodName == 'load') {
// Wait until the manifest has actually loaded to send another media
// info message, so on a new load it doesn't send the old info over.
p = p.then(function() {
p = p.then(() => {
this.initialStatusUpdatePending_ = true;
}.bind(this));
});
}
// Replies must go back to the specific sender who initiated, so that we
// don't have to deal with conflicting IDs between senders.
Expand Down Expand Up @@ -639,14 +639,14 @@ shaka.cast.CastReceiver.prototype.onGenericMessage_ = function(event) {
break;
}
case 'STOP':
this.player_.unload().then(function() {
this.player_.unload().then(() => {
if (!this.player_) {
// We've already been destroyed.
return;
}

this.sendMediaStatus_(0);
}.bind(this));
});
break;
case 'GET_STATUS':
// TODO(ismena): According to the SDK this is supposed to be a
Expand Down Expand Up @@ -689,15 +689,15 @@ shaka.cast.CastReceiver.prototype.onGenericMessage_ = function(event) {
if (autoplay) {
this.video_.autoplay = true;
}
this.player_.load(assetUri, currentTime).then(function() {
this.player_.load(assetUri, currentTime).then(() => {
if (!this.player_) {
// We've already been destroyed.
return;
}

// Notify generic controllers that the media has changed.
this.sendMediaInfoMessage_();
}.bind(this)).catch(function(error) {
}).catch((error) => {
// Load failed. Dispatch the error message to the sender.
let type = 'LOAD_FAILED';
if (error.category == shaka.util.Error.Category.PLAYER &&
Expand All @@ -709,7 +709,7 @@ shaka.cast.CastReceiver.prototype.onGenericMessage_ = function(event) {
'requestId': Number(message['requestId']),
'type': type,
}, this.genericBus_);
}.bind(this));
});
break;
}
default:
Expand Down
8 changes: 4 additions & 4 deletions lib/cast/cast_sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ shaka.cast.CastSender.prototype.init = function() {

// TODO: Have never seen this fail. When would it and how should we react?
chrome.cast.initialize(apiConfig,
function() { shaka.log.debug('CastSender: init'); },
function(error) { shaka.log.error('CastSender: init error', error); });
() => { shaka.log.debug('CastSender: init'); },
(error) => { shaka.log.error('CastSender: init error', error); });
if (shaka.cast.CastSender.hasReceivers_) {
// Fire a fake cast status change, to simulate the update that
// would be fired normally.
Expand Down Expand Up @@ -307,7 +307,7 @@ shaka.cast.CastSender.prototype.forceDisconnect = function() {
this.rejectAllPromises_();
if (shaka.cast.CastSender.session_) {
this.removeListeners_();
shaka.cast.CastSender.session_.stop(function() {}, function() {});
shaka.cast.CastSender.session_.stop(() => {}, () => {});
shaka.cast.CastSender.session_ = null;
}
};
Expand Down Expand Up @@ -657,6 +657,6 @@ shaka.cast.CastSender.prototype.sendMessage_ = function(message) {
const session = shaka.cast.CastSender.session_;
session.sendMessage(shaka.cast.CastUtils.SHAKA_MESSAGE_NAMESPACE,
serialized,
function() {}, // success callback
() => {}, // success callback
shaka.log.error); // error callback
};
4 changes: 2 additions & 2 deletions lib/cast/cast_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ shaka.cast.CastUtils.GENERIC_MESSAGE_NAMESPACE =
* @return {string}
*/
shaka.cast.CastUtils.serialize = function(thing) {
return JSON.stringify(thing, function(key, value) {
return JSON.stringify(thing, (key, value) => {
if (typeof value == 'function') {
// Functions can't be (safely) serialized.
return undefined;
Expand Down Expand Up @@ -317,7 +317,7 @@ shaka.cast.CastUtils.serialize = function(thing) {
* @return {?}
*/
shaka.cast.CastUtils.deserialize = function(str) {
return JSON.parse(str, function(key, value) {
return JSON.parse(str, (key, value) => {
if (value == 'NaN') {
return NaN;
} else if (value == '-Infinity') {
Expand Down
6 changes: 3 additions & 3 deletions lib/dash/content_protection.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ shaka.dash.ContentProtection.parseFromAdaptationSet = function(
if (!ignoreDrmInfo) {
// Find the default key ID and init data. Create a new array of all the
// non-CENC elements.
parsedNonCenc = parsed.filter(function(elem) {
parsedNonCenc = parsed.filter((elem) => {
if (elem.schemeUri == ContentProtection.MP4Protection_) {
goog.asserts.assert(!elem.init || elem.init.length,
'Init data must be null or non-empty.');
Expand Down Expand Up @@ -244,8 +244,8 @@ shaka.dash.ContentProtection.parseFromRepresentation = function(
} else if (repContext.drmInfos.length > 0) {
// If this is not the first Representation, then we need to remove entries
// from the context that do not appear in this Representation.
context.drmInfos = context.drmInfos.filter(function(asInfo) {
return repContext.drmInfos.some(function(repInfo) {
context.drmInfos = context.drmInfos.filter((asInfo) => {
return repContext.drmInfos.some((repInfo) => {
return repInfo.keySystem == asInfo.keySystem;
});
});
Expand Down
Loading

0 comments on commit 47daf49

Please sign in to comment.