iosignal 1.4.2 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +247 -240
  2. package/auth_file.json +13 -13
  3. package/auth_file.mjs +23 -23
  4. package/dist/iosignal.cjs +1 -1
  5. package/dist/iosignal.esm.js.map +1 -1
  6. package/dist/iosignal.min.js.map +1 -1
  7. package/index.js +19 -19
  8. package/indexWebBrowser.js +13 -13
  9. package/package.json +59 -60
  10. package/rollup.config.js +69 -69
  11. package/src/api/RedisAPI.js +68 -68
  12. package/src/api/api_constant.js +7 -7
  13. package/src/api/api_reply.js +34 -34
  14. package/src/api/api_sudo.js +96 -96
  15. package/src/auth/Auth_Env.js +78 -78
  16. package/src/auth/Auth_File.js +75 -75
  17. package/src/auth/Auth_Redis.js +50 -50
  18. package/src/auth/BohoAuth.js +168 -168
  19. package/src/client/CongPacket.js +150 -150
  20. package/src/client/IOCongSocket.js +88 -88
  21. package/src/client/IOCore.js +851 -851
  22. package/src/client/IOWS.js +81 -81
  23. package/src/client/IOWebSocket.js +95 -95
  24. package/src/common/constants.js +159 -159
  25. package/src/common/payload.js +82 -82
  26. package/src/common/quotaTable.js +68 -68
  27. package/src/common/util.js +61 -61
  28. package/src/server/FileLogger.js +30 -30
  29. package/src/server/Manager.js +449 -449
  30. package/src/server/Metric.js +154 -154
  31. package/src/server/Server.js +166 -148
  32. package/src/server/ServerRemote.js +227 -227
  33. package/src/server/ServerRemoteCore.js +467 -467
  34. package/src/server/serverOption.js +56 -55
  35. package/test-browser/favicon.ico +0 -0
  36. package/test-browser/index.html +92 -92
  37. package/test-browser/server.js +11 -11
  38. package/test-client-nodejs/client.cjs +17 -17
  39. package/test-client-nodejs/client.mjs +17 -17
  40. package/test-client-nodejs/client_api_reply.mjs +15 -15
  41. package/test-client-nodejs/stateChange.mjs +19 -19
  42. package/test-server/server-Auth_Env.js +19 -19
  43. package/test-server/server-Auth_File.js +12 -12
  44. package/test-server/server-api_reply.js +6 -6
  45. package/test-server/server-api_sudo.js +7 -7
  46. package/test-server/server-commonjs.cjs +8 -8
  47. package/test-server/server-esm.mjs +19 -19
  48. package/test-server/simple-server.mjs +11 -11
  49. package/test-signal-payloadType/signalPack.js +34 -34
  50. package/test-signal-payloadType/signaling.js +60 -60
