iosignal 2.2.0 → 3.0.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/LICENSE +1 -1
- package/README.md +109 -118
- package/dist/io.js +7 -10
- package/dist/io.js.map +1 -1
- package/dist/io.min.js +7 -10
- package/dist/io.min.js.map +1 -1
- package/dist/iosignal.js +9118 -0
- package/docs/README.kr.md +230 -0
- package/docs/iosignal_architecture.png +0 -0
- package/package.json +28 -22
- package/rollup.config.js +2 -4
- package/src/auth/Auth_File.js +1 -1
- package/src/client/{IOWebSocket.js → browser/IOWebSocket.js} +3 -3
- package/test-browser/index.html +1 -1
- package/test-nodejs/server-Auth_File.js +1 -1
- package/dist/iosignal.cjs +0 -25
- package/dist/iosignal.mjs +0 -25
- package/img/iosignal_stack.png +0 -0
- 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
|
@@ -0,0 +1,230 @@
|
|
|
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 라이선스에 따라 배포됩니다.
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "iosignal",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "iosignal",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
"import": "./dist/iosignal.js",
|
|
9
|
+
"require": null
|
|
10
|
+
},
|
|
11
11
|
"./io": "./dist/io.js",
|
|
12
12
|
"./io.js": "./dist/io.js",
|
|
13
13
|
"./browser": "./dist/io.js"
|
|
@@ -15,34 +15,34 @@
|
|
|
15
15
|
"browser": "./dist/io.min.js",
|
|
16
16
|
"jsdelivr": "./dist/io.min.js",
|
|
17
17
|
"unpkg": "./dist/io.min.js",
|
|
18
|
-
"devDependencies": {
|
|
19
|
-
"@rollup/plugin-json": "^6.1.0",
|
|
20
|
-
"@rollup/plugin-commonjs": "^28.0.0",
|
|
21
|
-
"@rollup/plugin-node-resolve": "^15.3.0",
|
|
22
|
-
"@rollup/plugin-terser": "^0.4.4",
|
|
23
|
-
"rollup": "^4.22.4"
|
|
24
|
-
},
|
|
25
18
|
"scripts": {
|
|
26
19
|
"build": "rollup -c",
|
|
27
20
|
"start": "node ./test-browser/server.js"
|
|
28
21
|
},
|
|
29
22
|
"engines": {
|
|
30
|
-
"node": ">=
|
|
23
|
+
"node": ">=18.0.0"
|
|
31
24
|
},
|
|
32
25
|
"author": {
|
|
33
|
-
"name": "Lee
|
|
34
|
-
"email": "
|
|
26
|
+
"name": "Taeo Lee",
|
|
27
|
+
"email": "sixgen@gmail.com"
|
|
35
28
|
},
|
|
36
29
|
"license": "MIT",
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@rollup/plugin-commonjs": "^28.0.0",
|
|
32
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
33
|
+
"@rollup/plugin-node-resolve": "^15.3.0",
|
|
34
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
35
|
+
"rollup": "^4.36.0"
|
|
36
|
+
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"boho": "^1.
|
|
38
|
+
"boho": "^1.1.1",
|
|
39
39
|
"eventemitter3": "^5.0.1",
|
|
40
|
-
"meta-buffer-pack": "^2.0
|
|
41
|
-
"ws": "^8.18.
|
|
40
|
+
"meta-buffer-pack": "^2.1.0",
|
|
41
|
+
"ws": "^8.18.3"
|
|
42
42
|
},
|
|
43
43
|
"optionalDependencies": {
|
|
44
|
-
"bufferutil": "^4.0.
|
|
45
|
-
"utf-8-validate": "^6.0.
|
|
44
|
+
"bufferutil": "^4.0.9",
|
|
45
|
+
"utf-8-validate": "^6.0.5"
|
|
46
46
|
},
|
|
47
47
|
"repository": {
|
|
48
48
|
"type": "git",
|
|
@@ -52,9 +52,15 @@
|
|
|
52
52
|
"keywords": [
|
|
53
53
|
"websocket",
|
|
54
54
|
"pubsub",
|
|
55
|
-
"
|
|
55
|
+
"messaging",
|
|
56
|
+
"real-time",
|
|
57
|
+
"signaling",
|
|
58
|
+
"signal",
|
|
59
|
+
"client-server",
|
|
60
|
+
"nodejs",
|
|
61
|
+
"browser",
|
|
56
62
|
"iot",
|
|
57
|
-
"
|
|
58
|
-
"
|
|
63
|
+
"arduino",
|
|
64
|
+
"auth"
|
|
59
65
|
]
|
|
60
66
|
}
|
package/rollup.config.js
CHANGED
|
@@ -5,7 +5,7 @@ import terser from '@rollup/plugin-terser'
|
|
|
5
5
|
|
|
6
6
|
export default [
|
|
7
7
|
{
|
|
8
|
-
input: './src/client/IOWebSocket.js',
|
|
8
|
+
input: './src/client/browser/IOWebSocket.js',
|
|
9
9
|
output: [
|
|
10
10
|
{
|
|
11
11
|
file: './dist/io.js',
|
|
@@ -31,8 +31,7 @@ export default [
|
|
|
31
31
|
{
|
|
32
32
|
input: './index.js',
|
|
33
33
|
output: [
|
|
34
|
-
{ file: './dist/iosignal.
|
|
35
|
-
{ file: './dist/iosignal.mjs', format: 'es' }
|
|
34
|
+
{ file: './dist/iosignal.js', format: 'es' }
|
|
36
35
|
],
|
|
37
36
|
plugins: [
|
|
38
37
|
resolve({
|
|
@@ -40,7 +39,6 @@ export default [
|
|
|
40
39
|
}),
|
|
41
40
|
json(),
|
|
42
41
|
commonjs()
|
|
43
|
-
,terser()
|
|
44
42
|
]
|
|
45
43
|
}
|
|
46
44
|
|
package/src/auth/Auth_File.js
CHANGED
|
@@ -11,7 +11,7 @@ export class Auth_File extends BohoAuth {
|
|
|
11
11
|
this.path = path.resolve(_path)
|
|
12
12
|
console.log('auth from file path:', this.path)
|
|
13
13
|
let ext = pathObj.ext;
|
|
14
|
-
if (ext.toLowerCase() == '.js'
|
|
14
|
+
if (ext.toLowerCase() == '.js') {
|
|
15
15
|
// Read auth data from file
|
|
16
16
|
console.log("#JS path:", this.path);
|
|
17
17
|
this.loadAuthInfoFile_JS(this.path)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {version} from "
|
|
2
|
-
import { IOCore } from "
|
|
1
|
+
import {version} from "../../../package.json";
|
|
2
|
+
import { IOCore } from "../IOCore.js";
|
|
3
3
|
import Boho from 'boho'
|
|
4
|
-
import * as constants from '
|
|
4
|
+
import * as constants from '../../common/constants.js'
|
|
5
5
|
|
|
6
6
|
const Buffer = Boho.Buffer
|
|
7
7
|
|
package/test-browser/index.html
CHANGED
|
@@ -7,6 +7,6 @@ const options = {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
// const server = new Server( options, new Auth_File('../authInfo.json') ) // JSON version. cannot add comments.
|
|
10
|
-
const server = new Server(options, new Auth_File('../auth_file.
|
|
10
|
+
const server = new Server(options, new Auth_File('../auth_file.js')) // JS version. it support comments.
|
|
11
11
|
|
|
12
12
|
|