-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Some bugfixes #69
base: master
Are you sure you want to change the base?
Some bugfixes #69
Changes from 3 commits
e8f2f76
9159a00
7db837b
2e3c9ee
649e140
71a28db
ea65a18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
"name": "react-native-zeroconf", | ||
"version": "0.9.0", | ||
"description": "A Zeroconf discovery utility for react-native", | ||
"main": "dist", | ||
"main": "src", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I doubt this is right There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don´t use minifying ;) |
||
"scripts": { | ||
"lint": "eslint src/*.js", | ||
"build": "rm -rf dist && mkdir dist && babel src -o dist/index.js" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ export default class Zeroconf extends EventEmitter { | |
super(props) | ||
|
||
this._services = {} | ||
this._resolvedServices = {} | ||
this._dListeners = {} | ||
|
||
this.addDeviceListeners() | ||
|
@@ -20,7 +21,7 @@ export default class Zeroconf extends EventEmitter { | |
addDeviceListeners () { | ||
|
||
if (Object.keys(this._dListeners).length) { | ||
return this.emit('error', new Error('RNZeroconf listeners already in place.')) | ||
return this.emit('error', 'RNZeroconf listeners already in place.') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why emit a simple string? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I only want to know if an error has ocurred (string is enough). If you pass an Error, you will get a red screen in debug mode, and an app crash in release mode There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fair |
||
} | ||
|
||
this._dListeners.start = DeviceEventEmitter.addListener('RNZeroconfStart', () => this.emit('start')) | ||
|
@@ -32,8 +33,8 @@ export default class Zeroconf extends EventEmitter { | |
const { name } = service | ||
|
||
this._services[name] = service | ||
this.emit('found', name) | ||
this.emit('update') | ||
this.emit('found', service) | ||
this.emit('update', service) | ||
}) | ||
|
||
this._dListeners.remove = DeviceEventEmitter.addListener('RNZeroconfRemove', service => { | ||
|
@@ -42,16 +43,17 @@ export default class Zeroconf extends EventEmitter { | |
|
||
delete this._services[name] | ||
|
||
this.emit('remove', name) | ||
this.emit('update') | ||
this.emit('remove', service) | ||
this.emit('update', service) | ||
}) | ||
|
||
this._dListeners.resolved = DeviceEventEmitter.addListener('RNZeroconfResolved', service => { | ||
if (!service || !service.name) { return } | ||
|
||
this._resolvedServices[service.name] = service | ||
this._services[service.name] = service | ||
this.emit('resolved', service) | ||
this.emit('update') | ||
this.emit('update', service) | ||
}) | ||
|
||
} | ||
|
@@ -65,27 +67,35 @@ export default class Zeroconf extends EventEmitter { | |
} | ||
|
||
/** | ||
* Get all the services already resolved | ||
* Get all the services fully resolved or not | ||
*/ | ||
getServices () { | ||
return this._services | ||
} | ||
|
||
/** | ||
* Get all the services fully resolved | ||
*/ | ||
getResolvedServices () { | ||
return this._resolvedServices | ||
} | ||
|
||
/** | ||
* Scan for Zeroconf services, | ||
* Defaults to _http._tcp. on local domain | ||
*/ | ||
scan (type = 'http', protocol = 'tcp', domain = 'local.') { | ||
this._services = {} | ||
this.emit('update') | ||
this._resolvedServices = {} | ||
this.emit('start') | ||
RNZeroconf.scan(type, protocol, domain) | ||
} | ||
|
||
/** | ||
* Stop current scan if any | ||
*/ | ||
stop () { | ||
RNZeroconf.stop() | ||
async stop () { | ||
await RNZeroconf.stop() | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use a simple ternary here to avoid repeating the same code, and send the errorString instead of the params if it's defined.
From my understanding, the errorString couldn't work because it was a String instead of an Object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, sorry this block is wrong. I´m going to upload a fix for this ;)