Skip to content

Commit 6211711

Browse files
committed
Prettify
1 parent 7673dc2 commit 6211711

File tree

2 files changed

+34
-36
lines changed

2 files changed

+34
-36
lines changed

src/qimessaging.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,17 @@ export class QiSession {
4848
this._sigs = [];
4949
this._idm = 0;
5050

51-
this._socket.on('reply', (data: any) => {this.onReply(data)});
51+
this._socket.on('reply', (data: any) => {
52+
this.onReply(data);
53+
});
5254

53-
this._socket.on('error', (data: any) => {this.onError(data)});
55+
this._socket.on('error', (data: any) => {
56+
this.onError(data);
57+
});
5458

55-
this._socket.on('signal', (data: any) => {this.onSignal(data)});
59+
this._socket.on('signal', (data: any) => {
60+
this.onSignal(data);
61+
});
5662

5763
this._socket.on('disconnect', this.onDisconnect);
5864

@@ -61,13 +67,12 @@ export class QiSession {
6167
this.service = this.createMetaCall('ServiceDirectory', 'service', 'data');
6268
}
6369

64-
isConnected () {
65-
const connected : boolean =
66-
(this._socket !== undefined) ?
67-
this._socket.socket.connected : false;
70+
isConnected() {
71+
const connected: boolean =
72+
this._socket !== undefined ? this._socket.socket.connected : false;
6873
return connected;
6974
}
70-
75+
7176
onReply(data: any) {
7277
const idm = data['idm'];
7378
if (
@@ -207,5 +212,4 @@ export class QiSession {
207212

208213
return signalObject;
209214
}
210-
211215
}

src/widget.ts

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@ export class NaoRobotModel extends DOMWidgetModel {
5454

5555
private validateIPaddress(ipAddress: string) {
5656
// TODO: validate port also
57-
if (ipAddress == 'nao.local') {
57+
if (ipAddress === 'nao.local') {
5858
return true;
5959
} else {
60-
const regexp = new RegExp('^((25[0-5]|(2[0-4]|1[0-9]|[1-9]|)[0-9])(\.(?!$)|$)){4}$');
60+
const regexp = new RegExp(
61+
'^((25[0-5]|(2[0-4]|1[0-9]|[1-9]|)[0-9])(.(?!$)|$)){4}$'
62+
);
6163
return regexp.test(ipAddress);
6264
}
6365
}
@@ -83,16 +85,16 @@ export class NaoRobotModel extends DOMWidgetModel {
8385
this.set('connected', 'Connected');
8486
this.save_changes();
8587
this.changeStatus('Available');
86-
console.log("Connection successful after ", i/10.0, " seconds.");
88+
console.log('Connection successful after ', i / 10.0, ' seconds.');
8789
break;
8890
}
8991
}
9092

9193
// Handle connection failure
9294
if (!this.qiSession.isConnected()) {
93-
console.error("Connection to ", ipAddress, " could not be established.");
95+
console.error('Connection to ', ipAddress, ' could not be established.');
9496
this.changeStatus('Unavailable');
95-
}
97+
}
9698
}
9799

98100
disconnect() {
@@ -103,26 +105,21 @@ export class NaoRobotModel extends DOMWidgetModel {
103105
this.changeStatus('Unavailable');
104106
}
105107

106-
107-
private async createService(
108-
serviceName: string,
109-
) {
108+
private async createService(serviceName: string) {
110109
this.changeStatus('Creating service ' + serviceName);
111110
const servicePromise = this.qiSession.service(serviceName);
112111

113-
const naoService = await servicePromise.then(
114-
(resolution: object) => {
112+
const naoService = await servicePromise
113+
.then((resolution: any) => {
115114
return resolution;
116-
}
117-
).catch(
118-
(rejection: string) => {
115+
})
116+
.catch((rejection: string) => {
119117
this.changeStatus(rejection);
120118
return rejection;
121-
}
122-
);
119+
});
123120

124121
// Store service only when successfully created
125-
if (typeof(naoService) === 'object') {
122+
if (typeof naoService === 'object') {
126123
this._services[serviceName] = naoService;
127124
this.changeStatus(serviceName + ' available');
128125
}
@@ -143,27 +140,25 @@ export class NaoRobotModel extends DOMWidgetModel {
143140
this.changeStatus('Running method ' + methodName);
144141

145142
const servicePromise = this._services[serviceName][methodName](...args);
146-
await servicePromise.then(
147-
(resolution: any) => {
143+
await servicePromise
144+
.then((resolution: any) => {
148145
this.changeStatus('Task completed');
149146
if (resolution !== undefined) {
150-
this.send(resolution)
147+
this.send(resolution);
151148
}
152-
}
153-
).catch(
154-
(rejection: string) => {
149+
})
150+
.catch((rejection: string) => {
155151
this.changeStatus(rejection);
156152
this.send(rejection);
157-
}
158-
);
153+
});
159154

160155
this.set('counter', this.get('counter') + 1);
161156
this.save_changes();
162157
}
163158

164159
private async onCommand(commandData: any, buffers: any) {
165160
const cmd = commandData['command'];
166-
161+
167162
switch (cmd) {
168163
case 'connect':
169164
await this.connect(commandData['ipAddress'], commandData['port']);
@@ -186,7 +181,6 @@ export class NaoRobotModel extends DOMWidgetModel {
186181
);
187182
break;
188183
}
189-
190184
}
191185

192186
static serializers: ISerializers = {

0 commit comments

Comments
 (0)