iosignal 2.2.1 → 3.0.1
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.
- package/README.md +248 -114
- package/dist/io.d.ts +481 -0
- package/dist/io.js +4 -5
- package/dist/io.js.map +1 -1
- package/dist/io.min.js +4 -5
- package/dist/io.min.js.map +1 -1
- package/dist/iosignal.js +9559 -0
- package/dist/types/client/IOCore.d.ts +408 -0
- package/dist/types/client/browser/IOWebSocket.d.ts +75 -0
- package/dist/types/common/constants.d.ts +169 -0
- package/dist/types/common/payload.d.ts +6 -0
- package/dist/types/common/quotaTable.d.ts +47 -0
- package/docs/README.ko.md +371 -0
- package/docs/iosignal_architecture.png +0 -0
- package/examples/react-chat-js/dist/assets/index-Cy4qaVcJ.js +56 -0
- package/examples/react-chat-js/dist/assets/index-NETrjYhz.css +1 -0
- package/examples/react-chat-js/dist/index.html +14 -0
- package/examples/react-chat-js/index.html +13 -0
- package/examples/react-chat-js/package-lock.json +1628 -0
- package/examples/react-chat-js/package.json +20 -0
- package/examples/react-chat-js/src/App.css +61 -0
- package/examples/react-chat-js/src/App.jsx +125 -0
- package/examples/react-chat-js/src/index.css +13 -0
- package/examples/react-chat-js/src/main.jsx +13 -0
- package/examples/react-chat-js/src/shared_io.js +12 -0
- package/examples/react-chat-js/vite.config.js +7 -0
- package/examples/server/index.js +12 -0
- package/examples/server/package.json +12 -0
- package/package.json +24 -12
- package/rollup.config.js +13 -8
- package/src/auth/Auth_File.js +1 -1
- package/src/client/IOCongSocket.js +20 -9
- package/src/client/IOCore.js +422 -77
- package/src/client/IOWS.js +12 -15
- package/src/client/browser/IOWebSocket.js +217 -0
- package/src/common/constants.js +91 -1
- package/test-nodejs/server-Auth_File.js +1 -1
- package/tsconfig.json +24 -0
- package/dist/iosignal.cjs +0 -23
- package/dist/iosignal.mjs +0 -23
- package/img/iosignal_stack.png +0 -0
- package/src/client/IOWebSocket.js +0 -118
- package/test-nodejs/client.cjs +0 -17
- package/test-nodejs/server-commonjs.cjs +0 -9
- /package/{auth_file.mjs → auth_file.js} +0 -0
- /package/test-nodejs/{client.mjs → client.js} +0 -0
- /package/test-nodejs/{client_api_reply.mjs → client_api_reply.js} +0 -0
- /package/test-nodejs/{server-esm.mjs → server.js} +0 -0
- /package/test-nodejs/{simple-server.mjs → simple-server.js} +0 -0
package/README.md
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
[ English | [한국어](docs/README.ko.md) ]
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
The signaling protocol is built-in, so the server can be used without programming.
|
|
3
|
+
# IOSignal
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
시그널링 프로토콜이 내장되어 있어서 서버는 프로그래밍 없이 사용 가능합니다.
|
|
5
|
+
IOSignal enables real-time communication across web browsers, Node.js, and Arduino. It features built-in secure authentication, encrypted communication, and a pre-configured signaling protocol, allowing server deployment without complex programming.
|
|
8
6
|
|
|
9
7
|
## Install
|
|
10
8
|
|
|
@@ -12,118 +10,183 @@ The signaling protocol is built-in, so the server can be used without programmin
|
|
|
12
10
|
$ npm i iosignal
|
|
13
11
|
```
|
|
14
12
|
|
|
15
|
-
## IOSignal Server
|
|
16
13
|
|
|
17
|
-
### ESM
|
|
18
|
-
```js
|
|
19
|
-
import { Server } from "iosignal"
|
|
20
|
-
const server = new Server( { port: 7777 } )
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
### CJS
|
|
24
|
-
```js
|
|
25
|
-
let { Server } = require('iosignal')
|
|
26
|
-
const server = new Server( { port: 7777 } )
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
### server options
|
|
30
14
|
|
|
15
|
+
## IOSignal Client
|
|
31
16
|
|
|
32
|
-
```js
|
|
33
|
-
let { Server } = require('iosignal')
|
|
34
|
-
|
|
35
|
-
const server = new Server(
|
|
36
|
-
{
|
|
37
|
-
port: 7777,
|
|
38
|
-
congPort: 8888,
|
|
39
|
-
showMetric: 2,
|
|
40
|
-
showMessage: 'message' // show signal message
|
|
41
|
-
})
|
|
42
17
|
|
|
18
|
+
### React Client Example
|
|
19
|
+
|
|
20
|
+
A sample React project is available in `examples/react-chat-js`. This example demonstrates how to integrate `iosignal` into a React application for real-time chat functionality.
|
|
21
|
+
|
|
22
|
+
**Key Concepts:**
|
|
23
|
+
|
|
24
|
+
- **`useRef`**: To maintain a stable reference to the `io` instance across component re-renders.
|
|
25
|
+
- **`useEffect`**: To manage the lifecycle of the `io` instance, including initialization and cleanup. Event handlers are set up within this hook.
|
|
26
|
+
- To release the `io` instance when the component unmounts, use `io.destroy()`. Event handlers registered during mount are also automatically removed.
|
|
27
|
+
|
|
28
|
+
**To run the example:**
|
|
29
|
+
|
|
30
|
+
1. Navigate to the server directory and start the server:
|
|
31
|
+
```shell
|
|
32
|
+
cd examples/server
|
|
33
|
+
npm install
|
|
34
|
+
node .
|
|
35
|
+
```
|
|
36
|
+
2. In a new terminal, navigate to the React project directory, install dependencies, and start the development server:
|
|
37
|
+
```shell
|
|
38
|
+
cd examples/react-chat-js
|
|
39
|
+
npm install
|
|
40
|
+
npm run dev
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**Example Code (`App.jsx`):**
|
|
44
|
+
|
|
45
|
+
If you open multiple browsers and enter a message, it will be delivered to each other via the server.
|
|
46
|
+
|
|
47
|
+
```javascript
|
|
48
|
+
import { useState, useEffect, useRef } from 'react';
|
|
49
|
+
import './App.css';
|
|
50
|
+
import IO from 'iosignal/io.js';
|
|
51
|
+
|
|
52
|
+
const url = 'ws://localhost:7777';
|
|
53
|
+
const channel_tag = 'channel#topic';
|
|
54
|
+
|
|
55
|
+
function App() {
|
|
56
|
+
const [messages, setMessages] = useState([]);
|
|
57
|
+
const [input, setInput] = useState('Hello, World!');
|
|
58
|
+
const [ioState, setIoState] = useState(null);
|
|
59
|
+
const [cid, setCid] = useState(null);
|
|
60
|
+
const [counts, setCounts] = useState({ instances: 0, websockets: 0 });
|
|
61
|
+
const ioRef = useRef(null);
|
|
62
|
+
const messagesEndRef = useRef(null);
|
|
63
|
+
|
|
64
|
+
const scrollToBottom = () => {
|
|
65
|
+
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
scrollToBottom();
|
|
70
|
+
}, [messages]);
|
|
71
|
+
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
ioRef.current = new IO(url);
|
|
74
|
+
setCounts({ instances: IO.instanceCount, websockets: IO.webSocketCount });
|
|
75
|
+
|
|
76
|
+
const handleReady = () => {
|
|
77
|
+
console.log('ready cid:', ioRef.current.cid);
|
|
78
|
+
setCid(ioRef.current.cid);
|
|
79
|
+
ioRef.current.subscribe(channel_tag);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const handleChange = (state) => {
|
|
83
|
+
setIoState(state);
|
|
84
|
+
setCounts({ instances: IO.instanceCount, websockets: IO.webSocketCount });
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const handleChannelMessage = (msgObj, tag) => {
|
|
88
|
+
console.log('Received message in App:', msgObj, tag);
|
|
89
|
+
if (typeof msgObj === 'string') {
|
|
90
|
+
msgObj = { text: msgObj, cid: 'cli unknown' };
|
|
91
|
+
}
|
|
92
|
+
setMessages((prevMessages) => [...prevMessages, `${msgObj.cid} : ${msgObj.text}`]);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const handleError = (error) => {
|
|
96
|
+
console.error('IO Error in App:', error);
|
|
97
|
+
setIoState(`Error: ${error.message}`);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
ioRef.current.on('ready', handleReady);
|
|
101
|
+
ioRef.current.on('change', handleChange);
|
|
102
|
+
ioRef.current.on(channel_tag, handleChannelMessage);
|
|
103
|
+
ioRef.current.on('error', handleError);
|
|
104
|
+
|
|
105
|
+
return () => {
|
|
106
|
+
ioRef.current.destroy();
|
|
107
|
+
console.log('IO instance destroyed.');
|
|
108
|
+
ioRef.current = null;
|
|
109
|
+
};
|
|
110
|
+
}, []);
|
|
111
|
+
|
|
112
|
+
const sendMessage = () => {
|
|
113
|
+
if (input.trim()) {
|
|
114
|
+
const msgObj = { text: input, cid: ioRef.current.cid };
|
|
115
|
+
ioRef.current.signal(channel_tag, msgObj);
|
|
116
|
+
setInput('date' + Date.now());
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const ioStateStyle = {
|
|
121
|
+
color: ioState === 'ready' ? 'green' : 'red',
|
|
122
|
+
fontWeight: 'bold',
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
return (
|
|
126
|
+
<div className="App">
|
|
127
|
+
<h1>React Chat Example</h1>
|
|
128
|
+
<div>URL: {url}</div>
|
|
129
|
+
<div>Channel: {channel_tag}</div>
|
|
130
|
+
<div>IO State: <span style={ioStateStyle}>{ioState}</span></div>
|
|
131
|
+
<div>Client ID: {cid}</div>
|
|
132
|
+
<div>IO Instances: {counts.instances}</div>
|
|
133
|
+
<div>WebSockets Created: {counts.websockets}</div>
|
|
134
|
+
<div className="messages">
|
|
135
|
+
{messages.map((msg, index) => (
|
|
136
|
+
<div key={index}>{msg}</div>
|
|
137
|
+
))}
|
|
138
|
+
<div ref={messagesEndRef} />
|
|
139
|
+
</div>
|
|
140
|
+
<div className="input-area">
|
|
141
|
+
<input
|
|
142
|
+
type="text"
|
|
143
|
+
value={input}
|
|
144
|
+
onChange={(e) => setInput(e.target.value)}
|
|
145
|
+
onKeyUp={(e) => e.key === 'Enter' && sendMessage()}
|
|
146
|
+
disabled={ioState !== 'ready'}
|
|
147
|
+
/>
|
|
148
|
+
<button onClick={sendMessage} disabled={ioState !== 'ready'}>
|
|
149
|
+
Send
|
|
150
|
+
</button>
|
|
151
|
+
</div>
|
|
152
|
+
</div>
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export default App;
|
|
43
157
|
```
|
|
44
158
|
|
|
45
|
-
- port: <Number> IOSignal over WebSocket
|
|
46
|
-
- congPort: <Number> IOsignal over CongSocket
|
|
47
|
-
- showMetric: 1|2|3 show clients cid(state) info
|
|
48
|
-
- showMessage: "none"|"message" show signal buffer message
|
|
49
|
-
- timeout <milliseconds> ping period & timeout (min. 1000)
|
|
50
|
-
|
|
51
|
-
### IOSignal API
|
|
52
159
|
|
|
53
|
-
|
|
54
|
-
- src/api_reply.js // 'echo', 'date', 'unixtime'
|
|
55
|
-
- src/api_sudo.js // server admin monitoring command
|
|
56
|
-
- src/RedisAPI.js // redis command and response service
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
To register an API service with the server, use the api() method
|
|
160
|
+
### Browser client : ESM
|
|
60
161
|
|
|
61
|
-
|
|
162
|
+
- local file: "dist/io.js"
|
|
163
|
+
- CDN: https://cdn.jsdelivr.net/npm/iosignal/dist/io.js
|
|
62
164
|
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
import { Server ,api_reply } from 'iosignal'
|
|
66
|
-
const server = new Server( { port: 7777 } )
|
|
67
|
-
server.api('reply', api_reply) // attach api module
|
|
68
|
-
```
|
|
165
|
+
```html
|
|
166
|
+
<html>
|
|
69
167
|
|
|
70
|
-
|
|
168
|
+
<script type="module">
|
|
169
|
+
import IO from "../dist/io.js"
|
|
71
170
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const io = new IO('ws://localhost:7777')
|
|
171
|
+
const io = new IO('wss://io.iosignal.net/ws')
|
|
172
|
+
io.listen('channel#topic', (...args)={
|
|
173
|
+
console.log( args )
|
|
174
|
+
})
|
|
77
175
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
let res_unixtime = await io.req('reply', 'unixtime' )
|
|
176
|
+
io.on('ready',()=>{
|
|
177
|
+
console.log('ready cid:', io.cid )
|
|
178
|
+
})
|
|
82
179
|
|
|
83
|
-
if( res_echo.ok ) console.log( res_echo.body )
|
|
84
|
-
if( res_date.ok ) console.log( res_date.body )
|
|
85
|
-
if( res_unixtime.ok ) console.log( res_unixtime.body )
|
|
86
|
-
});
|
|
87
180
|
</script>
|
|
88
181
|
|
|
89
|
-
|
|
90
|
-
[ 'hello' ]
|
|
91
|
-
Fri, 09 Feb 2024 14:24:37 GMT
|
|
92
|
-
1707488677
|
|
93
|
-
|
|
182
|
+
</html>
|
|
94
183
|
```
|
|
95
184
|
|
|
96
185
|
|
|
97
|
-
## IOSignal Client
|
|
98
|
-
|
|
99
|
-
### NodeJS Client
|
|
100
|
-
```js
|
|
101
|
-
// ESM
|
|
102
|
-
import { IO } from "iosignal"
|
|
103
|
-
|
|
104
|
-
// CJS
|
|
105
|
-
// const { IO } = require('iosignal')
|
|
106
|
-
|
|
107
|
-
const io = new IO('wss://io.iosignal.net/ws')
|
|
108
|
-
|
|
109
|
-
io.on('ready', ()=>{
|
|
110
|
-
console.log('ready cid:', io.cid)
|
|
111
|
-
io.signal('#screen','playToggle')
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
io.listen('#notify', (...args)=>{
|
|
115
|
-
console.log( args )
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
io.on('error',err=>{
|
|
119
|
-
console.log('err', err)
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
```
|
|
123
|
-
|
|
124
186
|
### Browser Client : UMD(IIFE)
|
|
125
|
-
- local file: "
|
|
126
|
-
- CDN: https://cdn.jsdelivr.net/npm/iosignal
|
|
187
|
+
- local file: "dist/io.min.js"
|
|
188
|
+
- CDN: https://cdn.jsdelivr.net/npm/iosignal/dist/io.min.js
|
|
189
|
+
|
|
127
190
|
```html
|
|
128
191
|
<html>
|
|
129
192
|
<script src="../dist/io.min.js"></script>
|
|
@@ -175,31 +238,101 @@ Fri, 09 Feb 2024 14:24:37 GMT
|
|
|
175
238
|
</html>
|
|
176
239
|
```
|
|
177
240
|
|
|
178
|
-
### Browser client : ESM
|
|
179
241
|
|
|
180
|
-
- local file: "./dist/io.js"
|
|
181
|
-
- CDN: https://cdn.jsdelivr.net/npm/iosignal@2.2.0/dist/io.js
|
|
182
242
|
|
|
183
|
-
```html
|
|
184
|
-
<html>
|
|
185
243
|
|
|
186
|
-
|
|
187
|
-
|
|
244
|
+
### NodeJS Client
|
|
245
|
+
```js
|
|
246
|
+
import { IO } from "iosignal"
|
|
188
247
|
|
|
189
|
-
|
|
190
|
-
io.listen('channel#topic', (...args)={
|
|
191
|
-
console.log( args )
|
|
192
|
-
})
|
|
248
|
+
const io = new IO('wss://io.iosignal.net/ws')
|
|
193
249
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
250
|
+
io.on('ready', ()=>{
|
|
251
|
+
console.log('ready cid:', io.cid)
|
|
252
|
+
io.signal('#screen','playToggle')
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
io.listen('#notify', (...args)=>{
|
|
256
|
+
console.log( args )
|
|
257
|
+
})
|
|
258
|
+
|
|
259
|
+
io.on('error',err=>{
|
|
260
|
+
console.log('err', err)
|
|
261
|
+
})
|
|
262
|
+
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
## IOSignal Server
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
```js
|
|
272
|
+
import { Server } from "iosignal"
|
|
273
|
+
|
|
274
|
+
const server = new Server(
|
|
275
|
+
{
|
|
276
|
+
port: 7777,
|
|
277
|
+
congPort: 8888,
|
|
278
|
+
showMetric: 2,
|
|
279
|
+
showMessage: 'message' // show signal message
|
|
280
|
+
})
|
|
281
|
+
|
|
282
|
+
```
|
|
197
283
|
|
|
284
|
+
- port: <Number> IOSignal over WebSocket
|
|
285
|
+
- congPort: <Number> IOsignal over CongSocket
|
|
286
|
+
- showMetric: 1|2|3 show clients cid(state) info
|
|
287
|
+
- showMessage: "none"|"message" show signal buffer message
|
|
288
|
+
- timeout <milliseconds> ping period & timeout (min. 1000)
|
|
289
|
+
|
|
290
|
+
### IOSignal API
|
|
291
|
+
|
|
292
|
+
IOSignal API examples
|
|
293
|
+
- src/api_reply.js // 'echo', 'date', 'unixtime'
|
|
294
|
+
- src/api_sudo.js // server admin monitoring command
|
|
295
|
+
- src/RedisAPI.js // redis command and response service
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
To register an API service with the server, use the api() method
|
|
299
|
+
|
|
300
|
+
`api('api_name', module )`
|
|
301
|
+
|
|
302
|
+
```js
|
|
303
|
+
// node.js
|
|
304
|
+
import { Server ,api_reply } from 'iosignal'
|
|
305
|
+
const server = new Server( { port: 7777 } )
|
|
306
|
+
server.api('reply', api_reply) // attach api module
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
Example of a client calling the reply API
|
|
310
|
+
|
|
311
|
+
```js
|
|
312
|
+
// web browser api client example
|
|
313
|
+
<script src="../dist/io.min.js"></script>
|
|
314
|
+
<script>
|
|
315
|
+
const io = new IO('ws://localhost:7777')
|
|
316
|
+
|
|
317
|
+
io.on('ready', async ()=>{
|
|
318
|
+
let res_echo = await io.req('reply', 'echo', 'hello' )
|
|
319
|
+
let res_date = await io.req('reply', 'date' )
|
|
320
|
+
let res_unixtime = await io.req('reply', 'unixtime' )
|
|
321
|
+
|
|
322
|
+
if( res_echo.ok ) console.log( res_echo.body )
|
|
323
|
+
if( res_date.ok ) console.log( res_date.body )
|
|
324
|
+
if( res_unixtime.ok ) console.log( res_unixtime.body )
|
|
325
|
+
});
|
|
198
326
|
</script>
|
|
199
327
|
|
|
200
|
-
|
|
328
|
+
// result
|
|
329
|
+
[ 'hello' ]
|
|
330
|
+
Fri, 09 Feb 2024 14:24:37 GMT
|
|
331
|
+
1707488677
|
|
332
|
+
|
|
201
333
|
```
|
|
202
334
|
|
|
335
|
+
|
|
203
336
|
## Features
|
|
204
337
|
|
|
205
338
|
### Built-in Message Trasport Protocol
|
|
@@ -220,7 +353,8 @@ Fri, 09 Feb 2024 14:24:37 GMT
|
|
|
220
353
|
- Node.js use WebSocket or CongSocket.
|
|
221
354
|
- Arduino use CongSocket.
|
|
222
355
|
|
|
223
|
-
|
|
356
|
+
## IOSignal Server Architecture
|
|
357
|
+

|
|
224
358
|
|
|
225
359
|
## IOSignal repositories.
|
|
226
360
|
|