Skip to content

Commit ba09fb6

Browse files
committed
import console from xmpp.js/packages/console
0 parents  commit ba09fb6

28 files changed

+43168
-0
lines changed

.eslintrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
rules:
2+
no-console: 0

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

Makefile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
make:
2+
# bootstrap
3+
cp ../../node_modules/bootstrap/dist/css/bootstrap.css public/vendor/
4+
cp ../../node_modules/bootstrap/dist/js/bootstrap.js public/vendor/
5+
# notie
6+
cp ../../node_modules/notie/dist/notie.css public/vendor/
7+
# jQuery
8+
cp ../../node_modules/jquery/dist/jquery.slim.js public/vendor/
9+
# tether
10+
cp ../../node_modules/tether/dist/js/tether.js public/vendor/
11+
# notie
12+
cp ../../node_modules/notie/dist/notie.js public/vendor/
13+
# clipboard
14+
cp ../../node_modules/clipboard/dist/clipboard.js public/vendor/
15+
# prismjs
16+
cd ../../node_modules/prismjs/ && cat themes/prism-solarizedlight.css plugins/autolinker/prism-autolinker.css plugins/autolinker/prism-autolinker.css plugins/toolbar/prism-toolbar.css > ../../packages/console/public/vendor/prism.css
17+
cd ../../node_modules/prismjs/ && cat prism.js plugins/autolinker/prism-autolinker.js plugins/toolbar/prism-toolbar.js plugins/copy-to-clipboard/prism-copy-to-clipboard.js > ../../packages/console/public/vendor/prism.js
18+
# codemirror
19+
cd ../../node_modules/codemirror/ && cat lib/codemirror.css theme/solarized.css addon/lint/lint.css addon/fold/foldgutter.css addon/hint/show-hint.css > ../../packages/console/public/vendor/codemirror.css
20+
cd ../../node_modules/codemirror/ && cat lib/codemirror.js mode/xml/xml.js addon/hint/show-hint.js addon/hint/xml-hint.js addon/fold/foldcode.js addon/fold/foldgutter.js addon/fold/xml-fold.js addon/edit/matchtags.js addon/edit/closetag.js > ../../packages/console/public/vendor/codemirror.js
21+
22+
../../node_modules/.bin/browserify public/script.js > public/bundle.js
23+
24+
clean:
25+
rm -f public/vendor/*
26+
rm -f public/bundle.js

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# console
2+
3+
XMPP console, terminal and web interfaces.
4+
5+
![](screenshot.png)
6+
7+
## Install
8+
9+
```
10+
npm install -g @xmpp/console
11+
```
12+
13+
## Usage
14+
15+
```
16+
Usage
17+
$ xmpp-console [endpoint]
18+
19+
Options
20+
--port, -p 8080 port for the web interface
21+
--web, -w use web interface
22+
--no-open, prevents opening the url for the web interface
23+
--type, -t client (default) or component
24+
25+
Examples
26+
$ xmpp-console
27+
$ xmpp-console xmpp://localhost[:5222] (classic XMPP)
28+
$ xmpp-console xmpps://localhost[:5223] (direct TLS)
29+
$ xmpp-console ws://localhost:5280/xmpp-websocket (WebSocket)
30+
$ xmpp-console wss://localhost:52801/xmpp-websocket (Secure WebSocket)
31+
$ xmpp-console xmpp://component.localhost[:5347] --type component (component)
32+
```
33+
34+
## Interfaces
35+
36+
### Terminal
37+
38+
The terminal interface supports component and client connection (TCP and WebSocket).
39+
40+
### Web
41+
42+
The Web interface only supports WebSocket client connection at the moment.
43+
44+
It is possible to use it locally with `xmpp-console --web` (see [Usage](#usage)) or deploy it with
45+
46+
```
47+
$ git clone https://github.com/xmppjs/xmpp.js
48+
$ cd xmpp.js
49+
$ make
50+
$ cd packages/console
51+
$ make
52+
```
53+
54+
and use your HTTP server to serve `xmpp.js/packages/console/public/`.

app.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env node
2+
3+
'use strict'
4+
5+
process.title = '@xmpp/console'
6+
7+
const meow = require('meow')
8+
9+
const cli = meow(
10+
`
11+
Usage
12+
$ xmpp-console [endpoint]
13+
14+
Options
15+
--port, -p 8080 port for the web interface
16+
--web, -w use web interface
17+
--no-open, prevents opening the url for the web interface
18+
--type, -t client (default) or component
19+
20+
Examples
21+
$ xmpp-console localhost (auto)
22+
$ xmpp-console xmpp://localhost[:5222] (classic XMPP)
23+
$ xmpp-console xmpps://localhost[:5223] (direct TLS)
24+
$ xmpp-console ws://localhost:5280/xmpp-websocket (WebSocket)
25+
$ xmpp-console wss://localhost:52801/xmpp-websocket (Secure WebSocket)
26+
$ xmpp-console xmpp://component.localhost[:5347] --type component (component)
27+
`,
28+
{
29+
alias: {
30+
p: 'port',
31+
w: 'web',
32+
t: 'type',
33+
},
34+
}
35+
)
36+
37+
const [endpoint] = cli.input
38+
39+
const int = cli.flags.web ? './web' : './cli'
40+
if (!cli.flags.type) {
41+
cli.flags.type = 'client'
42+
}
43+
require(int)(cli.flags, endpoint)
44+
45+
process.on('unhandledRejection', reason => {
46+
throw reason
47+
})

cli.js

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#!/usr/bin/env node
2+
3+
'use strict' // eslint-disable-line node/shebang
4+
5+
const readline = require('readline')
6+
const chalk = require('chalk')
7+
8+
const component = require('@xmpp/component')
9+
const client = require('@xmpp/client')
10+
const Console = require('./lib/Console')
11+
12+
module.exports = function(flags, endpoint) {
13+
const options = {
14+
input: process.stdin,
15+
output: process.stdout,
16+
prompt: chalk.magenta.bold('✏ '),
17+
}
18+
if (Number(process.env.NODE_NO_READLINE)) {
19+
options.terminal = false
20+
}
21+
const rl = readline.createInterface(options)
22+
23+
let prevent = false
24+
25+
let entity
26+
if (flags.type === 'compomnent') {
27+
entity = component.xmpp().component
28+
} else {
29+
entity = client.xmpp().client
30+
}
31+
32+
const xconsole = new Console(entity)
33+
xconsole.resetInput = function() {
34+
rl.prompt()
35+
}
36+
xconsole.log = function(...args) {
37+
readline.cursorTo(process.stdout, 0)
38+
console.log(...args)
39+
rl.prompt()
40+
}
41+
xconsole.info = function(...args) {
42+
this.log(chalk.cyan.bold('🛈'), ...args)
43+
}
44+
xconsole.warning = function(...args) {
45+
this.log(chalk.yellow.bold('⚠'), ...args)
46+
}
47+
xconsole.error = function(...args) {
48+
this.log(chalk.red.bold('❌') + ' error', ...args)
49+
}
50+
xconsole.input = function(el) {
51+
this.log(chalk.green.bold('⮈ IN\n') + this.beautify(el))
52+
}
53+
xconsole.output = function(el) {
54+
this.log(chalk.magenta.bold('⮊ OUT\n') + this.beautify(el))
55+
}
56+
xconsole.choose = function(options) {
57+
return new Promise(resolve => {
58+
this.log(
59+
chalk.yellow.bold('?'),
60+
options.text,
61+
':',
62+
options.choices.join(', ')
63+
)
64+
prevent = true
65+
rl.on('line', line => {
66+
prevent = false
67+
resolve(line)
68+
})
69+
})
70+
}
71+
xconsole.ask = function(options) {
72+
return new Promise(resolve => {
73+
this.log(chalk.yellow.bold('?'), options.text)
74+
prevent = true
75+
rl.once('line', line => {
76+
prevent = false
77+
resolve(line.trim())
78+
})
79+
})
80+
}
81+
82+
rl.prompt(true)
83+
84+
rl.on('line', line => {
85+
if (prevent) {
86+
return
87+
}
88+
// Clear stdin - any better idea? please contribute
89+
readline.moveCursor(process.stdout, 0, -1)
90+
readline.clearLine(process.stdout, 0)
91+
92+
line = line.trim()
93+
if (line) {
94+
xconsole.send(line)
95+
} else {
96+
rl.prompt()
97+
}
98+
})
99+
100+
rl.on('close', () => {
101+
process.exit() // eslint-disable-line no-process-exit
102+
})
103+
104+
entity.on('close', () => {
105+
process.exit() // eslint-disable-line no-process-exit
106+
})
107+
108+
if (endpoint) {
109+
entity.connect(endpoint)
110+
} else {
111+
xconsole
112+
.ask({
113+
text: 'Enter endpoint',
114+
value: 'ws://localhost:5280/xmpp-websocket',
115+
type: 'url',
116+
})
117+
.then(endpoint => {
118+
return entity.connect(endpoint)
119+
})
120+
}
121+
}

0 commit comments

Comments
 (0)