Make the client in load.

This commit is contained in:
wescoeur 2015-12-02 15:00:38 +01:00
parent 2471ad4215
commit 9983407c8b

View File

@ -7,65 +7,63 @@ export const configurationSchema = {
type: 'object',
properties: {
transport: {
type: 'object',
properties: {
host: {
type: 'string',
description: 'host where the XMPP server is located'
},
port: {
type: 'integer',
description: 'port of the XMPP server (default to 5222)',
default: 5222
},
jid: {
type: 'string',
title: 'user',
description: 'Xmpp address to use to authenticate'
},
password: {
type: 'string',
description: 'password to use to authenticate'
}
},
additionalProperties: false,
required: ['jid', 'password']
host: {
type: 'string',
description: 'host where the XMPP server is located'
},
port: {
type: 'integer',
description: 'port of the XMPP server (default to 5222)',
default: 5222
},
jid: {
type: 'string',
title: 'user',
description: 'Xmpp address to use to authenticate'
},
password: {
type: 'string',
description: 'password to use to authenticate'
}
},
additionalProperties: false,
required: ['transport']
required: ['jid', 'password']
}
// ===================================================================
class TransportXmppPlugin {
constructor (xo) {
this._sendToXmppClient = ::this._sendToXmppClient
this._set = ::xo.defineProperty
this._unset = null
// Defined in configure().
this._conf = null
// Defined in load().
this._client = null
}
async configure ({ transport: conf }) {
conf.reconnect = true
this._client = new XmppClient(conf)
this._client.on('error', () => {})
return eventToPromise(this._client.connection.socket, 'data')
.then(() => eventToPromise(this._client, 'online'))
configure (conf) {
this._conf = conf
this._conf.reconnect = true
}
load () {
async load () {
this._client = new XmppClient(this._conf)
this._client.on('error', () => {})
await eventToPromise(this._client.connection.socket, 'data')
await eventToPromise(this._client, 'online')
this._unset = this._set('sendToXmppClient', this._sendToXmppClient)
}
unload () {
this._unset()
this._client.end()
}
_sendToXmppClient ({to, message}) {