Merge remote-tracking branch 'xo-server-transport-xmpp/master'
This commit is contained in:
commit
a7dfa7a381
65
packages/xo-server-transport-xmpp/.editorconfig
Normal file
65
packages/xo-server-transport-xmpp/.editorconfig
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
# http://EditorConfig.org
|
||||||
|
#
|
||||||
|
# Julien Fontanet's configuration
|
||||||
|
# https://gist.github.com/julien-f/8096213
|
||||||
|
|
||||||
|
# Top-most EditorConfig file.
|
||||||
|
root = true
|
||||||
|
|
||||||
|
# Common config.
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
trim_trailing_whitespaces = true
|
||||||
|
|
||||||
|
# CoffeeScript
|
||||||
|
#
|
||||||
|
# https://github.com/polarmobile/coffeescript-style-guide/blob/master/README.md
|
||||||
|
[*.{,lit}coffee]
|
||||||
|
indent_size = 2
|
||||||
|
indent_style = space
|
||||||
|
|
||||||
|
# Markdown
|
||||||
|
[*.{md,mdwn,mdown,markdown}]
|
||||||
|
indent_size = 4
|
||||||
|
indent_style = space
|
||||||
|
|
||||||
|
# Package.json
|
||||||
|
#
|
||||||
|
# This indentation style is the one used by npm.
|
||||||
|
[/package.json]
|
||||||
|
indent_size = 2
|
||||||
|
indent_style = space
|
||||||
|
|
||||||
|
# Jade
|
||||||
|
[*.jade]
|
||||||
|
indent_size = 2
|
||||||
|
indent_style = space
|
||||||
|
|
||||||
|
# JavaScript
|
||||||
|
#
|
||||||
|
# Two spaces seems to be the standard most common style, at least in
|
||||||
|
# Node.js (http://nodeguide.com/style.html#tabs-vs-spaces).
|
||||||
|
[*.{js,jsx,ts,tsx}]
|
||||||
|
indent_size = 2
|
||||||
|
indent_style = space
|
||||||
|
|
||||||
|
# Less
|
||||||
|
[*.less]
|
||||||
|
indent_size = 2
|
||||||
|
indent_style = space
|
||||||
|
|
||||||
|
# Sass
|
||||||
|
#
|
||||||
|
# Style used for http://libsass.com
|
||||||
|
[*.s[ac]ss]
|
||||||
|
indent_size = 2
|
||||||
|
indent_style = space
|
||||||
|
|
||||||
|
# YAML
|
||||||
|
#
|
||||||
|
# Only spaces are allowed.
|
||||||
|
[*.yaml]
|
||||||
|
indent_size = 2
|
||||||
|
indent_style = space
|
7
packages/xo-server-transport-xmpp/.gitignore
vendored
Normal file
7
packages/xo-server-transport-xmpp/.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
/dist/
|
||||||
|
/node_modules/
|
||||||
|
|
||||||
|
npm-debug.log
|
||||||
|
npm-debug.log.*
|
||||||
|
pnpm-debug.log
|
||||||
|
pnpm-debug.log.*
|
10
packages/xo-server-transport-xmpp/.npmignore
Normal file
10
packages/xo-server-transport-xmpp/.npmignore
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
/examples/
|
||||||
|
example.js
|
||||||
|
example.js.map
|
||||||
|
*.example.js
|
||||||
|
*.example.js.map
|
||||||
|
|
||||||
|
/test/
|
||||||
|
/tests/
|
||||||
|
*.spec.js
|
||||||
|
*.spec.js.map
|
9
packages/xo-server-transport-xmpp/.travis.yml
Normal file
9
packages/xo-server-transport-xmpp/.travis.yml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
language: node_js
|
||||||
|
node_js:
|
||||||
|
- 'stable'
|
||||||
|
- '6'
|
||||||
|
- '4'
|
||||||
|
|
||||||
|
# Use containers.
|
||||||
|
# http://docs.travis-ci.com/user/workers/container-based-infrastructure/
|
||||||
|
sudo: false
|
50
packages/xo-server-transport-xmpp/README.md
Normal file
50
packages/xo-server-transport-xmpp/README.md
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
# xo-server-transport-xmpp [](https://travis-ci.org/vatesfr/xo-server-transport-xmpp)
|
||||||
|
|
||||||
|
XO-Server plugin which sends XMPP messages.
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
Installation of the [npm package](https://npmjs.org/package/xo-server-transport-xmpp):
|
||||||
|
|
||||||
|
```
|
||||||
|
> npm install --global xo-server-transport-xmpp
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Like all other xo-server plugins, it can be configured directly via
|
||||||
|
the web iterface, see [the plugin documentation](https://xen-orchestra.com/docs/plugins.html).
|
||||||
|
|
||||||
|
## Development
|
||||||
|
|
||||||
|
```
|
||||||
|
# Install dependencies
|
||||||
|
> npm install
|
||||||
|
|
||||||
|
# Run the tests
|
||||||
|
> npm test
|
||||||
|
|
||||||
|
# Continuously compile
|
||||||
|
> npm run dev
|
||||||
|
|
||||||
|
# Continuously run the tests
|
||||||
|
> npm run dev-test
|
||||||
|
|
||||||
|
# Build for production (automatically called by npm install)
|
||||||
|
> npm run build
|
||||||
|
```
|
||||||
|
|
||||||
|
## Contributions
|
||||||
|
|
||||||
|
Contributions are *very* welcomed, either on the documentation or on
|
||||||
|
the code.
|
||||||
|
|
||||||
|
You may:
|
||||||
|
|
||||||
|
- report any [issue](https://github.com/vatesfr/xo-server-transport-xmpp/issues)
|
||||||
|
you've encountered;
|
||||||
|
- fork and create a pull request.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
AGPL3 © [Vates SAS](http://vates.fr)
|
82
packages/xo-server-transport-xmpp/package.json
Normal file
82
packages/xo-server-transport-xmpp/package.json
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
{
|
||||||
|
"name": "xo-server-transport-xmpp",
|
||||||
|
"version": "0.1.1",
|
||||||
|
"license": "AGPL-3.0",
|
||||||
|
"description": "Transport Xmpp plugin for XO-Server",
|
||||||
|
"keywords": [
|
||||||
|
"jabber",
|
||||||
|
"orchestra",
|
||||||
|
"transport",
|
||||||
|
"xen",
|
||||||
|
"xen-orchestra",
|
||||||
|
"xmpp",
|
||||||
|
"xo-server"
|
||||||
|
],
|
||||||
|
"homepage": "https://github.com/vatesfr/xo-server-transport-xmpp",
|
||||||
|
"bugs": "https://github.com/vatesfr/xo-server-transport-xmpp/issues",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/vatesfr/xo-server-transport-xmpp"
|
||||||
|
},
|
||||||
|
"author": {
|
||||||
|
"name": "Julien Fontanet",
|
||||||
|
"email": "julien.fontanet@isonoe.net"
|
||||||
|
},
|
||||||
|
"preferGlobal": false,
|
||||||
|
"main": "dist/",
|
||||||
|
"bin": {},
|
||||||
|
"files": [
|
||||||
|
"dist/"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=4"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"babel-runtime": "^6.11.6",
|
||||||
|
"event-to-promise": "^0.7.0",
|
||||||
|
"node-xmpp-client": "^3.0.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"babel-cli": "^6.16.0",
|
||||||
|
"babel-eslint": "^7.0.0",
|
||||||
|
"babel-plugin-transform-runtime": "^6.15.0",
|
||||||
|
"babel-preset-latest": "^6.16.0",
|
||||||
|
"babel-preset-stage-0": "^6.16.0",
|
||||||
|
"cross-env": "^3.1.3",
|
||||||
|
"dependency-check": "^2.5.1",
|
||||||
|
"ghooks": "^1.3.2",
|
||||||
|
"rimraf": "^2.5.4",
|
||||||
|
"standard": "^8.2.0"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"build": "cross-env NODE_ENV=production babel --source-maps --out-dir=dist/ src/",
|
||||||
|
"clean": "rimraf dist/",
|
||||||
|
"depcheck": "dependency-check ./package.json",
|
||||||
|
"dev": "cross-env NODE_ENV=development babel --watch --source-maps --out-dir=dist/ src/",
|
||||||
|
"lint": "standard",
|
||||||
|
"posttest": "npm run lint && npm run depcheck",
|
||||||
|
"prebuild": "npm run clean",
|
||||||
|
"predev": "npm run clean",
|
||||||
|
"prepublish": "npm run build"
|
||||||
|
},
|
||||||
|
"babel": {
|
||||||
|
"plugins": [
|
||||||
|
"transform-runtime"
|
||||||
|
],
|
||||||
|
"presets": [
|
||||||
|
"latest",
|
||||||
|
"stage-0"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"standard": {
|
||||||
|
"ignore": [
|
||||||
|
"dist"
|
||||||
|
],
|
||||||
|
"parser": "babel-eslint"
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"ghooks": {
|
||||||
|
"commit-msg": "npm test"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
85
packages/xo-server-transport-xmpp/src/index.js
Normal file
85
packages/xo-server-transport-xmpp/src/index.js
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
import eventToPromise from 'event-to-promise'
|
||||||
|
import XmppClient from 'node-xmpp-client'
|
||||||
|
|
||||||
|
// ===================================================================
|
||||||
|
|
||||||
|
export const configurationSchema = {
|
||||||
|
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']
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===================================================================
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
configure (conf) {
|
||||||
|
this._conf = conf
|
||||||
|
this._conf.reconnect = true
|
||||||
|
}
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
this._unset = this._client = null
|
||||||
|
}
|
||||||
|
|
||||||
|
_sendToXmppClient ({to, message}) {
|
||||||
|
for (const receiver of to) {
|
||||||
|
this._client.send(
|
||||||
|
new XmppClient.Stanza('message', {
|
||||||
|
to: receiver,
|
||||||
|
type: 'chat'
|
||||||
|
}).c('body').t(message)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===================================================================
|
||||||
|
|
||||||
|
export default opts => new TransportXmppPlugin(opts)
|
Loading…
Reference in New Issue
Block a user