Skip to content

Commit 4da354b

Browse files
authored
progress (#405)
1 parent 685d52e commit 4da354b

File tree

125 files changed

+1702
-798
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+1702
-798
lines changed

.editorconfig

+3
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ charset = utf-8
99
trim_trailing_whitespace = true
1010
indent_style = space
1111
indent_size = 2
12+
13+
[Makefile]
14+
indent_style = tab

.eslintignore

+4
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
packages/console/public/vendor/
2+
server/modules/
3+
**/node_modules/
4+
**/dist/*.js
5+
bundle.js

.eslintrc

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
extends:
2+
- eslint:recommended
3+
- standard
4+
5+
parserOptions:
6+
sourceType: script
7+
8+
rules:
9+
strict:
10+
- error
11+
- global
12+
comma-dangle:
13+
- error
14+
- always-multiline
15+
# ES2015 http://eslint.org/docs/rules/#ecmascript-6
16+
no-var: error
17+
prefer-const: error

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ server/prosody.pid
1111
!.travis.yml
1212

1313
bundle.js
14-
browserify.js
1514
npm-debug.log
1615
lerna-debug.log
1716
yarn-error.log

.travis.yml

-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ addons:
2525
- prosody-0.10
2626
- lua-bitop # websocket
2727
- lua-sec # tls
28-
hosts:
29-
- node-xmpp.localhost
3028

3129
before_script:
3230
- sudo service prosody stop

LICENSE

+12-16
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
1-
Copyright (c) 2016 node-xmpp
1+
ISC License
22

3-
Permission is hereby granted, free of charge, to any person obtaining a copy
4-
of this software and associated documentation files (the "Software"), to deal
5-
in the Software without restriction, including without limitation the rights
6-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7-
copies of the Software, and to permit persons to whom the Software is
8-
furnished to do so, subject to the following conditions:
3+
Copyright (c) 2017, node-xmpp
94

10-
The above copyright notice and this permission notice shall be included in
11-
all copies or substantial portions of the Software.
5+
Permission to use, copy, modify, and/or distribute this software for any
6+
purpose with or without fee is hereby granted, provided that the above
7+
copyright notice and this permission notice appear in all copies.
128

13-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19-
THE SOFTWARE.
9+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14+
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15+
PERFORMANCE OF THIS SOFTWARE.

Makefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,18 @@ setup:
99

1010
test:
1111
ava
12-
standard
12+
eslint .
1313
make restart
1414
ava -v test/
1515

1616
clean:
17+
make stop
1718
rm -f prosody/prosody.err
1819
rm -f prosody/prosody.log
1920
lerna clean --yes
2021
rm -rf node_modules/
22+
rm packages/*/dist/*.js
23+
rm lerna-debug.log
2124

2225
bundle:
2326
lerna run bundle

lerna.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"example.js",
88
"ava/",
99
"test/",
10-
"test.js"
10+
"test.js",
11+
".eslintrc"
1112
]
1213
},
1314
"packages": [

package.json

+11-9
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,30 @@
22
"private": true,
33
"devDependencies": {
44
"ava": "^0.19.1",
5+
"babel-cli": "^6.24.1",
56
"babel-preset-es2015": "^6.22.0",
67
"babel-register": "^6.23.0",
8+
"babili": "^0.1.2",
79
"browserify": "^14.1.0",
10+
"eslint": "^3.19.0",
11+
"eslint-config-standard": "^10.2.1",
12+
"eslint-plugin-import": "^2.3.0",
13+
"eslint-plugin-node": "^4.2.2",
14+
"eslint-plugin-promise": "^3.5.0",
15+
"eslint-plugin-standard": "^3.0.1",
816
"lerna": "^2.0.0-rc.4",
917
"pem": "^1.9.4",
1018
"pify": "^2.3.0",
11-
"sinon": "^2.2.0",
12-
"standard": "^10.0.2"
19+
"sinon": "^2.2.0"
1320
},
1421
"ava": {
1522
"require": "babel-register",
1623
"babel": "inherit",
1724
"files": [
1825
"packages/*/test.js",
1926
"packages/*/ava/*.js",
20-
"packages/*/ava/unit/**/*.js"
21-
]
22-
},
23-
"standard": {
24-
"ignore": [
25-
"packages/console/public/vendor/",
26-
"server/modules/"
27+
"packages/*/ava/unit/**/*.js",
28+
"packages/plugins/*/test.js"
2729
]
2830
}
2931
}

