use node-compatible event emitter
This commit is contained in:
parent
6f328cca63
commit
6827e29118
|
@ -12,8 +12,9 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var inherits = require('inherits')
|
||||||
|
var EventEmitter = require('events').EventEmitter
|
||||||
var React = require('react-native')
|
var React = require('react-native')
|
||||||
var mixInEventEmitter = require('mixInEventEmitter')
|
|
||||||
var DeviceEventEmitter = require('RCTDeviceEventEmitter')
|
var DeviceEventEmitter = require('RCTDeviceEventEmitter')
|
||||||
var Sockets = require('NativeModules').UdpSockets
|
var Sockets = require('NativeModules').UdpSockets
|
||||||
var base64 = require('base64-js')
|
var base64 = require('base64-js')
|
||||||
|
@ -26,6 +27,8 @@ var STATE = {
|
||||||
}
|
}
|
||||||
|
|
||||||
function UdpSocket(type) {
|
function UdpSocket(type) {
|
||||||
|
EventEmitter.call(this)
|
||||||
|
|
||||||
this._id = instances++
|
this._id = instances++
|
||||||
this._state = STATE.UNBOUND
|
this._state = STATE.UNBOUND
|
||||||
this._subscription = DeviceEventEmitter.addListener(
|
this._subscription = DeviceEventEmitter.addListener(
|
||||||
|
@ -40,6 +43,8 @@ function UdpSocket(type) {
|
||||||
}) // later
|
}) // later
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inherits(UdpSocket, EventEmitter)
|
||||||
|
|
||||||
UdpSocket.prototype._debug = function() {
|
UdpSocket.prototype._debug = function() {
|
||||||
// for now
|
// for now
|
||||||
var args = [].slice.call(arguments)
|
var args = [].slice.call(arguments)
|
||||||
|
@ -222,11 +227,4 @@ UdpSocket.prototype.unref = function() {
|
||||||
// anything?
|
// anything?
|
||||||
}
|
}
|
||||||
|
|
||||||
mixInEventEmitter(UdpSocket, {
|
|
||||||
'listening': true,
|
|
||||||
'message': true,
|
|
||||||
'close': true,
|
|
||||||
'error': true
|
|
||||||
})
|
|
||||||
|
|
||||||
module.exports = UdpSocket
|
module.exports = UdpSocket
|
|
@ -33,6 +33,9 @@
|
||||||
"homepage": "https://github.com/tradle/react-native-udp",
|
"homepage": "https://github.com/tradle/react-native-udp",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"base64-js": "0.0.8",
|
"base64-js": "0.0.8",
|
||||||
"react-native": "^0.4.2"
|
"events": "^1.0.2",
|
||||||
|
"inherits": "^2.0.1",
|
||||||
|
"react-native": "^0.4.2",
|
||||||
|
"util": "^0.10.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue