iosignal 3.0.0 → 3.1.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.
- package/README.ko.md +566 -0
- package/README.md +561 -2
- package/dist/io.d.ts +481 -0
- package/dist/io.js +3 -3
- package/dist/io.js.map +1 -1
- package/dist/io.min.js +3 -3
- package/dist/io.min.js.map +1 -1
- package/dist/iosignal.js +558 -104
- 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/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 +1723 -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-lock.json +47 -0
- package/examples/server/package.json +12 -0
- package/examples/svelte-chat-js/.devtools +3 -0
- package/examples/svelte-chat-js/README.md +38 -0
- package/examples/svelte-chat-js/package-lock.json +1505 -0
- package/examples/svelte-chat-js/package.json +22 -0
- package/examples/svelte-chat-js/src/app.css +105 -0
- package/examples/svelte-chat-js/src/app.d.ts +13 -0
- package/examples/svelte-chat-js/src/app.html +12 -0
- package/examples/svelte-chat-js/src/lib/images/github.svg +1 -0
- package/examples/svelte-chat-js/src/lib/images/svelte-logo.svg +1 -0
- package/examples/svelte-chat-js/src/lib/images/svelte-welcome.png +0 -0
- package/examples/svelte-chat-js/src/lib/images/svelte-welcome.webp +0 -0
- package/examples/svelte-chat-js/src/lib/shared_io.js +12 -0
- package/examples/svelte-chat-js/src/routes/+layout.svelte +9 -0
- package/examples/svelte-chat-js/src/routes/+page.js +3 -0
- package/examples/svelte-chat-js/src/routes/+page.svelte +162 -0
- package/examples/svelte-chat-js/static/favicon.svg +1 -0
- package/examples/svelte-chat-js/static/global.css +19 -0
- package/examples/svelte-chat-js/static/robots.txt +3 -0
- package/examples/svelte-chat-js/svelte.config.js +15 -0
- package/examples/svelte-chat-js/vite.config.js +6 -0
- package/package.json +9 -3
- package/rollup.config.js +11 -4
- package/src/client/IOCongSocket.js +20 -9
- package/src/client/IOCore.js +437 -79
- package/src/client/IOWS.js +12 -15
- package/src/client/browser/IOWebSocket.js +101 -17
- package/src/common/constants.js +91 -1
- package/tsconfig.json +24 -0
- package/docs/README.kr.md +0 -230
package/src/client/IOWS.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { IOCore } from "./IOCore.js";
|
|
2
|
+
import { STATES } from "../common/constants.js";
|
|
2
3
|
import { WebSocket } from "ws";
|
|
3
4
|
|
|
4
5
|
// Node.js 'ws' websocket
|
|
@@ -10,32 +11,28 @@ export class IOWS extends IOCore {
|
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Closes ws WebSocket and cleans resources.
|
|
16
|
+
*/
|
|
13
17
|
close() {
|
|
14
18
|
if (this.socket) {
|
|
15
|
-
this.socket.
|
|
16
|
-
this.socket.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
this.socket = null;
|
|
19
|
+
this.socket.removeAllListeners();
|
|
20
|
+
if (this.socket.readyState !== WebSocket.CLOSED) {
|
|
21
|
+
this.socket.close();
|
|
22
|
+
}
|
|
20
23
|
}
|
|
21
|
-
|
|
24
|
+
super.close();
|
|
22
25
|
}
|
|
23
26
|
|
|
24
27
|
|
|
25
|
-
|
|
26
|
-
stop() {
|
|
27
|
-
this.close()
|
|
28
|
-
clearInterval(this.connectionCheckerIntervalID);
|
|
29
|
-
this.connectionCheckerIntervalID = null
|
|
30
|
-
}
|
|
31
|
-
|
|
32
28
|
keepAlive() {
|
|
33
|
-
if (!this.
|
|
29
|
+
if (!this.autoReconnect) return;
|
|
30
|
+
// Reconnect only if the socket is closed and the state reflects that.
|
|
31
|
+
if ((!this.socket || this.socket.readyState === WebSocket.CLOSED) && this.state === STATES.CLOSED) {
|
|
34
32
|
this.open();
|
|
35
33
|
}
|
|
36
34
|
}
|
|
37
35
|
|
|
38
|
-
|
|
39
36
|
createConnection(url) {
|
|
40
37
|
// node WebSocket
|
|
41
38
|
this.socket = new WebSocket(url);
|
|
@@ -3,23 +3,79 @@ import { IOCore } from "../IOCore.js";
|
|
|
3
3
|
import Boho from 'boho'
|
|
4
4
|
import * as constants from '../../common/constants.js'
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* @typedef {import("boho").Boho} Boho
|
|
8
|
+
* @typedef {import("boho").MBP} MBP
|
|
9
|
+
* @typedef {import("boho").Buffer} Buffer
|
|
10
|
+
*/
|
|
11
|
+
|
|
6
12
|
const Buffer = Boho.Buffer
|
|
7
13
|
|
|
8
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Browser WebSocket client extending IOCore.
|
|
16
|
+
* @augments {IOCore}
|
|
17
|
+
*/
|
|
9
18
|
export default class IO extends IOCore {
|
|
19
|
+
/**
|
|
20
|
+
* The version of the client.
|
|
21
|
+
* @type {string}
|
|
22
|
+
*/
|
|
10
23
|
static version = version
|
|
24
|
+
/**
|
|
25
|
+
* The binary type for WebSocket messages.
|
|
26
|
+
* @type {string}
|
|
27
|
+
*/
|
|
11
28
|
static binaryType = "arraybuffer"
|
|
29
|
+
/**
|
|
30
|
+
* The Boho library instance.
|
|
31
|
+
* @type {Boho}
|
|
32
|
+
*/
|
|
12
33
|
static Boho = Boho;
|
|
34
|
+
/**
|
|
35
|
+
* The MBP (MessagePack-Boho) instance.
|
|
36
|
+
* @type {MBP}
|
|
37
|
+
*/
|
|
13
38
|
static MBP = Boho.MBP;
|
|
39
|
+
/**
|
|
40
|
+
* The Buffer class from Boho.
|
|
41
|
+
* @type {Buffer}
|
|
42
|
+
*/
|
|
14
43
|
static Buffer = Boho.Buffer;
|
|
44
|
+
/**
|
|
45
|
+
* Constants used by the client.
|
|
46
|
+
* @type {object}
|
|
47
|
+
*/
|
|
15
48
|
static constants = constants
|
|
16
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Tracks the number of IO instances created.
|
|
52
|
+
* @type {number}
|
|
53
|
+
*/
|
|
54
|
+
static instanceCount = 0;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Tracks the number of WebSocket objects created.
|
|
58
|
+
* @type {number}
|
|
59
|
+
*/
|
|
60
|
+
static webSocketCount = 0;
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Creates an instance of IO.
|
|
66
|
+
* @param {string} url - The WebSocket URL to connect to.
|
|
67
|
+
*/
|
|
17
68
|
constructor(url) {
|
|
18
69
|
super(url);
|
|
19
|
-
|
|
70
|
+
IO.instanceCount++;
|
|
71
|
+
this.boundBrowserVisiblePing = this.browserVisiblePing.bind(this)
|
|
72
|
+
document.addEventListener('visibilitychange', this.boundBrowserVisiblePing);
|
|
20
73
|
if (url) this.open();
|
|
21
74
|
}
|
|
22
75
|
|
|
76
|
+
/**
|
|
77
|
+
* Pings the server when the browser tab becomes visible.
|
|
78
|
+
*/
|
|
23
79
|
browserVisiblePing() {
|
|
24
80
|
if (document.visibilityState === 'visible') {
|
|
25
81
|
this.ping()
|
|
@@ -27,41 +83,57 @@ export default class IO extends IOCore {
|
|
|
27
83
|
}
|
|
28
84
|
|
|
29
85
|
|
|
30
|
-
|
|
31
|
-
if (this.socket) {
|
|
32
|
-
this.socket.onclose = null
|
|
33
|
-
this.socket.onmessage = null
|
|
34
|
-
this.socket.onerror = null
|
|
35
|
-
this.socket.close();
|
|
36
|
-
this.socket = null;
|
|
37
|
-
}
|
|
38
|
-
this.emit('close')
|
|
39
|
-
}
|
|
40
|
-
|
|
86
|
+
|
|
41
87
|
|
|
88
|
+
/**
|
|
89
|
+
* Permanently stops the connection and cleans up its specific resources.
|
|
90
|
+
* For complete cleanup and to make the instance unusable, use destroy().
|
|
91
|
+
*/
|
|
42
92
|
stop() {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
93
|
+
super.stop();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Permanently destroys the instance, cleaning up all resources including global event listeners.
|
|
98
|
+
* The instance will not be usable after this.
|
|
99
|
+
*/
|
|
100
|
+
destroy() {
|
|
101
|
+
document.removeEventListener('visibilitychange', this.boundBrowserVisiblePing);
|
|
102
|
+
super.destroy();
|
|
46
103
|
}
|
|
47
104
|
|
|
48
105
|
|
|
106
|
+
/**
|
|
107
|
+
* Keeps the connection alive by re-opening if closed.
|
|
108
|
+
*/
|
|
49
109
|
keepAlive() {
|
|
50
|
-
if (!this.
|
|
110
|
+
if (!this.autoReconnect) return;
|
|
111
|
+
// Reconnect only if the socket is closed and the state reflects that.
|
|
112
|
+
if ((!this.socket || this.socket.readyState === WebSocket.CLOSED) && this.state === IO.constants.STATES.CLOSED) {
|
|
51
113
|
this.open();
|
|
52
114
|
}
|
|
53
115
|
}
|
|
54
116
|
|
|
55
117
|
|
|
56
118
|
|
|
119
|
+
/**
|
|
120
|
+
* Creates a new WebSocket connection.
|
|
121
|
+
* @param {string} url - The WebSocket URL to connect to.
|
|
122
|
+
*/
|
|
57
123
|
createConnection(url) {
|
|
58
124
|
// Web Browser WebSocket
|
|
125
|
+
IO.webSocketCount++;
|
|
59
126
|
this.socket = new WebSocket(url);
|
|
60
127
|
this.socket.binaryType = IO.binaryType
|
|
61
128
|
|
|
62
129
|
this.stateChange('opening')
|
|
63
130
|
|
|
64
131
|
this.socket.onopen = () => {
|
|
132
|
+
|
|
133
|
+
if (!this.socket) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
65
137
|
if (this.socket.binaryType == "arraybuffer") {
|
|
66
138
|
this.socket.onmessage = this.onWebSocketMessage.bind(this);
|
|
67
139
|
} else { // blob
|
|
@@ -79,6 +151,10 @@ export default class IO extends IOCore {
|
|
|
79
151
|
}
|
|
80
152
|
}
|
|
81
153
|
|
|
154
|
+
/**
|
|
155
|
+
* Handles incoming WebSocket messages (arraybuffer type).
|
|
156
|
+
* @param {MessageEvent} event - The WebSocket message event.
|
|
157
|
+
*/
|
|
82
158
|
onWebSocketMessage(event) {
|
|
83
159
|
// event.data is arrayBuffer or text_message
|
|
84
160
|
this.rxCounter++;
|
|
@@ -88,6 +164,10 @@ export default class IO extends IOCore {
|
|
|
88
164
|
this.emit('socket_data', buffer);
|
|
89
165
|
}
|
|
90
166
|
|
|
167
|
+
/**
|
|
168
|
+
* Handles incoming WebSocket messages (blob type).
|
|
169
|
+
* @param {MessageEvent} event - The WebSocket message event.
|
|
170
|
+
*/
|
|
91
171
|
async onWebSocketMessageBlob(event) {
|
|
92
172
|
// event.data is Blob or text_message
|
|
93
173
|
this.rxCounter++;
|
|
@@ -103,6 +183,10 @@ export default class IO extends IOCore {
|
|
|
103
183
|
this.emit('socket_data', buffer);
|
|
104
184
|
}
|
|
105
185
|
|
|
186
|
+
/**
|
|
187
|
+
* Sends data over the WebSocket.
|
|
188
|
+
* @param {BufferSource} data - The data to send.
|
|
189
|
+
*/
|
|
106
190
|
socket_send(data) {
|
|
107
191
|
if (this.socket?.readyState === 1) {
|
|
108
192
|
this.socket.send(data)
|
package/src/common/constants.js
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
|
|
2
|
+
/**
|
|
3
|
+
* @typedef {object} STATES
|
|
4
|
+
* @property {number} OPENING
|
|
5
|
+
* @property {number} OPEN
|
|
6
|
+
* @property {number} CLOSING
|
|
7
|
+
* @property {number} CLOSED
|
|
8
|
+
* @property {number} SERVER_READY
|
|
9
|
+
* @property {number} AUTH_FAIL
|
|
10
|
+
* @property {number} AUTH_READY
|
|
11
|
+
* @property {number} READY
|
|
12
|
+
* @property {number} REDIRECTING
|
|
13
|
+
*/
|
|
2
14
|
// Client STATES: name and number
|
|
3
15
|
export const STATES = {
|
|
4
16
|
OPENING: 0,
|
|
@@ -13,7 +25,17 @@ export const STATES = {
|
|
|
13
25
|
}
|
|
14
26
|
for (let c in STATES) { STATES[STATES[c]] = c }
|
|
15
27
|
|
|
16
|
-
|
|
28
|
+
/**
|
|
29
|
+
* @typedef {object} CLIENT_STATE
|
|
30
|
+
* @property {number} INIT
|
|
31
|
+
* @property {number} SENT_SERVER_READY
|
|
32
|
+
* @property {number} RECV_AUTH_REQ
|
|
33
|
+
* @property {number} SENT_SERVER_NONCE
|
|
34
|
+
* @property {number} RECV_AUTH_HMAC
|
|
35
|
+
* @property {number} AUTH_FAIL
|
|
36
|
+
* @property {number} AUTH_READY
|
|
37
|
+
* @property {number} CID_READY
|
|
38
|
+
*/
|
|
17
39
|
export const CLIENT_STATE = {
|
|
18
40
|
INIT: 0,
|
|
19
41
|
SENT_SERVER_READY: 1,
|
|
@@ -26,6 +48,12 @@ export const CLIENT_STATE = {
|
|
|
26
48
|
}
|
|
27
49
|
for (let c in CLIENT_STATE) { CLIENT_STATE[CLIENT_STATE[c]] = c }
|
|
28
50
|
|
|
51
|
+
/**
|
|
52
|
+
* @typedef {object} ENC_MODE
|
|
53
|
+
* @property {number} NO
|
|
54
|
+
* @property {number} YES
|
|
55
|
+
* @property {number} AUTO
|
|
56
|
+
*/
|
|
29
57
|
export let ENC_MODE = {
|
|
30
58
|
NO: 0,
|
|
31
59
|
YES: 1,
|
|
@@ -35,6 +63,15 @@ export let ENC_MODE = {
|
|
|
35
63
|
for (let c in ENC_MODE) { ENC_MODE[ENC_MODE[c]] = c }
|
|
36
64
|
|
|
37
65
|
|
|
66
|
+
/**
|
|
67
|
+
* @typedef {object} SIZE_LIMIT
|
|
68
|
+
* @property {number} TAG_LEN1
|
|
69
|
+
* @property {number} TAG_LEN2
|
|
70
|
+
* @property {number} CONNECTION_CHECKER_PERIOD
|
|
71
|
+
* @property {number} PROMISE_TIMEOUT
|
|
72
|
+
* @property {number} DID
|
|
73
|
+
* @property {number} CID
|
|
74
|
+
*/
|
|
38
75
|
export const SIZE_LIMIT = {
|
|
39
76
|
TAG_LEN1: 255,
|
|
40
77
|
TAG_LEN2: 65535,
|
|
@@ -44,6 +81,15 @@ export const SIZE_LIMIT = {
|
|
|
44
81
|
CID: 12
|
|
45
82
|
}
|
|
46
83
|
|
|
84
|
+
/**
|
|
85
|
+
* @typedef {object} PAYLOAD_TYPE
|
|
86
|
+
* @property {number} EMPTY
|
|
87
|
+
* @property {number} TEXT
|
|
88
|
+
* @property {number} BINARY
|
|
89
|
+
* @property {number} OBJECT
|
|
90
|
+
* @property {number} MJSON
|
|
91
|
+
* @property {number} MBA
|
|
92
|
+
*/
|
|
47
93
|
export let PAYLOAD_TYPE = {
|
|
48
94
|
EMPTY: 0,
|
|
49
95
|
TEXT: 1,
|
|
@@ -55,6 +101,40 @@ export let PAYLOAD_TYPE = {
|
|
|
55
101
|
for (let c in PAYLOAD_TYPE) { PAYLOAD_TYPE[PAYLOAD_TYPE[c]] = c }
|
|
56
102
|
|
|
57
103
|
|
|
104
|
+
/**
|
|
105
|
+
* @typedef {object} IOMsg
|
|
106
|
+
* @property {number} SERVER_READY
|
|
107
|
+
* @property {number} CID_REQ
|
|
108
|
+
* @property {number} CID_RES
|
|
109
|
+
* @property {number} QUOTA_LEVEL
|
|
110
|
+
* @property {number} SERVER_CLEAR_AUTH
|
|
111
|
+
* @property {number} SERVER_REDIRECT
|
|
112
|
+
* @property {number} LOOP
|
|
113
|
+
* @property {number} ECHO
|
|
114
|
+
* @property {number} PING
|
|
115
|
+
* @property {number} PONG
|
|
116
|
+
* @property {number} CLOSE
|
|
117
|
+
* @property {number} SIGNAL
|
|
118
|
+
* @property {number} SIGNAL_REQ
|
|
119
|
+
* @property {number} SIGNAL_E2E
|
|
120
|
+
* @property {number} SUBSCRIBE
|
|
121
|
+
* @property {number} SUBSCRIBE_REQ
|
|
122
|
+
* @property {number} UNSUBSCRIBE
|
|
123
|
+
* @property {number} SERVER_SIGNAL
|
|
124
|
+
* @property {number} IAM
|
|
125
|
+
* @property {number} IAM_RES
|
|
126
|
+
* @property {number} SET
|
|
127
|
+
* @property {number} RESPONSE_CODE
|
|
128
|
+
* @property {number} RESPONSE_MBP
|
|
129
|
+
* @property {number} REQUEST
|
|
130
|
+
* @property {number} RESPONSE
|
|
131
|
+
* @property {number} FLOW_MODE
|
|
132
|
+
* @property {number} WAIT
|
|
133
|
+
* @property {number} RESUME
|
|
134
|
+
* @property {number} TIME_OUT
|
|
135
|
+
* @property {number} OVER_SIZE
|
|
136
|
+
* @property {number} OVER_FLOW
|
|
137
|
+
*/
|
|
58
138
|
// IO message's one-byte headers.
|
|
59
139
|
export let IOMsg = {
|
|
60
140
|
|
|
@@ -134,11 +214,21 @@ export let IOMsg = {
|
|
|
134
214
|
for (let c in IOMsg) { IOMsg[IOMsg[c]] = c }
|
|
135
215
|
// console.log( IOMsg );
|
|
136
216
|
|
|
217
|
+
/**
|
|
218
|
+
* @typedef {object} API_TYPE
|
|
219
|
+
* @property {string} REQUEST_RESPONSE
|
|
220
|
+
* @property {string} ONE_WAY
|
|
221
|
+
*/
|
|
137
222
|
export const API_TYPE = {
|
|
138
223
|
'REQUEST_RESPONSE': 'requet_response',
|
|
139
224
|
'ONE_WAY': 'one_way'
|
|
140
225
|
}
|
|
141
226
|
|
|
227
|
+
/**
|
|
228
|
+
* @typedef {object} STATUS
|
|
229
|
+
* @property {number} OK
|
|
230
|
+
* @property {number} ERROR
|
|
231
|
+
*/
|
|
142
232
|
// api response status code
|
|
143
233
|
export const STATUS = {
|
|
144
234
|
OK: 0,
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"declaration": true,
|
|
4
|
+
"emitDeclarationOnly": true,
|
|
5
|
+
"outDir": "./dist/types",
|
|
6
|
+
"allowJs": true,
|
|
7
|
+
"moduleResolution": "node",
|
|
8
|
+
"target": "es2015",
|
|
9
|
+
"lib": ["es2020", "dom"],
|
|
10
|
+
"baseUrl": ".",
|
|
11
|
+
"paths": {
|
|
12
|
+
"@src/*": ["src/*"]
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"include": [
|
|
16
|
+
"src/client/browser/IOWebSocket.js",
|
|
17
|
+
"src/client/IOCore.js",
|
|
18
|
+
"src/common/constants.js",
|
|
19
|
+
"package.json"
|
|
20
|
+
],
|
|
21
|
+
"exclude": [
|
|
22
|
+
"node_modules"
|
|
23
|
+
]
|
|
24
|
+
}
|
package/docs/README.kr.md
DELETED
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
[ [en](../README.md) | kr ]
|
|
2
|
-
|
|
3
|
-
# IOSignal
|
|
4
|
-
|
|
5
|
-
IOSignal은 웹 브라우저, Node.js, 아두이노 간의 실시간 통신을 지원합니다. 또한 안전한 인증 및 암호화된 통신을 제공합니다. 시그널링 프로토콜이 내장되어 있어 프로그래밍 없이 서버를 사용할 수 있습니다.
|
|
6
|
-
|
|
7
|
-
## 설치
|
|
8
|
-
|
|
9
|
-
```shell
|
|
10
|
-
$ npm i iosignal
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## IOSignal 클라이언트
|
|
14
|
-
|
|
15
|
-
### 브라우저 클라이언트 : ESM
|
|
16
|
-
|
|
17
|
-
- 로컬 파일: "dist/io.js"
|
|
18
|
-
- CDN: https://cdn.jsdelivr.net/npm/iosignal/dist/io.js
|
|
19
|
-
|
|
20
|
-
```html
|
|
21
|
-
<html>
|
|
22
|
-
|
|
23
|
-
<script type="module">
|
|
24
|
-
import IO from "../dist/io.js"
|
|
25
|
-
|
|
26
|
-
const io = new IO('wss://io.iosignal.net/ws')
|
|
27
|
-
io.listen('channel#topic', (...args)=>{
|
|
28
|
-
console.log( args )
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
io.on('ready',()=>{
|
|
32
|
-
console.log('ready cid:', io.cid )
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
</script>
|
|
36
|
-
|
|
37
|
-
</html>
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
### 브라우저 클라이언트 : UMD(IIFE)
|
|
41
|
-
- 로컬 파일: "dist/io.min.js"
|
|
42
|
-
- CDN: https://cdn.jsdelivr.net/npm/iosignal/dist/io.min.js
|
|
43
|
-
|
|
44
|
-
```html
|
|
45
|
-
<html>
|
|
46
|
-
<script src="../dist/io.min.js"></script>
|
|
47
|
-
<script>
|
|
48
|
-
console.log('IO', IO) // 기본 전역 변수 이름은 IO
|
|
49
|
-
|
|
50
|
-
var io1 = new IO('ws://localhost:7777')
|
|
51
|
-
var io2 = new IO('ws://localhost:7777')
|
|
52
|
-
var io3 = new IO('ws://localhost:7777')
|
|
53
|
-
|
|
54
|
-
io1.on('error', errorHandler )
|
|
55
|
-
io2.on('error', errorHandler )
|
|
56
|
-
io3.on('error', errorHandler )
|
|
57
|
-
|
|
58
|
-
let channelName = 'io'
|
|
59
|
-
|
|
60
|
-
// 고전적인 스타일의 구독
|
|
61
|
-
io1.on('ready',e=>{
|
|
62
|
-
io1.subscribe(channelName)
|
|
63
|
-
io1.on(channelName, (...args)=>{
|
|
64
|
-
// console.log('io1 received', args )
|
|
65
|
-
let msg = '[io1] ' + JSON.stringify( args )
|
|
66
|
-
addMessage(msg)
|
|
67
|
-
})
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
// iosignal 스타일의 구독
|
|
71
|
-
io2.listen(channelName, (...args)=>{
|
|
72
|
-
// console.log('io2 receive', args )
|
|
73
|
-
let msg = '[io2] ' + JSON.stringify( args )
|
|
74
|
-
addMessage(msg)
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
setInterval(e=>{
|
|
78
|
-
io3.signal(channelName, 'single string') // 단일 문자열 페이로드
|
|
79
|
-
io3.signal(channelName, Date.now(), 'a', 2 , {key: 3} ) // 다중 페이로드
|
|
80
|
-
io3.signal(channelName ) // 페이로드 없는 순수 시그널
|
|
81
|
-
},3000)
|
|
82
|
-
|
|
83
|
-
function addMessage(msg){
|
|
84
|
-
// ...
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function errorHandler(e){
|
|
88
|
-
// ...
|
|
89
|
-
}
|
|
90
|
-
</script>
|
|
91
|
-
|
|
92
|
-
</html>
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
### NodeJS 클라이언트
|
|
96
|
-
```js
|
|
97
|
-
import { IO } from "iosignal"
|
|
98
|
-
|
|
99
|
-
const io = new IO('wss://io.iosignal.net/ws')
|
|
100
|
-
|
|
101
|
-
io.on('ready', ()=>{
|
|
102
|
-
console.log('ready cid:', io.cid)
|
|
103
|
-
io.signal('#screen','playToggle')
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
io.listen('#notify', (...args)=>{
|
|
107
|
-
console.log( args )
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
io.on('error',err=>{
|
|
111
|
-
console.log('err', err)
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
## IOSignal 서버
|
|
117
|
-
|
|
118
|
-
```js
|
|
119
|
-
import { Server } from "iosignal"
|
|
120
|
-
|
|
121
|
-
const server = new Server(
|
|
122
|
-
{
|
|
123
|
-
port: 7777,
|
|
124
|
-
congPort: 8888,
|
|
125
|
-
showMetric: 2,
|
|
126
|
-
showMessage: 'message' // 시그널 메시지 표시
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
- port: <Number> WebSocket을 통한 IOSignal
|
|
132
|
-
- congPort: <Number> CongSocket을 통한 IOSignal
|
|
133
|
-
- showMetric: 1|2|3 클라이언트 CID(상태) 정보 표시
|
|
134
|
-
- showMessage: "none"|"message" 시그널 버퍼 메시지 표시
|
|
135
|
-
- timeout <milliseconds> 핑 주기 및 타임아웃 (최소 1000)
|
|
136
|
-
|
|
137
|
-
### IOSignal API
|
|
138
|
-
|
|
139
|
-
IOSignal API 예시
|
|
140
|
-
- src/api_reply.js // 'echo', 'date', 'unixtime'
|
|
141
|
-
- src/api_sudo.js // 서버 관리자 모니터링 명령어
|
|
142
|
-
- src/RedisAPI.js // Redis 명령어 및 응답 서비스
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
서버에 API 서비스를 등록하려면 api() 메서드를 사용합니다.
|
|
146
|
-
|
|
147
|
-
`api('api_name', module )`
|
|
148
|
-
|
|
149
|
-
```js
|
|
150
|
-
// node.js
|
|
151
|
-
import { Server ,api_reply } from 'iosignal'
|
|
152
|
-
const server = new Server( { port: 7777 } )
|
|
153
|
-
server.api('reply', api_reply) // API 모듈 연결
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
클라이언트가 reply API를 호출하는 예시
|
|
157
|
-
|
|
158
|
-
```js
|
|
159
|
-
// 웹 브라우저 API 클라이언트 예시
|
|
160
|
-
<script src="../dist/io.min.js"></script>
|
|
161
|
-
<script>
|
|
162
|
-
const io = new IO('ws://localhost:7777')
|
|
163
|
-
|
|
164
|
-
io.on('ready', async ()=>{
|
|
165
|
-
let res_echo = await io.req('reply', 'echo', 'hello' )
|
|
166
|
-
let res_date = await io.req('reply', 'date' )
|
|
167
|
-
let res_unixtime = await io.req('reply', 'unixtime' )
|
|
168
|
-
|
|
169
|
-
if( res_echo.ok ) console.log( res_echo.body )
|
|
170
|
-
if( res_date.ok ) console.log( res_date.body )
|
|
171
|
-
if( res_unixtime.ok ) console.log( res_unixtime.body )
|
|
172
|
-
});
|
|
173
|
-
</script>
|
|
174
|
-
|
|
175
|
-
// 결과
|
|
176
|
-
[ 'hello' ]
|
|
177
|
-
Fri, 09 Feb 2024 14:24:37 GMT
|
|
178
|
-
1707488677
|
|
179
|
-
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
## 기능
|
|
183
|
-
|
|
184
|
-
### 내장 메시지 전송 프로토콜
|
|
185
|
-
- 채널 이름을 통한 pub/sub 멀티캐스트.
|
|
186
|
-
- 유니캐스트: CID를 통한 일대일 메시징.
|
|
187
|
-
- `CID`는 통신 ID입니다.
|
|
188
|
-
- CID 구독: CID를 사용하여 하나의 피어 구독.
|
|
189
|
-
- HomeChannel: IP 주소별 그룹화.
|
|
190
|
-
|
|
191
|
-
### 내장 보안
|
|
192
|
-
- 인증
|
|
193
|
-
- 암호화
|
|
194
|
-
- E2EE
|
|
195
|
-
- `Boho` 덕분입니다 [ [github](https://github.com/remocons/boho) ]
|
|
196
|
-
|
|
197
|
-
## 연결
|
|
198
|
-
- 웹 브라우저는 WebSocket을 사용합니다.
|
|
199
|
-
- Node.js는 WebSocket 또는 CongSocket을 사용합니다.
|
|
200
|
-
- 아두이노는 CongSocket을 사용합니다.
|
|
201
|
-
|
|
202
|
-
## IOSignal 서버 아키텍처
|
|
203
|
-

|
|
204
|
-
|
|
205
|
-
## IOSignal 저장소
|
|
206
|
-
|
|
207
|
-
- Javascript: `iosignal` [ [github](https://github.com/remocons/iosignal) | [npm](https://www.npmjs.com/package/iosignal) ]
|
|
208
|
-
- Node.js 서버 (WebSocket, CongSocket)
|
|
209
|
-
- Node.js 클라이언트 (WebSocket, CongSocket)
|
|
210
|
-
- 웹 브라우저 클라이언트 (WebSocket)
|
|
211
|
-
|
|
212
|
-
- CLI 프로그램
|
|
213
|
-
- `iosignal-cli` [ [github](https://github.com/remocons/iosignal-cli) | [npm](https://www.npmjs.com/package/iosignal-cli) ]
|
|
214
|
-
- 설치: `npm i -g iosignal-cli` 또는 `sudo npm i -g iosignal-cli`
|
|
215
|
-
- Mac, Linux, Windows 지원.
|
|
216
|
-
- 서버 및 클라이언트
|
|
217
|
-
|
|
218
|
-
- 아두이노 iosignal 라이브러리 및 예시:
|
|
219
|
-
- 아두이노 라이브러리 관리자 사용: `iosignal`
|
|
220
|
-
- 또는 `iosignal-arduino` [ [github](https://github.com/remocons/iosignal-arduino) ]
|
|
221
|
-
- 웹 앱 : http://test.iosignal.net
|
|
222
|
-
|
|
223
|
-
- 아두이노 remocon 라이브러리 및 예시:
|
|
224
|
-
- 아두이노 라이브러리 관리자 사용: `remocon`
|
|
225
|
-
- 또는 `remocon-arduino` [ [github](https://github.com/remocons/remocon-arduino) ]
|
|
226
|
-
- 웹 앱 : https://remocon.kr
|
|
227
|
-
|
|
228
|
-
## 라이선스
|
|
229
|
-
|
|
230
|
-
이 코드는 MIT 라이선스에 따라 배포됩니다.
|