iosignal 1.7.0 → 1.8.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 (57) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +254 -247
  3. package/auth_file.json +13 -13
  4. package/auth_file.mjs +23 -23
  5. package/dist/iosignal-iife.js +11 -0
  6. package/dist/iosignal-iife.js.map +1 -0
  7. package/dist/iosignal.cjs +1 -2
  8. package/dist/iosignal.js +11 -0
  9. package/dist/iosignal.js.map +1 -0
  10. package/index.js +19 -19
  11. package/indexWebBrowser.js +13 -13
  12. package/package.json +56 -59
  13. package/rollup.config.js +72 -69
  14. package/src/api/RedisAPI.js +65 -65
  15. package/src/api/api_constant.js +7 -7
  16. package/src/api/api_reply.js +31 -31
  17. package/src/api/api_sudo.js +91 -91
  18. package/src/auth/Auth_Env.js +76 -76
  19. package/src/auth/Auth_File.js +71 -71
  20. package/src/auth/Auth_Redis.js +44 -44
  21. package/src/auth/BohoAuth.js +164 -164
  22. package/src/client/CongPacket.js +141 -141
  23. package/src/client/IOCongSocket.js +81 -81
  24. package/src/client/IOCore.js +822 -822
  25. package/src/client/IOWS.js +80 -80
  26. package/src/client/IOWebSocket.js +111 -111
  27. package/src/common/constants.js +148 -148
  28. package/src/common/payload.js +81 -81
  29. package/src/common/quotaTable.js +68 -68
  30. package/src/common/util.js +61 -61
  31. package/src/server/FileLogger.js +30 -30
  32. package/src/server/Manager.js +433 -433
  33. package/src/server/Metric.js +155 -155
  34. package/src/server/Remote.js +207 -207
  35. package/src/server/RemoteCore.js +439 -439
  36. package/src/server/Server.js +163 -163
  37. package/src/server/serverOption.js +56 -56
  38. package/test-browser/favicon.ico +0 -0
  39. package/test-browser/index.html +96 -96
  40. package/test-browser/server.js +11 -11
  41. package/test-client-nodejs/client.cjs +17 -17
  42. package/test-client-nodejs/client.mjs +17 -17
  43. package/test-client-nodejs/client_api_reply.mjs +15 -15
  44. package/test-client-nodejs/stateChange.mjs +19 -19
  45. package/test-server/server-Auth_Env.js +19 -19
  46. package/test-server/server-Auth_File.js +12 -12
  47. package/test-server/server-api_reply.js +6 -6
  48. package/test-server/server-api_sudo.js +7 -7
  49. package/test-server/server-commonjs.cjs +8 -8
  50. package/test-server/server-esm.mjs +20 -20
  51. package/test-server/simple-server.mjs +11 -11
  52. package/test-signal-payloadType/signalPack.js +34 -34
  53. package/test-signal-payloadType/signaling.js +60 -60
  54. package/dist/iosignal.esm.js +0 -3
  55. package/dist/iosignal.esm.js.map +0 -1
  56. package/dist/iosignal.min.js +0 -3
  57. package/dist/iosignal.min.js.map +0 -1
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Taeo Lee <taeo.mocha@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,248 +1,255 @@
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
-
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
+ ## online demo
10
+
11
+ ### StackBlitz Webcontainer demo
12
+
13
+ [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/~/github.com/remocons/iosignal-example)
14
+
15
+
16
+ ## Install
17
+
18
+ ```
19
+ $ npm i iosignal
20
+ ```
21
+
22
+ ## IOSignal Server
23
+
24
+ CommonJS and ESM support both
25
+
26
+ ### ESM style
27
+
28
+ ```
29
+ import { Server } from "iosignal"
30
+ const server = new Server( { port: 7777 } )
31
+ ```
32
+
33
+ ### CJS style
34
+
35
+ ```
36
+ let { Server } = require('iosignal')
37
+ const server = new Server( { port: 7777 } )
38
+ ```
39
+
40
+ ### server options
41
+
42
+
43
+ ```js
44
+ let { Server } = require('iosignal')
45
+
46
+ const server = new Server(
47
+ {
48
+ port: 7777,
49
+ congPort: 8888,
50
+ showMetric: 2,
51
+ showMessage: 'message' // show raw signal buffer
52
+ })
53
+
54
+ ```
55
+
56
+ - port: <Number> IOSignal over WebSocket
57
+ - congPort: <Number> IOsignal over CongSocket
58
+ - showMetric: 1|2|3 show clients cid(state) info
59
+ - showMessage: "none"|"message" show signal buffer message
60
+ - timeout <milliseconds> ping period & timeout (min. 1000)
61
+
62
+ ### IOSiognal API
63
+
64
+ IOSignal API examples
65
+ - src/api_reply.js // 'echo', 'date', 'unixtime'
66
+ - src/api_sudo.js // server admin monitoring command
67
+ - src/RedisAPI.js // redis command and response service
68
+
69
+
70
+ To register an API service with the server, use the api() method
71
+
72
+ `api('api_name', module )`
73
+
74
+ ```js
75
+ import { Server ,api_reply } from 'iosignal'
76
+ const server = new Server( { port: 7777 } )
77
+ server.api('reply', api_reply) // attach api module
78
+ ```
79
+
80
+ Example of a client calling the reply API
81
+
82
+ ```js
83
+ import { IO } from "iosignal"
84
+ const io = new IO('ws://localhost:7777')
85
+
86
+ io.on('ready', async ()=>{
87
+ let res_echo = await io.req('reply', 'echo', 'hello' )
88
+ let res_date = await io.req('reply', 'date' )
89
+ let res_unixtime = await io.req('reply', 'unixtime' )
90
+
91
+ if( res_echo.ok ) console.log( res_echo.body )
92
+ if( res_date.ok ) console.log( res_date.body )
93
+ if( res_unixtime.ok ) console.log( res_unixtime.body )
94
+
95
+ });
96
+
97
+ // result
98
+ [ 'hello' ]
99
+ Fri, 09 Feb 2024 14:24:37 GMT
100
+ 1707488677
101
+
102
+ ```
103
+
104
+
105
+ ## IOSignal Client
106
+
107
+ ### NodeJS Client
108
+ ```
109
+ // ESM
110
+ import { IO } from "iosignal"
111
+
112
+ // CJS
113
+ // const { IO } = require('iosignal')
114
+
115
+ const io = new IO('wss://io.iosignal.net/ws')
116
+
117
+ io.on('ready', ()=>{
118
+ console.log('ready cid:', io.cid)
119
+ io.signal('#screen','playToggle')
120
+ });
121
+
122
+ io.listen('#notify', (...args)=>{
123
+ console.log( args )
124
+ })
125
+
126
+ io.on('error',err=>{
127
+ console.log('err', err)
128
+ })
129
+
130
+ ```
131
+
132
+ ### Browser Client : IIFE
133
+
134
+ ```html
135
+ <html>
136
+
137
+ <script src="../dist/iosignal-iife.js"></script>
138
+
139
+ <script>
140
+ console.log('IO', IO) // default global variable name is IO
141
+
142
+ var io1 = new IO('ws://localhost:7777')
143
+ var io2 = new IO('ws://localhost:7777')
144
+ var io3 = new IO('ws://localhost:7777')
145
+
146
+ io1.on('error', errorHandler )
147
+ io2.on('error', errorHandler )
148
+ io3.on('error', errorHandler )
149
+
150
+ let channelName = 'io'
151
+
152
+ // classic style subsribing
153
+ io1.on('ready',e=>{
154
+ io1.subscribe(channelName)
155
+ io1.on(channelName, (...args)=>{
156
+ // console.log('io1 received', args )
157
+ let msg = '[io1] ' + JSON.stringify( args )
158
+ addMessage(msg)
159
+ })
160
+ })
161
+
162
+ // iosignal style subscribing
163
+ io2.listen(channelName, (...args)=>{
164
+ // console.log('io2 receive', args )
165
+ let msg = '[io2] ' + JSON.stringify( args )
166
+ addMessage(msg)
167
+ })
168
+
169
+ setInterval(e=>{
170
+ io3.signal(channelName, 'single string') // single string payload
171
+ io3.signal(channelName, Date.now(), 'a', 2 , {key: 3} ) //multiple payload
172
+ io3.signal(channelName ) // pure signal without payload.
173
+ },3000)
174
+
175
+ function addMessage(msg){
176
+ // ...
177
+ }
178
+
179
+ function errorHandler(e){
180
+ // ...
181
+ }
182
+ </script>
183
+
184
+ </html>
185
+ ```
186
+
187
+ ### Browser client : ESM
188
+ ```html
189
+ <html>
190
+
191
+ <script type="module">
192
+ import { IO, Boho, MBP, Buffer } from "../dist/iosignal.js"
193
+
194
+ const = io = new IO('wss://io.iosignal.net/ws')
195
+ io.listen('channel#topic', (...args)={
196
+ console.log( args )
197
+ })
198
+
199
+ io.on('ready',()=>{
200
+ console.log('ready cid:', io.cid )
201
+ })
202
+
203
+ </script>
204
+
205
+ </html>
206
+ ```
207
+
208
+ ## Features
209
+
210
+ ### Built-in Message Trasport Protocol
211
+ - pub/sub multicast by channel name.
212
+ - uni-cast: one to one messaging by CID.
213
+ - `CID` is a Communication Id
214
+ - CID subscribing: subscribe one peer using CID.
215
+ - HomeChannel: group by IP address.
216
+
217
+ ### Built-in Security
218
+ - Authentication
219
+ - Encryption
220
+ - E2EE
221
+ - thanks to the `Boho` [ [github](https://github.com/remocons/boho) ]
222
+
223
+ ## Connection
224
+ - Web browser use WebSocket.
225
+ - Node.js use WebSocket or CongSocket.
226
+ - Arduino use CongSocket.
227
+
228
+ ![IOSignal](./img/iosignal_stack.png)
229
+
230
+ ## IOSignal repositories.
231
+
232
+ - Javascript: `iosignal` [ [github](https://github.com/remocons/iosignal) | [npm](https://www.npmjs.com/package/iosignal) ]
233
+ - Node.js server ( WebSocket, CongSocket)
234
+ - Node.js client ( WebSocket, CongSocket)
235
+ - Web Browser client( WebSocket)
236
+
237
+ - CLI program
238
+ - `iosignal-cli` [ [github](https://github.com/remocons/iosignal-cli) | [npm](https://www.npmjs.com/package/iosignal-cli) ]
239
+ - install: `npm i -g iosignal-cli` or `sudo npm i -g iosignal-cli`
240
+ - support mac, linux and windows.
241
+ - server and client
242
+
243
+ - Arduino iosignal library and examples:
244
+ - use Arduino Library Manager: `iosignal`
245
+ - or `iosignal-arduino` [ [github](https://github.com/remocons/iosignal-arduino) ]
246
+ - web app : http://test.iosignal.net
247
+
248
+ - Arduino remocon library and examples:
249
+ - use Arduino Library Manager: `remocon`
250
+ - or `remocon-arduino` [ [github](https://github.com/remocons/remocon-arduino) ]
251
+ - web app : https://remocon.kr
252
+
253
+ ## License
254
+
248
255
  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
+