connection-dashboard-extension-worona
Advanced tools
Comparing version 1.3.0 to 1.3.1
{ | ||
"name": "connection-dashboard-extension-worona", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "Extension for the Worona Dashboard in charge of the connection to the server.", | ||
@@ -38,6 +38,5 @@ "scripts": { | ||
"dependencies": { | ||
"asteroid": "^2.0.2", | ||
"ws": "^1.1.0" | ||
"worona-asteroid": "^1.0.1" | ||
}, | ||
"devDependencies": {} | ||
} |
import * as types from '../types'; | ||
import stringifyError from 'stringify-error-message'; | ||
@@ -7,4 +6,3 @@ export const connectionStarted = () => ({ type: types.CONNECTION_STARTED }); | ||
export const connectionSucceed = () => ({ type: types.CONNECTION_SUCCEED }); | ||
export const connectionFailed = errorObj => | ||
({ type: types.CONNECTION_FAILED, error: stringifyError(errorObj) }); | ||
export const connectionFailed = error => ({ type: types.CONNECTION_FAILED, error }); | ||
export const disconnected = error => ({ type: types.DISCONNECTED, error }); |
import { isRemote } from 'worona-deps'; | ||
export const url = isRemote ? 'wss://meteor.worona.io/websocket' : 'ws://localhost:3000/websocket'; | ||
export const endpoint = isRemote ? 'wss://meteor.worona.io/websocket' : 'ws://localhost:3000/websocket'; | ||
export const timeout = 10000; |
/* eslint-disable class-methods-use-this */ | ||
import { createClass } from 'asteroid'; | ||
import { eventChannel } from 'redux-saga'; | ||
import { url } from '../config'; | ||
import Connection from 'worona-asteroid'; | ||
import { endpoint } from '../config'; | ||
const Asteroid = createClass(); | ||
const connection = new Connection({ endpoint }); | ||
export class Connection { | ||
constructor(options = {}) { | ||
this.url = options.url || url; | ||
this.client = null; | ||
} | ||
start() { | ||
this.client = new Asteroid({ | ||
autoConnect: false, | ||
autoReconnect: false, | ||
maintainCollections: true, | ||
ddpVersion: '1', | ||
endpoint: this.url, | ||
}); | ||
} | ||
connect() { | ||
this.client.ddp.connect(); | ||
} | ||
connectedEventChannel() { | ||
return eventChannel(listener => { | ||
const connected = this.client.ddp.on('connected', () => { | ||
listener('connected'); | ||
}); | ||
return () => { | ||
this.client.ddp.removeListener('connected', connected); | ||
}; | ||
}); | ||
} | ||
disconnectedEventChannel() { | ||
return eventChannel(listener => { | ||
const disconnected = this.client.ddp.on('disconnected', () => { | ||
listener('disconnected'); | ||
}); | ||
return () => { | ||
this.client.ddp.removeListener('disconnected', disconnected); | ||
}; | ||
}); | ||
} | ||
call(...params) { | ||
return new Promise((resolve, reject) => { | ||
this.client.call(...params) | ||
.then(result => { | ||
if (typeof result === 'object' && result.errorType === 'Meteor.Error') { | ||
reject(result); | ||
} else { | ||
resolve(result); | ||
} | ||
}) | ||
.catch(error => reject(error)); | ||
}); | ||
} | ||
loginWithPassword(email, password) { | ||
return this.client.loginWithPassword({ email, password }); | ||
} | ||
loggedInEventChannel() { | ||
return eventChannel(listener => { | ||
const loggedIn = this.client.on('loggedIn', () => { | ||
listener(this.client.userId); | ||
}); | ||
return () => { | ||
this.client.removeListener('loggedIn', loggedIn); | ||
}; | ||
}); | ||
} | ||
loggedOutEventChannel() { | ||
return eventChannel(listener => { | ||
const loggedOut = this.client.on('loggedOut', () => { | ||
listener('logout'); | ||
}); | ||
return () => { | ||
this.client.removeListener('loggedOut', loggedOut); | ||
}; | ||
}); | ||
} | ||
logout() { | ||
return this.client.logout(); | ||
} | ||
subscribe(...params) { | ||
return this.client.subscribe(...params); | ||
} | ||
unsubscribe(id) { | ||
this.client.unsubscribe(id); | ||
} | ||
collectionEventChannel(selectedCollection) { | ||
return eventChannel(listener => { | ||
const added = this.client.ddp.on('added', ({ collection, id, fields }) => { | ||
if (collection === selectedCollection) { | ||
listener({ collection: selectedCollection, event: 'added', id, fields }); | ||
} | ||
}); | ||
const changed = this.client.ddp.on('changed', ({ collection, id, fields }) => { | ||
if (collection === selectedCollection) { | ||
listener({ collection: selectedCollection, event: 'changed', id, fields }); | ||
} | ||
}); | ||
const removed = this.client.ddp.on('removed', ({ collection, id, fields }) => { | ||
if (collection === selectedCollection) { | ||
listener({ collection: selectedCollection, event: 'removed', id, fields }); | ||
} | ||
}); | ||
return () => { | ||
this.client.ddp.removeListener('added', added); | ||
this.client.ddp.removeListener('changed', changed); | ||
this.client.ddp.removeListener('removed', removed); | ||
}; | ||
}); | ||
} | ||
readyEventChannel(subscription) { | ||
return eventChannel(listener => { | ||
const ready = subscription.on('ready', () => { | ||
listener({ subscription: subscription.name }); | ||
}); | ||
return () => { | ||
subscription.removeListener('ready', ready); | ||
}; | ||
}); | ||
} | ||
errorEventChannel(subscription) { | ||
return eventChannel(listener => { | ||
const error = subscription.on('error', err => { | ||
listener({ subscription: subscription.name, error: err }); | ||
}); | ||
return () => { | ||
subscription.removeListener('error', error); | ||
}; | ||
}); | ||
} | ||
} | ||
const connection = new Connection(); | ||
export const start = connection.start.bind(connection); | ||
@@ -152,0 +8,0 @@ export const connect = connection.connect.bind(connection); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1
8689
14
176
+ Addedworona-asteroid@^1.0.1
+ Addedredux-saga@0.14.8(transitive)
+ Addedworona-asteroid@1.0.1(transitive)
- Removedasteroid@^2.0.2
- Removedws@^1.1.0
- Removedoptions@0.0.6(transitive)
- Removedultron@1.0.2(transitive)
- Removedws@1.1.5(transitive)