-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
25 lines (21 loc) · 1000 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
const EventEmitter2 = require('eventemitter2')
class Plugin extends EventEmitter2 {
constructor (opts, api, mirror) {
super()
if (!mirror) {
mirror = new Plugin(opts, api, this)
}
this.mirror = mirror
}
connect () { this._connected = true; this.emit('connect'); return Promise.resolve(null) }
disconnect () { this._connected = false; this.emit('disconnect'); return Promise.resolve(null) }
isConnected () { return this._connected }
sendData (data) { return Promise.resolve(this.mirror._dataHandler ? this.mirror._dataHandler(data) : null) }
registerDataHandler (handler) { this._dataHandler = handler }
deregisterDataHandler (handler) { delete this._dataHandler }
sendMoney (amount) { return Promise.resolve(this.mirror._moneyHandler ? this.mirror._moneyHandler(amount) : null) }
registerMoneyHandler (handler) { this._moneyHandler = handler }
deregisterMoneyHandler (handler) { delete this._moneyHandler }
}
Plugin.version = 2
module.exports = Plugin