-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
58 lines (44 loc) · 1.38 KB
/
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const EventEmitter = require('eventemitter2')
const PaymentServerPlugin = require('./src/server')
const PaymentClientPlugin = require('./src/client')
class PaymentPlugin extends EventEmitter {
constructor (opts) {
super()
this._role = opts.role || 'client'
const InternalPluginClass = this._role === 'client' ? PaymentClientPlugin : PaymentServerPlugin
this._plugin = new InternalPluginClass(opts)
this._plugin.setSettler(this)
this._plugin.on('connect', () => this.emitAsync('connect'))
this._plugin.on('disconnect', () => this.emitAsync('disconnect'))
this._plugin.on('error', e => this.emitAsync('error', e))
}
async connect () {
return this._plugin.connect()
}
async disconnect () {
return this._plugin.disconnect()
}
isConnected () {
return this._plugin.isConnected()
}
async sendData (data) {
return this._plugin.sendData(data)
}
async sendMoney (amount) {
return this._plugin.sendMoney(amount)
}
registerDataHandler (dataHandler) {
return this._plugin.registerDataHandler(dataHandler)
}
deregisterDataHandler () {
return this._plugin.deregisterDataHandler()
}
registerMoneyHandler (moneyHandler) {
return this._plugin.registerMoneyHandler(moneyHandler)
}
deregisterMoneyHandler () {
return this._plugin.deregisterMoneyHandler()
}
}
PaymentPlugin.version = 2
module.exports = PaymentPlugin