Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Side by Side Diff: remoting/webapp/crd/js/video_frame_recorder.js

Issue 1028803002: [Chromoting] Convert VideoFrameRecorder into a proper protocol extension. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix nits Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/webapp/crd/js/desktop_remoting.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview 6 * @fileoverview
7 * Class implement the video frame recorder extension client. 7 * Class implement the video frame recorder extension client.
8 */ 8 */
9 9
10 'use strict'; 10 'use strict';
11 11
12 /** @suppress {duplicate} */ 12 /** @suppress {duplicate} */
13 var remoting = remoting || {}; 13 var remoting = remoting || {};
14 14
15 /** 15 /**
16 * @constructor 16 * @constructor
17 * @param {remoting.ClientPlugin} plugin 17 * @implements {remoting.ProtocolExtension}
18 */ 18 */
19 remoting.VideoFrameRecorder = function(plugin) { 19 remoting.VideoFrameRecorder = function() {
20 /** @private {?function(string,string)} */
21 this.sendMessageToHostCallback_ = null;
22
20 this.fileWriter_ = null; 23 this.fileWriter_ = null;
21 this.isRecording_ = false; 24 this.isRecording_ = false;
22 this.plugin_ = plugin; 25 };
26
27 /** @private {string} */
28 remoting.VideoFrameRecorder.EXTENSION_TYPE = 'video-recorder';
29
30 /** @return {Array<string>} */
31 remoting.VideoFrameRecorder.prototype.getExtensionTypes = function() {
32 return [remoting.VideoFrameRecorder.EXTENSION_TYPE];
23 }; 33 };
24 34
25 /** 35 /**
26 * Starts or stops video recording. 36 * @param {function(string,string)} sendMessageToHost Callback to send a message
37 * to the host.
27 */ 38 */
28 remoting.VideoFrameRecorder.prototype.startStopRecording = function() { 39 remoting.VideoFrameRecorder.prototype.startExtension =
29 var data = {}; 40 function(sendMessageToHost) {
30 if (this.isRecording_) { 41 this.sendMessageToHostCallback_ = sendMessageToHost;
31 this.isRecording_ = false; 42 };
32 data = { type: 'stop' }
33 43
34 chrome.fileSystem.chooseEntry( 44 /**
35 {type: 'saveFile', suggestedName: 'videoRecording.pb'}, 45 * @param {Object} data The data to send.
36 this.onFileChosen_.bind(this)); 46 * @private
37 } else { 47 */
38 this.isRecording_ = true; 48 remoting.VideoFrameRecorder.prototype.sendMessageToHost_ = function(data) {
39 data = { type: 'start' } 49 this.sendMessageToHostCallback_(remoting.VideoFrameRecorder.EXTENSION_TYPE,
40 } 50 JSON.stringify(data));
41 this.plugin_.sendClientMessage('video-recorder', JSON.stringify(data));
42 } 51 }
43 52
44 /** 53 /**
45 * Returns true if the session is currently being recorded.
46 * @return {boolean}
47 */
48 remoting.VideoFrameRecorder.prototype.isRecording = function() {
49 return this.isRecording_;
50 }
51
52 /**
53 * Handles 'video-recorder' extension messages and returns true. Returns 54 * Handles 'video-recorder' extension messages and returns true. Returns
54 * false for all other message types. 55 * false for all other message types.
55 * 56 *
56 * @param {string} type Type of extension message. 57 * @param {string} type Type of extension message.
57 * @param {Object} message The parsed extension message data. 58 * @param {Object} message The parsed extension message data.
58 * @return {boolean} 59 * @return {boolean}
59 */ 60 */
60 remoting.VideoFrameRecorder.prototype.handleMessage = 61 remoting.VideoFrameRecorder.prototype.onExtensionMessage =
61 function(type, message) { 62 function(type, message) {
62 if (type != 'video-recorder') { 63 base.debug.assert(type == remoting.VideoFrameRecorder.EXTENSION_TYPE);
63 return false;
64 }
65 64
66 var messageType = base.getStringAttr(message, 'type'); 65 var messageType = base.getStringAttr(message, 'type');
67 var messageData = base.getStringAttr(message, 'data'); 66 var messageData = base.getStringAttr(message, 'data');
68 67
69 if (messageType == 'next-frame-reply') { 68 if (messageType == 'next-frame-reply') {
70 if (!this.fileWriter_) { 69 if (!this.fileWriter_) {
71 console.log("Received frame but have no writer"); 70 console.log("Received frame but have no writer");
72 return true; 71 return true;
73 } 72 }
74 if (!messageData) { 73 if (!messageData) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 this.fileWriter_.write(videoPacketBlob); 107 this.fileWriter_.write(videoPacketBlob);
109 108
110 return true; 109 return true;
111 } 110 }
112 111
113 console.log("Unrecognized message: " + messageType); 112 console.log("Unrecognized message: " + messageType);
114 return true; 113 return true;
115 } 114 }
116 115
117 /** 116 /**
117 * Starts or stops video recording.
118 */
119 remoting.VideoFrameRecorder.prototype.startStopRecording = function() {
120 var data = {};
121 if (this.isRecording_) {
122 this.isRecording_ = false;
123 data = { type: 'stop' }
124
125 chrome.fileSystem.chooseEntry(
126 {type: 'saveFile', suggestedName: 'videoRecording.pb'},
127 this.onFileChosen_.bind(this));
128 } else {
129 this.isRecording_ = true;
130 data = { type: 'start' }
131 }
132 this.sendMessageToHost_(data);
133 }
134
135 /**
136 * Returns true if the session is currently being recorded.
137 * @return {boolean}
138 */
139 remoting.VideoFrameRecorder.prototype.isRecording = function() {
140 return this.isRecording_;
141 }
142
143 /**
118 * @param {Entry} entry The single file entry if multiple files are not allowed. 144 * @param {Entry} entry The single file entry if multiple files are not allowed.
119 * @param {Array<FileEntry>} fileEntries List of file entries if multiple files 145 * @param {Array<FileEntry>} fileEntries List of file entries if multiple files
120 * are allowed. 146 * are allowed.
121 */ 147 */
122 remoting.VideoFrameRecorder.prototype.onFileChosen_ = function( 148 remoting.VideoFrameRecorder.prototype.onFileChosen_ = function(
123 entry, fileEntries) { 149 entry, fileEntries) {
124 if (!entry) { 150 if (!entry) {
125 console.log("Cancelled save of video frames."); 151 console.log("Cancelled save of video frames.");
126 } else { 152 } else {
127 chrome.fileSystem.getDisplayPath(entry, function(path) { 153 chrome.fileSystem.getDisplayPath(entry, function(path) {
(...skipping 12 matching lines...) Expand all
140 } 166 }
141 167
142 remoting.VideoFrameRecorder.prototype.onWriteComplete_ = function(e) { 168 remoting.VideoFrameRecorder.prototype.onWriteComplete_ = function(e) {
143 console.log("Video frame write complete"); 169 console.log("Video frame write complete");
144 this.fetchNextFrame_(); 170 this.fetchNextFrame_();
145 } 171 }
146 172
147 remoting.VideoFrameRecorder.prototype.fetchNextFrame_ = function() { 173 remoting.VideoFrameRecorder.prototype.fetchNextFrame_ = function() {
148 console.log("Request next video frame"); 174 console.log("Request next video frame");
149 var data = { type: 'next-frame' } 175 var data = { type: 'next-frame' }
150 this.plugin_.sendClientMessage('video-recorder', JSON.stringify(data)); 176 this.sendMessageToHost_(data);
151 } 177 }
OLDNEW
« no previous file with comments | « remoting/webapp/crd/js/desktop_remoting.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698