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..e73c832e26e967776cdf1709d1c665f9878b234f 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,11 +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') { |
- return false; |
- } |
+ base.debug.assert(type == remoting.VideoFrameRecorder.EXTENSION_TYPE); |
var messageType = base.getStringAttr(message, 'type'); |
var messageData = base.getStringAttr(message, 'data'); |
@@ -115,6 +114,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 +173,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); |
} |