package/README.md CHANGED
@@ -1,241 +1,248 @@
1
- # IOSignal
2
-
3
- [En] iosignal supports real-time communication between web browsers, node.js, and arduino. It also provides secure authentication and encrypted communication.
4
- The signaling protocol is built-in, so the server can be used without programming.
5
-
6
- [Kr] iosignal 은 웹브라우저, node.js , arduino 간의 실시간 통신을 지원합니다. 또한 보안 인증과 암호통신 기능도 제공됩니다.
7
- 시그널링 프로토콜이 내장되어 있어서 서버는 프로그래밍 없이 사용 가능합니다.
8
-
9
- ## Install
10
-
11
- ```
12
- $ npm i iosignal
13
- ```
14
-
15
- ## IOSignal Server
16
-
17
- CommonJS and ESM support both
18
-
19
- ### ESM style
20
-
21
- ```
22
- import { Server } from "iosignal"
23
- const server = new Server( { port: 7777 } )
24
- ```
25
-
26
- ### CJS style
27
-
28
- ```
29
- let { Server } = require('iosignal')
30
- const server = new Server( { port: 7777 } )
31
- ```
32
-
33
- ### server options
34
-
35
-
36
- ```js
37
- let { Server } = require('iosignal')
38
-
39
- const server = new Server(
40
- {
41
- port: 7777,
42
- congPort: 8888,
43
- showMetric: 2,
44
- showMessage: 'message' // show raw signal buffer
45
- })
46
-
47
- ```
48
-
49
- - port: <Number> IOSignal over WebSocket
50
- - congPort: <Number> IOsignal over CongSocket
51
- - showMetric: 1|2|3 show clients cid(state) info
52
- - showMessage: "none"|"message" show signal buffer message
53
- - timeout <milliseconds> ping period & timeout (min. 1000)
54
-
55
- ### IOSiognal API
56
-
57
- IOSignal API examples
58
- - src/api_reply.js // 'echo', 'date', 'unixtime'
59
- - src/api_sudo.js // server admin monitoring command
60
- - src/RedisAPI.js // redis command and response service
61
-
62
-
63
- To register an API service with the server, use the api() method
64
-
65
- `api('api_name', module )`
66
-
67
- ```js
68
- import { Server ,api_reply } from 'iosignal'
69
- const server = new Server( { port: 7777 } )
70
- server.api('reply', api_reply) // attach api module
71
- ```
72
-
73
- Example of a client calling the reply API
74
-
75
- ```js
76
- import { IO } from "iosignal"
77
- const io = new IO('ws://localhost:7777')
78
-
79
- io.on('ready', async ()=>{
80
- let res_echo = await io.req('reply', 'echo', 'hello' )
81
- let res_date = await io.req('reply', 'date' )
82
- let res_unixtime = await io.req('reply', 'unixtime' )
83
-
84
- if( res_echo.ok ) console.log( res_echo.body )
85
- if( res_date.ok ) console.log( res_date.body )
86
- if( res_unixtime.ok ) console.log( res_unixtime.body )
87
-
88
- });
89
-
90
- // result
91
- [ 'hello' ]
92
- Fri, 09 Feb 2024 14:24:37 GMT
93
- 1707488677
94
-
95
- ```
96
-
97
-
98
- ## IOSignal Client
99
-
100
- ### NodeJS Client
101
- ```
102
- // ESM
103
- import { IO } from "iosignal"
104
-
105
- // CJS
106
- // const { IO } = require('iosignal')
107
-
108
- const io = new IO('wss://io.iosignal.net/ws')
109
-
110
- io.on('ready', ()=>{
111
- console.log('ready cid:', io.cid)
112
- io.signal('#screen','playToggle')
113
- });
114
-
115
- io.listen('#notify', (...args)=>{
116
- console.log( args )
117
- })
118
-
119
- io.on('error',err=>{
120
- console.log('err', err)
121
- })
122
-
123
- ```
124
-
125
- ### Browser Client : IIFE
126
-
127
- ```html
128
- <html>
129
-
130
- <script src="../dist/iosignal.min.js"></script>
131
-
132
- <script>
133
- console.log('IO', IO) // default global variable name is IO
134
-
135
- var io1 = new IO('ws://localhost:7777')
136
- var io2 = new IO('ws://localhost:7777')
137
- var io3 = new IO('ws://localhost:7777')
138
-
139
- io1.on('error', errorHandler )
140
- io2.on('error', errorHandler )
141
- io3.on('error', errorHandler )
142
-
143
- let channelName = 'io'
144
-
145
- // classic style subsribing
146
- io1.on('ready',e=>{
147
- io1.subscribe(channelName)
148
- io1.on(channelName, (...args)=>{
149
- // console.log('io1 received', args )
150
- let msg = '[io1] ' + JSON.stringify( args )
151
- addMessage(msg)
152
- })
153
- })
154
-
155
- // iosignal style subscribing
156
- io2.listen(channelName, (...args)=>{
157
- // console.log('io2 receive', args )
158
- let msg = '[io2] ' + JSON.stringify( args )
159
- addMessage(msg)
160
- })
161
-
162
- setInterval(e=>{
163
- io3.signal(channelName, 'single string') // single string payload
164
- io3.signal(channelName, Date.now(), 'a', 2 , {key: 3} ) //multiple payload
165
- io3.signal(channelName ) // pure signal without payload.
166
- },3000)
167
-
168
- function addMessage(msg){
169
- // ...
170
- }
171
-
172
- function errorHandler(e){
173
- // ...
174
- }
175
- </script>
176
-
177
- </html>
178
- ```
179
-
180
- ### Browser client : ESM
181
- ```html
182
- <html>
183
-
184
- <script type="module">
185
- import { IO, Boho, MBP, Buffer } from "../dist/iosignal.esm.js"
186
-
187
- const = io = new IO('wss://io.iosignal.net/ws')
188
- io.listen('channel#topic', (...args)={
189
- console.log( args )
190
- })
191
-
192
- io.on('ready',()=>{
193
- console.log('ready cid:', io.cid )
194
- })
195
-
196
- </script>
197
-
198
- </html>
199
- ```
200
-
201
- ## Features
202
-
203
- ### Built-in Message Trasport Protocol
204
- - pub/sub multicast by channel name.
205
- - uni-cast: one to one messaging by CID.
206
- - `CID` is a Communication Id
207
- - CID subscribing: subscribe one peer using CID.
208
- - HomeChannel: group by IP address.
209
-
210
- ### Built-in Security
211
- - Authentication
212
- - Encryption
213
- - E2EE
214
- - thanks to the `Boho` [ [github](https://github.com/remocons/boho) ]
215
-
216
- ## Connection
217
- - Web browser use WebSocket.
218
- - Node.js use WebSocket or CongSocket.
219
- - Arduino use CongSocket.
220
-
221
- ![IOSignal](./img/iosignal_stack.png)
222
-
223
- ## iosignal repositories.
224
- - JavaScript: `iosignal` [ [github](https://github.com/remocons/iosignal) | [npm](https://www.npmjs.com/package/iosignal) ]
225
- - Node.js server ( WebSocket, CongSocket)
226
- - Node.js client ( WebSocket, CongSocket)
227
- - Web Browser Client( WebSocket)
228
-
229
- - Arduino client:
230
- - Arduino Library Manager: `IOSignal`
231
- - or `iosignal-arduino` [ [github](https://github.com/remocons/iosignal-arduino) ]
232
-
233
- - IOSignal CLI program
234
- - server and client
235
- - support mac, linux and windows.
236
- - `iosignal-cli` [ [github](https://github.com/remocons/iosignal-cli) | [npm](https://www.npmjs.com/package/iosignal-cli) ]
237
- - install: `sudo npm i -g iosignal-cli` or `npm i -g iosignal-cli`
238
-
239
- ## License
240
-
1
+ # IOSignal
2
+
3
+ [En] iosignal supports real-time communication between web browsers, node.js, and arduino. It also provides secure authentication and encrypted communication.
4
+ The signaling protocol is built-in, so the server can be used without programming.
5
+
6
+ [Kr] iosignal 은 웹브라우저, node.js , arduino 간의 실시간 통신을 지원합니다. 또한 보안 인증과 암호통신 기능도 제공됩니다.
7
+ 시그널링 프로토콜이 내장되어 있어서 서버는 프로그래밍 없이 사용 가능합니다.
8
+
9
+ ## Install
10
+
11
+ ```
12
+ $ npm i iosignal
13
+ ```
14
+
15
+ ## IOSignal Server
16
+
17
+ CommonJS and ESM support both
18
+
19
+ ### ESM style
20
+
21
+ ```
22
+ import { Server } from "iosignal"
23
+ const server = new Server( { port: 7777 } )
24
+ ```
25
+
26
+ ### CJS style
27
+
28
+ ```
29
+ let { Server } = require('iosignal')
30
+ const server = new Server( { port: 7777 } )
31
+ ```
32
+
33
+ ### server options
34
+
35
+
36
+ ```js
37
+ let { Server } = require('iosignal')
38
+
39
+ const server = new Server(
40
+ {
41
+ port: 7777,
42
+ congPort: 8888,
43
+ showMetric: 2,
44
+ showMessage: 'message' // show raw signal buffer
45
+ })
46
+
47
+ ```
48
+
49
+ - port: <Number> IOSignal over WebSocket
50
+ - congPort: <Number> IOsignal over CongSocket
51
+ - showMetric: 1|2|3 show clients cid(state) info
52
+ - showMessage: "none"|"message" show signal buffer message
53
+ - timeout <milliseconds> ping period & timeout (min. 1000)
54
+
55
+ ### IOSiognal API
56
+
57
+ IOSignal API examples
58
+ - src/api_reply.js // 'echo', 'date', 'unixtime'
59
+ - src/api_sudo.js // server admin monitoring command
60
+ - src/RedisAPI.js // redis command and response service
61
+
62
+
63
+ To register an API service with the server, use the api() method
64
+
65
+ `api('api_name', module )`
66
+
67
+ ```js
68
+ import { Server ,api_reply } from 'iosignal'
69
+ const server = new Server( { port: 7777 } )
70
+ server.api('reply', api_reply) // attach api module
71
+ ```
72
+
73
+ Example of a client calling the reply API
74
+
75
+ ```js
76
+ import { IO } from "iosignal"
77
+ const io = new IO('ws://localhost:7777')
78
+
79
+ io.on('ready', async ()=>{
80
+ let res_echo = await io.req('reply', 'echo', 'hello' )
81
+ let res_date = await io.req('reply', 'date' )
82
+ let res_unixtime = await io.req('reply', 'unixtime' )
83
+
84
+ if( res_echo.ok ) console.log( res_echo.body )
85
+ if( res_date.ok ) console.log( res_date.body )
86
+ if( res_unixtime.ok ) console.log( res_unixtime.body )
87
+
88
+ });
89
+
90
+ // result
91
+ [ 'hello' ]
92
+ Fri, 09 Feb 2024 14:24:37 GMT
93
+ 1707488677
94
+
95
+ ```
96
+
97
+
98
+ ## IOSignal Client
99
+
100
+ ### NodeJS Client
101
+ ```
102
+ // ESM
103
+ import { IO } from "iosignal"
104
+
105
+ // CJS
106
+ // const { IO } = require('iosignal')
107
+
108
+ const io = new IO('wss://io.iosignal.net/ws')
109
+
110
+ io.on('ready', ()=>{
111
+ console.log('ready cid:', io.cid)
112
+ io.signal('#screen','playToggle')
113
+ });
114
+
115
+ io.listen('#notify', (...args)=>{
116
+ console.log( args )
117
+ })
118
+
119
+ io.on('error',err=>{
120
+ console.log('err', err)
121
+ })
122
+
123
+ ```
124
+
125
+ ### Browser Client : IIFE
126
+
127
+ ```html
128
+ <html>
129
+
130
+ <script src="../dist/iosignal.min.js"></script>
131
+
132
+ <script>
133
+ console.log('IO', IO) // default global variable name is IO
134
+
135
+ var io1 = new IO('ws://localhost:7777')
136
+ var io2 = new IO('ws://localhost:7777')
137
+ var io3 = new IO('ws://localhost:7777')
138
+
139
+ io1.on('error', errorHandler )
140
+ io2.on('error', errorHandler )
141
+ io3.on('error', errorHandler )
142
+
143
+ let channelName = 'io'
144
+
145
+ // classic style subsribing
146
+ io1.on('ready',e=>{
147
+ io1.subscribe(channelName)
148
+ io1.on(channelName, (...args)=>{
149
+ // console.log('io1 received', args )
150
+ let msg = '[io1] ' + JSON.stringify( args )
151
+ addMessage(msg)
152
+ })
153
+ })
154
+
155
+ // iosignal style subscribing
156
+ io2.listen(channelName, (...args)=>{
157
+ // console.log('io2 receive', args )
158
+ let msg = '[io2] ' + JSON.stringify( args )
159
+ addMessage(msg)
160
+ })
161
+
162
+ setInterval(e=>{
163
+ io3.signal(channelName, 'single string') // single string payload
164
+ io3.signal(channelName, Date.now(), 'a', 2 , {key: 3} ) //multiple payload
165
+ io3.signal(channelName ) // pure signal without payload.
166
+ },3000)
167
+
168
+ function addMessage(msg){
169
+ // ...
170
+ }
171
+
172
+ function errorHandler(e){
173
+ // ...
174
+ }
175
+ </script>
176
+
177
+ </html>
178
+ ```
179
+
180
+ ### Browser client : ESM
181
+ ```html
182
+ <html>
183
+
184
+ <script type="module">
185
+ import { IO, Boho, MBP, Buffer } from "../dist/iosignal.esm.js"
186
+
187
+ const = io = new IO('wss://io.iosignal.net/ws')
188
+ io.listen('channel#topic', (...args)={
189
+ console.log( args )
190
+ })
191
+
192
+ io.on('ready',()=>{
193
+ console.log('ready cid:', io.cid )
194
+ })
195
+
196
+ </script>
197
+
198
+ </html>
199
+ ```
200
+
201
+ ## Features
202
+
203
+ ### Built-in Message Trasport Protocol
204
+ - pub/sub multicast by channel name.
205
+ - uni-cast: one to one messaging by CID.
206
+ - `CID` is a Communication Id
207
+ - CID subscribing: subscribe one peer using CID.
208
+ - HomeChannel: group by IP address.
209
+
210
+ ### Built-in Security
211
+ - Authentication
212
+ - Encryption
213
+ - E2EE
214
+ - thanks to the `Boho` [ [github](https://github.com/remocons/boho) ]
215
+
216
+ ## Connection
217
+ - Web browser use WebSocket.
218
+ - Node.js use WebSocket or CongSocket.
219
+ - Arduino use CongSocket.
220
+
221
+ ![IOSignal](./img/iosignal_stack.png)
222
+
223
+ ## IOSignal repositories.
224
+
225
+ - Javascript: `iosignal` [ [github](https://github.com/remocons/iosignal) | [npm](https://www.npmjs.com/package/iosignal) ]
226
+ - Node.js server ( WebSocket, CongSocket)
227
+ - Node.js client ( WebSocket, CongSocket)
228
+ - Web Browser client( WebSocket)
229
+
230
+ - CLI program
231
+ - `iosignal-cli` [ [github](https://github.com/remocons/iosignal-cli) | [npm](https://www.npmjs.com/package/iosignal-cli) ]
232
+ - install: `npm i -g iosignal-cli` or `sudo npm i -g iosignal-cli`
233
+ - support mac, linux and windows.
234
+ - server and client
235
+
236
+ - Arduino iosignal library and examples:
237
+ - use Arduino Library Manager: `iosignal`
238
+ - or `iosignal-arduino` [ [github](https://github.com/remocons/iosignal-arduino) ]
239
+ - web app : http://test.iosignal.net
240
+
241
+ - Arduino remocon library and examples:
242
+ - use Arduino Library Manager: `remocon`
243
+ - or `remocon-arduino` [ [github](https://github.com/remocons/remocon-arduino) ]
244
+ - web app : https://remocon.kr
245
+
246
+ ## License
247
+
241
248
  This code is released under the MIT License.
package/auth_file.json CHANGED
@@ -1,13 +1,13 @@
1
- [
2
- ["sampleid","samplekey","sample_cid",0],
3
- ["id_max8","no_key_size_limit","communication_id",0],
4
- ["device1","device1_key","device1_cid",0],
5
- ["device2","device2_key","device2_cid",0],
6
- ["uno","uno","uno",1],
7
- ["go","go","go",2],
8
- ["bro","bro","bro",3],
9
- ["admin","admin","admin",255],
10
- ["adminb","adminb","adminb",255]
11
- ]
12
-
13
-
1
+ [
2
+ ["sampleid","samplekey","sample_cid",0],
3
+ ["id_max8","no_key_size_limit","communication_id",0],
4
+ ["device1","device1_key","device1_cid",0],
5
+ ["device2","device2_key","device2_cid",0],
6
+ ["uno","uno","uno",1],
7
+ ["go","go","go",2],
8
+ ["bro","bro","bro",3],
9
+ ["admin","admin","admin",255],
10
+ ["adminb","adminb","adminb",255]
11
+ ]
12
+
13
+
package/auth_file.mjs CHANGED
@@ -1,23 +1,23 @@
1
-
2
- /*
3
- Authentication data sample.
4
-
5
- device props: ["did", "key", "cid", level ]
6
-
7
- did: ( device id ) authentication id. maximum 8 chars.
8
- key: ( device key ) authentication key. no size limit.
9
- cid: ( communication id ) signal target id. maximum 12 chars.
10
- level:( quota level) <Number> ref. /server/quotaTable.js
11
-
12
- */
13
- export const authInfo = [
14
- ["did","passowrd","cid",0],
15
- ["device1","device1_key","device1_cid",0],
16
- ["device2","device2_key","device2_cid",0],
17
- ["uno","uno-key","uno",1],
18
- ["go","go-key","go",2],
19
- ["bro","bro-key","bro",3],
20
- ["admin","admin-key","admin",255],
21
- ]
22
-
23
-
1
+
2
+ /*
3
+ Authentication data sample.
4
+
5
+ device props: ["did", "key", "cid", level ]
6
+
7
+ did: ( device id ) authentication id. maximum 8 chars.
8
+ key: ( device key ) authentication key. no size limit.
9
+ cid: ( communication id ) signal target id. maximum 12 chars.
10
+ level:( quota level) <Number> ref. /server/quotaTable.js
11
+
12
+ */
13
+ export const authInfo = [
14
+ ["did","passowrd","cid",0],
15
+ ["device1","device1_key","device1_cid",0],
16
+ ["device2","device2_key","device2_cid",0],
17
+ ["uno","uno-key","uno",1],
18
+ ["go","go-key","go",2],
19
+ ["bro","bro-key","bro",3],
20
+ ["admin","admin-key","admin",255],
21
+ ]
22
+
23
+