Skip to content

Commit

Permalink
Fix a bug that will accidentally remove the last connection from the …
Browse files Browse the repository at this point in the history
…connections array (#128)
  • Loading branch information
cheton committed Feb 13, 2017
1 parent 7228ea5 commit 2461181
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
11 changes: 6 additions & 5 deletions src/app/controllers/Grbl/GrblController.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ class GrblController {
return {
port: this.options.port,
baudrate: this.options.baudrate,
connections: _.size(this.connections),
connections: this.connections.map(c => c.socket.id),
ready: this.ready,
controller: {
type: this.type,
Expand Down Expand Up @@ -497,6 +497,8 @@ class GrblController {
return !(this.isOpen());
}
addConnection(socket) {
log.debug(`[Grbl] Add socket connection: id=${socket.id}`);

this.connections.push(new Connection(socket));

if (!_.isEmpty(this.state)) {
Expand All @@ -510,10 +512,9 @@ class GrblController {
}
}
removeConnection(socket) {
const index = _.findIndex(this.connections, (c) => {
return c.socket === socket;
});
this.connections.splice(index, 1);
log.debug(`[Grbl] Remove socket connection: id=${socket.id}`);

this.connections = this.connections.filter(c => (c.socket.id !== socket.id));
}
emitAll(eventName, ...args) {
this.connections.forEach((c) => {
Expand Down
11 changes: 6 additions & 5 deletions src/app/controllers/Smoothie/SmoothieController.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ class SmoothieController {
return {
port: this.options.port,
baudrate: this.options.baudrate,
connections: _.size(this.connections),
connections: this.connections.map(c => c.socket.id),
ready: this.ready,
controller: {
type: this.type,
Expand Down Expand Up @@ -453,6 +453,8 @@ class SmoothieController {
return !(this.isOpen());
}
addConnection(socket) {
log.debug(`[Smoothie] Add socket connection: id=${socket.id}`);

this.connections.push(new Connection(socket));

if (!_.isEmpty(this.state)) {
Expand All @@ -466,10 +468,9 @@ class SmoothieController {
}
}
removeConnection(socket) {
const index = _.findIndex(this.connections, (c) => {
return c.socket === socket;
});
this.connections.splice(index, 1);
log.debug(`[Smoothie] Remove socket connection: id=${socket.id}`);

this.connections = this.connections.filter(c => (c.socket.id !== socket.id));
}
emitAll(eventName, ...args) {
this.connections.forEach((c) => {
Expand Down
11 changes: 6 additions & 5 deletions src/app/controllers/TinyG/TinyGController.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ class TinyGController {
return {
port: this.options.port,
baudrate: this.options.baudrate,
connections: _.size(this.connections),
connections: this.connections.map(c => c.socket.id),
ready: this.ready,
controller: {
type: this.type,
Expand Down Expand Up @@ -505,6 +505,8 @@ class TinyGController {
return !(this.isOpen());
}
addConnection(socket) {
log.debug(`[TinyG] Add socket connection: id=${socket.id}`);

this.connections.push(new Connection(socket));

if (!_.isEmpty(this.state)) {
Expand All @@ -518,10 +520,9 @@ class TinyGController {
}
}
removeConnection(socket) {
const index = _.findIndex(this.connections, (c) => {
return c.socket === socket;
});
this.connections.splice(index, 1);
log.debug(`[TinyG] Remove socket connection: id=${socket.id}`);

this.connections = this.connections.filter(c => (c.socket.id !== socket.id));
}
emitAll(eventName, ...args) {
this.connections.forEach((c) => {
Expand Down

0 comments on commit 2461181

Please sign in to comment.