packages/client-core/index.js

+10-56
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,15 @@
11
'use strict'
22

3-
const Connection = require('@xmpp/connection')
3+
const Client = require('./lib/Client')
4+
const xml = require('@xmpp/xml')
5+
const jid = require('@xmpp/jid')
46

5-
class Client extends Connection {
6-
constructor (options) {
7-
super(options)
8-
this.transports = []
9-
}
10-
11-
send (element, ...args) {
12-
if (
13-
!element.attrs.xmlns &&
14-
(element.is('iq') || element.is('message') || element.is('presence'))
15-
) {
16-
element.attrs.xmlns = 'jabber:client' // FIXME no need for TCP/TLS transports
17-
}
18-
return super.send(element, ...args)
19-
}
20-
21-
connect (uri) {
22-
const Transport = this.transports.find(Transport => {
23-
try {
24-
return Transport.prototype.socketParameters(uri) !== undefined
25-
} catch (err) {
26-
return false
27-
}
28-
})
29-
30-
if (!Transport) throw new Error('No compatible connection method found.')
31-
32-
this.Transport = Transport
33-
this.Socket = Transport.prototype.Socket
34-
35-
return super.connect(uri)
36-
}
37-
38-
socketParameters (...args) {
39-
return this.Transport.prototype.socketParameters(...args)
40-
}
41-
42-
header (...args) {
43-
return this.Transport.prototype.header(...args)
44-
}
45-
46-
headerElement (...args) {
47-
return this.Transport.prototype.headerElement(...args)
48-
}
49-
50-
footer (...args) {
51-
return this.Transport.prototype.footer(...args)
52-
}
53-
54-
footerElement (...args) {
55-
return this.Transport.prototype.footerElement(...args)
56-
}
7+
function client (...args) {
8+
return new Client(...args)
579
}
5810

59-
Client.prototype.NS = 'jabber:client'
60-
61-
module.exports = Client
11+
module.exports = client
12+
module.exports.client = client
13+
module.exports.Client = Client
14+
module.exports.xml = xml
15+
module.exports.jid = jid

packages/client-core/lib/Client.js

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
'use strict'
2+
3+
const Connection = require('@xmpp/connection')
4+
5+
class Client extends Connection {
6+
constructor (options) {
7+
super(options)
8+
this.transports = []
9+
}
10+
11+
send (element, ...args) {
12+
if (
13+
!element.attrs.xmlns &&
14+
(element.is('iq') || element.is('message') || element.is('presence'))
15+
) {
16+
element.attrs.xmlns = 'jabber:client' // FIXME no need for TCP/TLS transports
17+
}
18+
return super.send(element, ...args)
19+
}
20+
21+
connect (uri) {
22+
const Transport = this.transports.find(Transport => {
23+
try {
24+
return Transport.prototype.socketParameters(uri) !== undefined
25+
} catch (err) {
26+
return false
27+
}
28+
})
29+
30+
if (!Transport) throw new Error('No compatible connection method found.')
31+
32+
this.Transport = Transport
33+
this.Socket = Transport.prototype.Socket
34+
35+
return super.connect(uri)
36+
}
37+
38+
socketParameters (...args) {
39+
return this.Transport.prototype.socketParameters(...args)
40+
}
41+
42+
header (...args) {
43+
return this.Transport.prototype.header(...args)
44+
}
45+
46+
headerElement (...args) {
47+
return this.Transport.prototype.headerElement(...args)
48+
}
49+
50+
footer (...args) {
51+
return this.Transport.prototype.footer(...args)
52+
}
53+
54+
footerElement (...args) {
55+
return this.Transport.prototype.footerElement(...args)
56+
}
57+
}
58+
59+
Client.prototype.NS = 'jabber:client'
60+
61+
module.exports = Client

packages/client-core/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"version": "0.0.2",
77
"license": "ISC",
88
"dependencies": {
9-
"@xmpp/connection": "^0.0.6"
9+
"@xmpp/connection": "^0.0.6",
10+
"@xmpp/jid": "^0.0.2",
11+
"@xmpp/xml": "^0.1.3"
1012
}
1113
}

