1
1
#!/usr/bin/env node
2
+ // tslint:disable
2
3
3
- const path = require ( ' path' ) ;
4
- const pkg = require ( ' ../package.json' ) ;
5
- const fs = require ( 'fs' ) ;
4
+ const path = require ( " path" ) ;
5
+ const pkg = require ( " ../package.json" ) ;
6
+ const fs = require ( "fs" ) ;
6
7
const version = pkg . version ;
7
- const PeerServer = require ( ' ../src' ) . PeerServer ;
8
- const opts = require ( ' optimist' )
9
- . usage ( ' Usage: $0' )
8
+ const { PeerServer } = require ( " ../dist/ src" ) ;
9
+ const opts = require ( " optimist" )
10
+ . usage ( " Usage: $0" )
10
11
. options ( {
11
12
expire_timeout : {
12
13
demand : false ,
13
- alias : 't' ,
14
- description : ' timeout (milliseconds)' ,
14
+ alias : "t" ,
15
+ description : " timeout (milliseconds)" ,
15
16
default : 5000
16
17
} ,
17
18
concurrent_limit : {
18
19
demand : false ,
19
- alias : 'c' ,
20
- description : ' concurrent limit' ,
20
+ alias : "c" ,
21
+ description : " concurrent limit" ,
21
22
default : 5000
22
23
} ,
23
24
alive_timeout : {
24
25
demand : false ,
25
- description : ' broken connection check timeout (milliseconds)' ,
26
+ description : " broken connection check timeout (milliseconds)" ,
26
27
default : 60000
27
28
} ,
28
29
key : {
29
30
demand : false ,
30
- alias : 'k' ,
31
- description : ' connection key' ,
32
- default : ' peerjs'
31
+ alias : "k" ,
32
+ description : " connection key" ,
33
+ default : " peerjs"
33
34
} ,
34
35
sslkey : {
35
36
demand : false ,
36
- description : ' path to SSL key'
37
+ description : " path to SSL key"
37
38
} ,
38
39
sslcert : {
39
40
demand : false ,
40
- description : ' path to SSL certificate'
41
+ description : " path to SSL certificate"
41
42
} ,
42
43
port : {
43
44
demand : true ,
44
- alias : 'p' ,
45
- description : ' port'
45
+ alias : "p" ,
46
+ description : " port"
46
47
} ,
47
48
path : {
48
49
demand : false ,
49
- description : ' custom path' ,
50
- default : '/'
50
+ description : " custom path" ,
51
+ default : "/"
51
52
} ,
52
53
allow_discovery : {
53
54
demand : false ,
54
- description : ' allow discovery of peers'
55
+ description : " allow discovery of peers"
55
56
} ,
56
57
proxied : {
57
58
demand : false ,
58
- description : ' Set true if PeerServer stays behind a reverse proxy' ,
59
+ description : " Set true if PeerServer stays behind a reverse proxy" ,
59
60
default : false
60
61
}
61
62
} )
62
- . boolean ( ' allow_discovery' )
63
+ . boolean ( " allow_discovery" )
63
64
. argv ;
64
65
65
- process . on ( ' uncaughtException' , function ( e ) {
66
- console . error ( ' Error: ' + e ) ;
66
+ process . on ( " uncaughtException" , function ( e ) {
67
+ console . error ( " Error: " + e ) ;
67
68
} ) ;
68
69
69
70
if ( opts . sslkey || opts . sslcert ) {
@@ -76,8 +77,8 @@ if (opts.sslkey || opts.sslcert) {
76
77
delete opts . sslkey ;
77
78
delete opts . sslcert ;
78
79
} else {
79
- console . error ( ' Warning: PeerServer will not run because either ' +
80
- ' the key or the certificate has not been provided.' ) ;
80
+ console . error ( " Warning: PeerServer will not run because either " +
81
+ " the key or the certificate has not been provided." ) ;
81
82
process . exit ( 1 ) ;
82
83
}
83
84
}
@@ -88,15 +89,15 @@ const server = PeerServer(opts, server => {
88
89
const port = server . address ( ) . port ;
89
90
90
91
console . log (
91
- ' Started PeerServer on %s, port: %s, path: %s (v. %s)' ,
92
- host , port , userPath || '/' , version
92
+ " Started PeerServer on %s, port: %s, path: %s (v. %s)" ,
93
+ host , port , userPath || "/" , version
93
94
) ;
94
95
} ) ;
95
96
96
- server . on ( ' connection' , client => {
97
+ server . on ( " connection" , client => {
97
98
console . log ( `Client connected: ${ client . getId ( ) } ` ) ;
98
99
} ) ;
99
100
100
- server . on ( ' disconnect' , client => {
101
+ server . on ( " disconnect" , client => {
101
102
console . log ( `Client disconnected: ${ client . getId ( ) } ` ) ;
102
103
} ) ;
0 commit comments