support options object in constructor, onmessage parameter to constructor

This commit is contained in:
Mark Vayngrib 2015-06-01 11:13:36 -04:00
parent 2d589e62ad
commit b455a8eb63
1 changed files with 7 additions and 3 deletions

View File

@ -26,10 +26,12 @@ var STATE = {
BOUND: 2
}
function UdpSocket(type) {
function UdpSocket(options, onmessage) {
EventEmitter.call(this)
this.type = type
if (typeof options === 'string') options = { type: options }
this.type = options.type
this._id = instances++
this._state = STATE.UNBOUND
this._subscription = DeviceEventEmitter.addListener(
@ -39,8 +41,10 @@ function UdpSocket(type) {
// ensure compatibility with node's EventEmitter
if (!this.on) this.on = this.addListener.bind(this)
if (onmessage) this.on('message', onmessage)
Sockets.createSocket(this._id, {
type: type || 'udp4'
type: this.type
}) // later
}