Skip to content

Instantly share code, notes, and snippets.

@buesing
Created June 28, 2019 10:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save buesing/e2257c3a4e1450a205d5255056b27047 to your computer and use it in GitHub Desktop.
Save buesing/e2257c3a4e1450a205d5255056b27047 to your computer and use it in GitHub Desktop.
connectToServer(host) {
// connect to the deepstream server
return new Promise((resolve, reject) => {
setTimeout(() => {
reject('timeout');
}, 2000);
this.client = deepstream(host, {
mergeStrategy: deepstream.MERGE_STRATEGIES.REMOTE_WINS,
});
this.client.login();
this.client.on('error', e => {
reject(e);
});
this.client.on('connectionStateChanged', e => {
if (e === deepstream.CONSTANTS.CONNECTION_STATE.OPEN) {
resolve();
}
if (e === deepstream.CONSTANTS.CONNECTION_STATE.ERROR) {
reject('error');
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment