From b455a8eb63a46b082aea235c469cc15834dfd4dd Mon Sep 17 00:00:00 2001 From: Mark Vayngrib Date: Mon, 1 Jun 2015 11:13:36 -0400 Subject: [PATCH] support options object in constructor, onmessage parameter to constructor --- UdpSocket.ios.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/UdpSocket.ios.js b/UdpSocket.ios.js index d09ee0b..1c9cae2 100644 --- a/UdpSocket.ios.js +++ b/UdpSocket.ios.js @@ -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 }