Chromium Code Reviews| Index: remoting/webapp/crd/js/video_frame_recorder.js |
| diff --git a/remoting/webapp/crd/js/video_frame_recorder.js b/remoting/webapp/crd/js/video_frame_recorder.js |
| index a5bceb91029c4f8e365325ab4768a1e2df60de4e..53564ea5e65977b2a801305d746b4c6f11afe079 100644 |
| --- a/remoting/webapp/crd/js/video_frame_recorder.js |
| +++ b/remoting/webapp/crd/js/video_frame_recorder.js |
| @@ -14,39 +14,40 @@ var remoting = remoting || {}; |
| /** |
| * @constructor |
| - * @param {remoting.ClientPlugin} plugin |
| + * @implements {remoting.ProtocolExtension} |
| */ |
| -remoting.VideoFrameRecorder = function(plugin) { |
| +remoting.VideoFrameRecorder = function() { |
| + /** @private {?function(string,string)} */ |
| + this.sendMessageToHostCallback_ = null; |
| + |
| this.fileWriter_ = null; |
| this.isRecording_ = false; |
| - this.plugin_ = plugin; |
| +}; |
| + |
| +/** @private {string} */ |
| +remoting.VideoFrameRecorder.EXTENSION_TYPE = 'video-recorder'; |
| + |
| +/** @return {Array<string>} */ |
| +remoting.VideoFrameRecorder.prototype.getExtensionTypes = function() { |
| + return [remoting.VideoFrameRecorder.EXTENSION_TYPE]; |
| }; |
| /** |
| - * Starts or stops video recording. |
| + * @param {function(string,string)} sendMessageToHost Callback to send a message |
| + * to the host. |
| */ |
| -remoting.VideoFrameRecorder.prototype.startStopRecording = function() { |
| - var data = {}; |
| - if (this.isRecording_) { |
| - this.isRecording_ = false; |
| - data = { type: 'stop' } |
| - |
| - chrome.fileSystem.chooseEntry( |
| - {type: 'saveFile', suggestedName: 'videoRecording.pb'}, |
| - this.onFileChosen_.bind(this)); |
| - } else { |
| - this.isRecording_ = true; |
| - data = { type: 'start' } |
| - } |
| - this.plugin_.sendClientMessage('video-recorder', JSON.stringify(data)); |
| -} |
| +remoting.VideoFrameRecorder.prototype.startExtension = |
| + function(sendMessageToHost) { |
| + this.sendMessageToHostCallback_ = sendMessageToHost; |
| +}; |
| /** |
| - * Returns true if the session is currently being recorded. |
| - * @return {boolean} |
| + * @param {Object} data The data to send. |
| + * @private |
| */ |
| -remoting.VideoFrameRecorder.prototype.isRecording = function() { |
| - return this.isRecording_; |
| +remoting.VideoFrameRecorder.prototype.sendMessageToHost_ = function(data) { |
| + this.sendMessageToHostCallback_(remoting.VideoFrameRecorder.EXTENSION_TYPE, |
| + JSON.stringify(data)); |
| } |
| /** |
| @@ -57,9 +58,9 @@ remoting.VideoFrameRecorder.prototype.isRecording = function() { |
| * @param {Object} message The parsed extension message data. |
| * @return {boolean} |
| */ |
| -remoting.VideoFrameRecorder.prototype.handleMessage = |
| +remoting.VideoFrameRecorder.prototype.onExtensionMessage = |
| function(type, message) { |
| - if (type != 'video-recorder') { |
| + if (type != remoting.VideoFrameRecorder.EXTENSION_TYPE) { |
|
kelvinp
2015/03/21 17:36:09
Nit: Assert instead.
garykac
2015/03/23 22:51:04
Done.
|
| return false; |
| } |
| @@ -115,6 +116,33 @@ remoting.VideoFrameRecorder.prototype.handleMessage = |
| } |
| /** |
| + * Starts or stops video recording. |
| + */ |
| +remoting.VideoFrameRecorder.prototype.startStopRecording = function() { |
| + var data = {}; |
| + if (this.isRecording_) { |
| + this.isRecording_ = false; |
| + data = { type: 'stop' } |
| + |
| + chrome.fileSystem.chooseEntry( |
| + {type: 'saveFile', suggestedName: 'videoRecording.pb'}, |
| + this.onFileChosen_.bind(this)); |
| + } else { |
| + this.isRecording_ = true; |
| + data = { type: 'start' } |
| + } |
| + this.sendMessageToHost_(data); |
| +} |
| + |
| +/** |
| + * Returns true if the session is currently being recorded. |
| + * @return {boolean} |
| + */ |
| +remoting.VideoFrameRecorder.prototype.isRecording = function() { |
| + return this.isRecording_; |
| +} |
| + |
| +/** |
| * @param {Entry} entry The single file entry if multiple files are not allowed. |
| * @param {Array<FileEntry>} fileEntries List of file entries if multiple files |
| * are allowed. |
| @@ -147,5 +175,5 @@ remoting.VideoFrameRecorder.prototype.onWriteComplete_ = function(e) { |
| remoting.VideoFrameRecorder.prototype.fetchNextFrame_ = function() { |
| console.log("Request next video frame"); |
| var data = { type: 'next-frame' } |
| - this.plugin_.sendClientMessage('video-recorder', JSON.stringify(data)); |
| + this.sendMessageToHost_(data); |
| } |