packages/client-core/yarn.lock

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
"@xmpp/connection@^0.0.6":
6+
version "0.0.6"
7+
resolved "https://registry.yarnpkg.com/@xmpp/connection/-/connection-0.0.6.tgz#eaa599c488f4b7e4cfdc6bbb55df9058df52f63a"
8+
dependencies:
9+
"@xmpp/jid" "^0.0.2"
10+
"@xmpp/streamparser" "^0.0.6"
11+
12+
"@xmpp/jid@^0.0.2":
13+
version "0.0.2"
14+
resolved "https://registry.yarnpkg.com/@xmpp/jid/-/jid-0.0.2.tgz#0d528ca9d58dafc833665564ffe62f332a3167f2"
15+
16+
"@xmpp/streamparser@^0.0.6":
17+
version "0.0.6"
18+
resolved "https://registry.yarnpkg.com/@xmpp/streamparser/-/streamparser-0.0.6.tgz#118033ea9db7c86a1cb46103f269ebff79f6f1ea"
19+
dependencies:
20+
"@xmpp/xml" "^0.1.3"
21+
inherits "^2.0.3"
22+
ltx "^2.5.0"
23+
24+
"@xmpp/xml@^0.1.3":
25+
version "0.1.3"
26+
resolved "https://registry.yarnpkg.com/@xmpp/xml/-/xml-0.1.3.tgz#1f14399e53e419688558698f6c62e71e39a86a6e"
27+
dependencies:
28+
inherits "^2.0.3"
29+
ltx "^2.6.2"
30+
31+
inherits@^2.0.1, inherits@^2.0.3:
32+
version "2.0.3"
33+
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"
34+
35+
ltx@^2.5.0, ltx@^2.6.2:
36+
version "2.7.1"
37+
resolved "https://registry.yarnpkg.com/ltx/-/ltx-2.7.1.tgz#0e5cbdcb5bf178cfa7831ea41dc323d97422315a"
38+
dependencies:
39+
inherits "^2.0.1"

packages/client/example.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
/* eslint-disable */
2-
31
'use strict'
42

3+
/* eslint-disable no-console */
4+
55
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
66

7-
const {Client, xml} = require('./index') // require('@xmpp/client')
8-
const entity = new Client()
7+
const {client, xml} = require('./index') // require('@xmpp/client')
8+
const entity = client()
99

1010
// emitted for any error
1111
entity.on('error', (err) => {
@@ -16,7 +16,6 @@ entity.on('close', () => {
1616
console.log('closed')
1717
})
1818

19-
2019
// emitted for incoming stanza _only_ (iq/presence/message) qualified with the right namespace
2120
// entity.on('stanza', (stanza) => {
2221
// console.log('stanza', stanza.toString())
@@ -27,11 +26,11 @@ entity.on('close', () => {
2726
// console.log('nonza', nonza.toString())
2827
// })
2928

30-
// emitted for any in our out XML fragment
3129
// useful for logging raw XML traffic
32-
entity.on('fragment', (input, output) => {
33-
console.log(output ? '=>' : '<=', (output || input).trim())
34-
})
30+
// emitted for every fragment out
31+
entity.on('input', (data) => console.log('⮈ IN ', data))
32+
// emitted for every fragment in
33+
entity.on('output', (data) => console.log('⮊ OUT', data))
3534

3635
// emitted for any in our out XML root element
3736
// useful for logging

packages/client/index.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
'use strict'
22

33
const Client = require('./lib/Client')
4-
const xml = require('@xmpp/xml')
5-
const jid = require('@xmpp/jid')
4+
const {xml, jid} = require('@xmpp/client-core')
65

7-
module.exports = function client (...args) {
6+
function client (...args) {
87
return new Client(...args)
98
}
9+
10+
module.exports = client
11+
module.exports.client = client
1012
module.exports.Client = Client
1113
module.exports.xml = xml
1214
module.exports.jid = jid

packages/client/lib/Client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const ClientCore = require('@xmpp/client-core')
3+
const ClientCore = require('@xmpp/client-core').Client
44
const plugins = require('./plugins')
55

66
class Client extends ClientCore {

0 commit comments

Comments
 (0)