Use node-xmpp-client for the transport protocol
This commit is contained in:
parent
74a31f3301
commit
f266982560
@ -25,7 +25,8 @@
|
|||||||
"node": ">=0.12"
|
"node": ">=0.12"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"babel-runtime": "^5.8.34"
|
"babel-runtime": "^5.8.34",
|
||||||
|
"node-xmpp-client": "^3.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel": "^5.8.34",
|
"babel": "^5.8.34",
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
import XmppClient from 'node-xmpp-client'
|
||||||
|
|
||||||
|
// ===================================================================
|
||||||
|
|
||||||
export const configurationSchema = {
|
export const configurationSchema = {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
|
|
||||||
@ -11,27 +15,18 @@ export const configurationSchema = {
|
|||||||
description: 'host where the XMPP server is located'
|
description: 'host where the XMPP server is located'
|
||||||
},
|
},
|
||||||
port: {
|
port: {
|
||||||
type: 'number',
|
type: 'integer',
|
||||||
description: 'port of the XMPP server (default to 5222)'
|
description: 'port of the XMPP server (default to 5222)',
|
||||||
|
default: 5222
|
||||||
},
|
},
|
||||||
user: {
|
jid: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
description: 'name to use to authenticate'
|
description: 'Xmpp address to use to authenticate'
|
||||||
},
|
},
|
||||||
pass: {
|
password: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
description: 'password to use to authenticate'
|
description: 'password to use to authenticate'
|
||||||
}
|
},
|
||||||
},
|
|
||||||
|
|
||||||
additionalProperties: false,
|
|
||||||
required: ['user', 'pass']
|
|
||||||
},
|
|
||||||
|
|
||||||
accountOptions: {
|
|
||||||
type: 'object',
|
|
||||||
|
|
||||||
properties: {
|
|
||||||
register: {
|
register: {
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
description: 'create a new account if necessary',
|
description: 'create a new account if necessary',
|
||||||
@ -40,31 +35,45 @@ export const configurationSchema = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
additionalProperties: false,
|
additionalProperties: false,
|
||||||
required: ['register']
|
required: ['jid', 'password', 'register']
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
additionalProperties: false,
|
additionalProperties: false,
|
||||||
required: ['transport', 'accountOptions']
|
required: ['transport']
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===================================================================
|
// ===================================================================
|
||||||
|
|
||||||
class TransportXmppPlugin {
|
class TransportXmppPlugin {
|
||||||
constructor (xo) {
|
constructor (xo) {
|
||||||
|
this._set = ::xo.defineProperty
|
||||||
|
this._unset = null
|
||||||
|
|
||||||
|
// Defined in configure().
|
||||||
|
this._client = null
|
||||||
}
|
}
|
||||||
|
|
||||||
configure (conf) {
|
configure ({ transport: conf }) {
|
||||||
|
conf.reconnect = true
|
||||||
|
this._client = new XmppClient(conf)
|
||||||
|
|
||||||
|
this._client.on('error', () => {})
|
||||||
}
|
}
|
||||||
|
|
||||||
load () {
|
load () {
|
||||||
|
this._unset = this._set('sendToXmppClient', this._sendToXmppClient)
|
||||||
}
|
}
|
||||||
|
|
||||||
unload () {
|
unload () {
|
||||||
|
this._client.end()
|
||||||
|
this._unset()
|
||||||
|
}
|
||||||
|
|
||||||
|
async _sendToXmppClient ({to, message}) {
|
||||||
|
const stanza = new XmppClient.Stanza('message', { to: to, type: 'chat' })
|
||||||
|
.c('body').t(message)
|
||||||
|
this._client.send(stanza)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user