Skip to content

Commit

Permalink
Merge pull request #86 from laggingreflex/fix/75_lost-connections
Browse files Browse the repository at this point in the history
feat: forceReconnect
  • Loading branch information
Joel Griffith committed Feb 22, 2017
2 parents af55b54 + 59a8a71 commit b867eb5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ Flag that will turn on or off encrypted sync messages.

When true, this will tell `sicksync` to follow and sync files and folders that are symlinked. Defaults to `false` in setup.

`forceReconnect: {boolean}`

When true, this will tell `sicksync` to force reconnect in case of "close" event (default false). In case of "error" event it still reconnects regardless of this option.

## Migrating to from 1.x to 2.x

2.x introduces a number of new and breaking changes. It's worthwhile to upgrade, as sicksync now has better reliabitiliy, new functionality, and extensibility in 2.x. Aside from command-line changes, sicksync 2.x also introduces a breaking config change as well. Below are the steps you'll need to run in order to migrate to sicksync 2.x:
Expand Down
1 change: 1 addition & 0 deletions src/local/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ function startProject(config, projectConf) {
websocketPort: projectConf.websocketPort,
secret: secret,
prefersEncrypted: projectConf.prefersEncrypted,
forceReconnect: projectConf.forceReconnect,
});

// WS events
Expand Down
10 changes: 9 additions & 1 deletion src/local/ws-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class WSClient extends EventEmitter {
this._hostname = params.hostname;
this._webSocketPort = params.websocketPort;
this._username = params.username;
this._forceReconnect = params.forceReconnect;

this._startDevBox();
this._reconnect();
Expand All @@ -38,8 +39,15 @@ export class WSClient extends EventEmitter {
_connect() {
this._ws = new WebSocket('ws://' + this._hostname + ':' + this._webSocketPort);
this._ws.on('open', _.partial(this.emit.bind(this), wsEvents.READY));
this._ws.on('close', this._handleDisconnect.bind(this));
this._ws.on('error', this._reconnect.bind(this));
this._ws.on('close', () => {
if (this._forceReconnect) {
this._startDevBox();
this._reconnect();
} else {
this._handleDisconnect();
}
});
}

_handleDisconnect() {
Expand Down
5 changes: 5 additions & 0 deletions src/project-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ export const add = (config) => {
default: 'no',
before: util.toBoolean,
},
forceReconnect: {
description: 'Should sicksync force reconnect on "close"?',
default: 'no',
before: util.toBoolean,
},
};

if (_.isUndefined(config.debug)) {
Expand Down

0 comments on commit b867eb5

Please sign in to comment.