Skip to content

Commit 820fa0f

Browse files
committed
Removed duplicated file and move files to folder for better overview.
1 parent d605651 commit 820fa0f

File tree

11 files changed

+106
-364
lines changed

11 files changed

+106
-364
lines changed

src/protocol/low-level/bluetooth/low_energy/device.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ cwc.protocol.bluetooth.lowEnergy.Device.prototype.listen = function(
110110
this.characteristic_[characteristicId]['startNotifications']().then(() => {
111111
this.log.info('Adding event listener for', characteristicId);
112112
this.characteristic_[characteristicId]['addEventListener'](
113-
'characteristicvaluechanged', function(e) {
114-
func(e.target.value.buffer);
113+
'characteristicvaluechanged', (e) => {
114+
this.handleData_(e.target.value.buffer, func);
115115
});
116116
});
117117
};
@@ -225,6 +225,15 @@ cwc.protocol.bluetooth.lowEnergy.Device.prototype.connectCharacteristic_ =
225225
};
226226

227227

228-
cwc.protocol.bluetooth.lowEnergy.Device.prototype.handleData_ = function(e) {
229-
console.log('Data', e.target, e.target.value);
228+
/**
229+
* @param {?} data
230+
* @param {?} callback
231+
*/
232+
cwc.protocol.bluetooth.lowEnergy.Device.prototype.handleData_ = function(data,
233+
callback) {
234+
if (!data) {
235+
return;
236+
}
237+
console.log('Data', data);
238+
callback(data);
230239
};

src/runner/runnerConnector.js

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,6 @@ cwc.runner.Connector = function(helper, name = 'Runner Connector') {
5858
/** @type {!boolean} */
5959
this.listen = false;
6060

61-
/** @private {!cwc.utils.Events} */
62-
this.events_ = new cwc.utils.Events(this.name);
63-
64-
/** @type {!boolean} */
65-
this.directUpdate = false;
66-
6761
/** @type {!string} */
6862
this.token = String(new Date().getTime());
6963

@@ -76,21 +70,24 @@ cwc.runner.Connector = function(helper, name = 'Runner Connector') {
7670
/** @type {!number} */
7771
this.pingTestWorker = 0;
7872

73+
/** @private {!cwc.utils.Events} */
74+
this.events_ = new cwc.utils.Events(this.name);
75+
7976
/** @private {!cwc.utils.Logger} */
8077
this.log_ = new cwc.utils.Logger(this.name);
8178
};
8279

8380

8481
/**
8582
* Inits the runner instance.
86-
* @param {boolean=} opt_listen
83+
* @param {boolean=} listen
8784
*/
88-
cwc.runner.Connector.prototype.init = function(opt_listen) {
89-
if (opt_listen) {
85+
cwc.runner.Connector.prototype.init = function(listen) {
86+
if (listen) {
9087
this.events_.listen(window, 'message', this.handleMessage_, false, this);
9188
this.listen = true;
9289
}
93-
this.addCommand('__direct_update__', this.enableDirectUpdate_, this);
90+
this.addCommand('__gamepad__', this.handleGamepad_, this);
9491
this.addCommand('__handshake__', this.handleHandshake_, this);
9592
this.addCommand('__pong__', this.handlePong_, this);
9693
};
@@ -113,15 +110,15 @@ cwc.runner.Connector.prototype.setTarget = function(target) {
113110

114111
/**
115112
* @param {string!} command
116-
* @param {Object|number|string|Array=} optValue
113+
* @param {Object|number|string|Array=} value
117114
*/
118-
cwc.runner.Connector.prototype.send = function(command, optValue) {
115+
cwc.runner.Connector.prototype.send = function(command, value) {
119116
if (!this.target || !this.target.contentWindow || !this.targetLoaded) {
120117
return;
121118
}
122119

123120
this.target.contentWindow.postMessage({
124-
'command': command, 'value': optValue},
121+
'command': command, 'value': value},
125122
this.targetOrigin);
126123
};
127124

@@ -138,15 +135,6 @@ cwc.runner.Connector.prototype.start = function() {
138135
};
139136

140137

141-
/**
142-
* @private
143-
*/
144-
cwc.runner.Connector.prototype.enableDirectUpdate_ = function() {
145-
this.log_.info('Enabled direct update ...');
146-
this.directUpdate = true;
147-
};
148-
149-
150138
/**
151139
* @param {!string} name
152140
* @param {!function(?)} func
@@ -198,27 +186,27 @@ cwc.runner.Connector.prototype.addCommandProfile = function(profile, scope) {
198186

199187
/**
200188
* @param {!function(?)} func
201-
* @param {?=} opt_scope
189+
* @param {?=} scope
202190
* @export
203191
*/
204-
cwc.runner.Connector.prototype.setStartEvent = function(func, opt_scope) {
205-
this.addCommand('__start__', func, opt_scope);
192+
cwc.runner.Connector.prototype.setStartEvent = function(func, scope) {
193+
this.addCommand('__start__', func, scope);
206194
};
207195

208196

209197
/**
210198
* @param {!string} name
211199
* @param {!function(?)} func
212-
* @param {?=} opt_scope
200+
* @param {?=} scope
213201
* @export
214202
*/
215-
cwc.runner.Connector.prototype.addMonitor = function(name, func, opt_scope) {
203+
cwc.runner.Connector.prototype.addMonitor = function(name, func, scope) {
216204
if (!func) {
217205
this.log_.error('Runner monitor function is undefined for', name);
218206
return;
219207
}
220-
if (opt_scope) {
221-
this.monitor[name] = func.bind(opt_scope);
208+
if (scope) {
209+
this.monitor[name] = func.bind(scope);
222210
} else {
223211
this.monitor[name] = func;
224212
}
@@ -311,11 +299,11 @@ cwc.runner.Connector.prototype.ping = function() {
311299

312300

313301
/**
314-
* @param {boolean=} opt_disable
302+
* @param {boolean=} disable
315303
* @export
316304
*/
317-
cwc.runner.Connector.prototype.pingTest = function(opt_disable) {
318-
if (opt_disable && this.pingTestWorker) {
305+
cwc.runner.Connector.prototype.pingTest = function(disable) {
306+
if (disable && this.pingTestWorker) {
319307
clearInterval(this.pingTestWorker);
320308
} else if (!this.pingTestWorker) {
321309
this.pingTestWorker = setInterval(this.ping.bind(this), 0);
@@ -324,10 +312,9 @@ cwc.runner.Connector.prototype.pingTest = function(opt_disable) {
324312

325313

326314
/**
327-
* @param {goog.events.BrowserEvent=} opt_event
328315
* @private
329316
*/
330-
cwc.runner.Connector.prototype.handleContentLoad_ = function(opt_event) {
317+
cwc.runner.Connector.prototype.handleContentLoad_ = function() {
331318
this.targetLoaded = true;
332319
};
333320

@@ -348,6 +335,14 @@ cwc.runner.Connector.prototype.handleMessage_ = function(event) {
348335
};
349336

350337

338+
/**
339+
* @private
340+
*/
341+
cwc.runner.Connector.prototype.handleGamepad_ = function() {
342+
console.log('Enable Gamepad Support');
343+
};
344+
345+
351346
/**
352347
* @param {!string} token
353348
* @private

src/ui/runner/runner.js

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -61,27 +61,18 @@ cwc.ui.Runner = function(helper) {
6161
/** @type {Element} */
6262
this.nodeRuntime = null;
6363

64-
/** @type {Element} */
65-
this.nodeToolbar = null;
66-
6764
/** @type {Element} */
6865
this.nodeTerminal = null;
6966

7067
/** @type {Element} */
7168
this.nodeInfo = null;
7269

73-
/** @type {Element} */
74-
this.nodeStatusbar = null;
75-
7670
/** @type {Element} */
7771
this.nodeOverlay = null;
7872

7973
/** @type {Element} */
8074
this.nodeTurtle = null;
8175

82-
/** @type {Element} */
83-
this.nodeInfobar = null;
84-
8576
/** @type {Element} */
8677
this.nodeMonitor = null;
8778

@@ -130,9 +121,6 @@ cwc.ui.Runner = function(helper) {
130121
/** @type {number} */
131122
this.stopTime = 0;
132123

133-
/** @type {string} */
134-
this.targetOrigin = '*';
135-
136124
/** @type {?function()} */
137125
this.externalCleanUp = null;
138126

@@ -166,23 +154,25 @@ cwc.ui.Runner.prototype.decorate = function(node) {
166154
this.nodeTurtle = goog.dom.getElement(this.prefix + 'turtle');
167155

168156
// Toolbar
169-
this.nodeToolbar = goog.dom.getElement(this.prefix + 'toolbar-chrome');
170-
if (this.nodeToolbar) {
157+
let nodeToolbar = goog.dom.getElement(this.prefix + 'toolbar-chrome');
158+
if (nodeToolbar) {
171159
this.toolbar = new cwc.ui.RunnerToolbar(this.helper);
172-
this.toolbar.decorate(this.nodeToolbar);
160+
this.toolbar.decorate(nodeToolbar);
173161
}
174162

175163
// Statusbar
176-
this.nodeStatusbar = goog.dom.getElement(this.prefix + 'statusbar');
177-
if (this.nodeStatusbar) {
164+
let nodeStatusbar = goog.dom.getElement(this.prefix + 'statusbar');
165+
if (nodeStatusbar) {
178166
this.statusbar = new cwc.ui.Statusbar(this.helper);
179-
this.statusbar.decorate(this.nodeStatusbar);
167+
this.statusbar.decorate(nodeStatusbar);
180168
}
181169

182170
// Infobar
183-
this.nodeInfobar = goog.dom.getElement(this.prefix + 'infobar');
184-
this.infobar = new cwc.ui.RunnerInfobar(this.helper);
185-
this.infobar.decorate(this.nodeInfobar);
171+
let nodeInfobar = goog.dom.getElement(this.prefix + 'infobar');
172+
if (nodeInfobar) {
173+
this.infobar = new cwc.ui.RunnerInfobar(this.helper);
174+
this.infobar.decorate(nodeInfobar);
175+
}
186176

187177
// Monitor
188178
this.nodeMonitor = goog.dom.getElement(this.prefix + 'monitor');

0 commit comments

Comments
 (0)