iosignal 5.2.0 → 6.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.md +163 -0
- package/dist/browser/esm/io.d.ts +17 -12
- package/dist/browser/esm/io.js +5 -5
- package/dist/browser/esm/io.js.map +1 -1
- package/dist/browser/iife/io.js +5 -5
- package/dist/browser/iife/io.js.map +1 -1
- package/dist/node/iosignal.cjs +195 -550
- package/dist/node/iosignal.js +193 -548
- package/dist/types/client/IOCore.d.ts +11 -5
- package/dist/types/client/browser/IOWebSocket.d.ts +4 -4
- package/dist/types/common/payload.d.ts +2 -2
- package/package.json +22 -4
- package/.vscode/settings.json +0 -3
- package/index.js +0 -26
- package/rollup.config.js +0 -59
- package/src/auth/BohoAuth.js +0 -196
- package/src/auth/key_providers/FileKeyProvider.js +0 -59
- package/src/auth/key_providers/RedisKeyProvider.js +0 -46
- package/src/auth/key_providers/StringKeyProvider.js +0 -54
- package/src/client/CongPacket.js +0 -143
- package/src/client/IOCongSocket.js +0 -92
- package/src/client/IOCore.js +0 -1202
- package/src/client/IOWS.js +0 -78
- package/src/client/browser/IOWebSocket.js +0 -202
- package/src/common/constants.js +0 -210
- package/src/common/payload.js +0 -82
- package/src/common/quotaTable.js +0 -68
- package/src/common/util.js +0 -64
- package/src/server/FileLogger.js +0 -30
- package/src/server/Manager.js +0 -450
- package/src/server/Metrics.js +0 -155
- package/src/server/Remote.js +0 -216
- package/src/server/RemoteCore.js +0 -427
- package/src/server/Server.js +0 -236
- package/src/server/serverOption.js +0 -56
- package/src/services/RedisService.js +0 -53
- package/src/services/constant.js +0 -7
- package/src/services/replyService.js +0 -39
- package/src/services/sudoService.js +0 -85
- package/tsconfig.json +0 -25
package/README.md
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# iosignal
|
|
2
|
+
|
|
3
|
+
Node.js와 브라우저를 위한 실시간 메시징 라이브러리입니다. WebSocket 기반
|
|
4
|
+
클라이언트·서버 통신, 태그 기반 발행/구독, RPC 서비스를 제공합니다.
|
|
5
|
+
Node.js에서는 TCP 기반 `IOCongSocket`도 사용할 수 있습니다.
|
|
6
|
+
|
|
7
|
+
## 설치
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install iosignal
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
아래 Node.js 예제는 ESM 형식입니다. `.mjs` 파일로 저장하거나 프로젝트의
|
|
14
|
+
`package.json`에 `"type": "module"`을 설정하세요.
|
|
15
|
+
|
|
16
|
+
## 빠른 시작
|
|
17
|
+
|
|
18
|
+
### 서버
|
|
19
|
+
|
|
20
|
+
다음을 `server.mjs`로 저장하고 `node server.mjs`로 실행합니다.
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
import { Server, replyService } from 'iosignal';
|
|
24
|
+
|
|
25
|
+
const server = new Server({ port: 8080 });
|
|
26
|
+
server.attach('reply', replyService);
|
|
27
|
+
|
|
28
|
+
server.on('ready', () => {
|
|
29
|
+
console.log(`Listening on port ${server.port}`);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
process.once('SIGINT', () => server.close());
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
이 예제는 인증 없는 로컬 개발용 서버입니다.
|
|
36
|
+
|
|
37
|
+
### Node.js 클라이언트
|
|
38
|
+
|
|
39
|
+
서버 실행 후 다음을 `client.mjs`로 저장하고 `node client.mjs`로 실행합니다.
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
import { IO } from 'iosignal';
|
|
43
|
+
|
|
44
|
+
const io = new IO('ws://localhost:8080');
|
|
45
|
+
io.on('error', console.error);
|
|
46
|
+
|
|
47
|
+
io.on('ready', async () => {
|
|
48
|
+
try {
|
|
49
|
+
const response = await io.call('reply', 'echo', 'Hello, iosignal!');
|
|
50
|
+
console.log(response.body);
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.error(error);
|
|
53
|
+
} finally {
|
|
54
|
+
io.stop();
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
CommonJS에서도 공개 API를 사용할 수 있습니다.
|
|
60
|
+
|
|
61
|
+
```js
|
|
62
|
+
const { IO, Server, replyService } = require('iosignal');
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## 발행과 구독
|
|
66
|
+
|
|
67
|
+
연결이 준비되면 `subscribe()`로 태그를 구독하고 `signal()`로 메시지를 보냅니다.
|
|
68
|
+
다음 클라이언트는 메시지를 계속 수신합니다.
|
|
69
|
+
|
|
70
|
+
```js
|
|
71
|
+
import { IO } from 'iosignal';
|
|
72
|
+
|
|
73
|
+
const io = new IO('ws://localhost:8080');
|
|
74
|
+
io.on('error', console.error);
|
|
75
|
+
io.on('message', (tag, message) => {
|
|
76
|
+
console.log(tag, message);
|
|
77
|
+
});
|
|
78
|
+
io.on('ready', () => {
|
|
79
|
+
io.subscribe('room');
|
|
80
|
+
io.signal('room', 'Hello, subscribers!');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
process.once('SIGINT', () => io.stop());
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
`signal(tag, ...args)`는 문자열, 바이너리, 객체 및 여러 인자를 지원합니다.
|
|
87
|
+
`unsubscribe(tag)`로 구독을 해제할 수 있습니다.
|
|
88
|
+
|
|
89
|
+
## 브라우저
|
|
90
|
+
|
|
91
|
+
번들러를 사용하는 브라우저 프로젝트에서는 브라우저 전용 진입점을 가져옵니다.
|
|
92
|
+
|
|
93
|
+
```js
|
|
94
|
+
import IO from 'iosignal/io';
|
|
95
|
+
|
|
96
|
+
const io = new IO('ws://localhost:8080');
|
|
97
|
+
io.on('error', console.error);
|
|
98
|
+
io.on('message', (tag, message) => console.log(tag, message));
|
|
99
|
+
io.on('ready', () => {
|
|
100
|
+
io.subscribe('room');
|
|
101
|
+
io.signal('room', 'Hello from the browser!');
|
|
102
|
+
});
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
브라우저 예제도 위 서버에 연결합니다. HTTPS 페이지에서는 TLS가 구성된
|
|
106
|
+
`wss://` 서버 주소를 사용하세요. 사용이 끝나면 `io.stop()`으로 연결과 자동 재연결을 중단합니다.
|
|
107
|
+
|
|
108
|
+
## 주요 API
|
|
109
|
+
|
|
110
|
+
| API | 용도 |
|
|
111
|
+
| --- | --- |
|
|
112
|
+
| `Server` | WebSocket/TCP 서버 생성 |
|
|
113
|
+
| `IO` | Node.js WebSocket 클라이언트; `iosignal/io`에서는 브라우저 클라이언트 |
|
|
114
|
+
| `IOCongSocket` | Node.js TCP 클라이언트 |
|
|
115
|
+
| `server.attach(name, service)` | RPC 서비스 등록 |
|
|
116
|
+
| `io.call(service, command, ...args)` | RPC 요청 |
|
|
117
|
+
| `io.subscribe(tag)` / `io.unsubscribe(tag)` | 태그 구독 / 해제 |
|
|
118
|
+
| `io.signal(tag, ...args)` | 메시지 발행 |
|
|
119
|
+
| `io.stop()` | 자동 재연결 중단 및 연결 정리 |
|
|
120
|
+
| `server.close(callback)` | 서버 종료 |
|
|
121
|
+
| `BohoAuth` | 서버 인증 관리자 |
|
|
122
|
+
| `StringKeyProvider`, `FileKeyProvider`, `RedisKeyProvider` | 인증 키 공급자 |
|
|
123
|
+
|
|
124
|
+
## 소스 빌드 및 검증
|
|
125
|
+
|
|
126
|
+
이 저장소의 개발·검증 환경은 Node.js 22와 npm 10을 사용합니다.
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
npm ci
|
|
130
|
+
npm run verify
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
`verify`는 공개 파일 정책을 검사하고, `dist`를 삭제한 뒤 번들과 타입 선언을
|
|
134
|
+
재생성합니다. 이어서 자동 테스트와 npm 패키지 포함 파일 검사를 수행합니다.
|
|
135
|
+
|
|
136
|
+
빌드만 실행하려면 `npm run build`, 이미 빌드된 결과의 자동 테스트만 실행하려면
|
|
137
|
+
`npm test`를 사용합니다.
|
|
138
|
+
|
|
139
|
+
### 통신 자동 테스트
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
npm run build
|
|
143
|
+
npm run test:integration
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
`test/integration/`은 공개 ESM·CommonJS 빌드 각각에 대해 실제 WebSocket 통신을 검사합니다.
|
|
147
|
+
로컬 루프백(`127.0.0.1`)의 임시 포트를 사용하므로 외부 서버, Redis, 실제 인증키가 필요하지 않습니다.
|
|
148
|
+
|
|
149
|
+
- 연결과 RPC 응답, 없는 명령 및 권한 거부
|
|
150
|
+
- 두 클라이언트 간 문자열·객체·바이너리 발행/구독과 구독 해제
|
|
151
|
+
- 인증 성공 및 암호화된 RPC 응답, 잘못된 인증 거부
|
|
152
|
+
- 연결 종료 후 클라이언트 재사용과 서버 자원 정리
|
|
153
|
+
|
|
154
|
+
`npm test`와 `npm run verify`에도 통신 검사가 포함됩니다. 테스트별 시간 제한과
|
|
155
|
+
전체 테스트 파일 시간 제한을 두며, 종료 시 서버와 클라이언트를 정리합니다.
|
|
156
|
+
실제 브라우저, TLS, TCP 전송 및 Redis 연동 검증은 이 통신 테스트 범위에 포함되지 않습니다.
|
|
157
|
+
|
|
158
|
+
기존 `test/attach-services/`, `test/auth_server_client/`, `test/pubsub-counter/`,
|
|
159
|
+
`test/subscribe-signal/`은 수동 예제입니다. 자동 실행하지 않으며, 일부는 별도 서버나 Redis가 필요합니다.
|
|
160
|
+
|
|
161
|
+
## 라이선스
|
|
162
|
+
|
|
163
|
+
패키지 라이선스: MIT.
|
package/dist/browser/esm/io.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import * as meta_buffer_pack from 'meta-buffer-pack';
|
|
2
1
|
import * as boho from 'boho';
|
|
2
|
+
import boho__default from 'boho';
|
|
3
|
+
import * as buffer from 'buffer';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Core class for handling WebSocket communication.
|
|
@@ -79,8 +80,8 @@ declare class IOCore {
|
|
|
79
80
|
* Boho instance for encryption/decryption.
|
|
80
81
|
* @type {Boho}
|
|
81
82
|
*/
|
|
82
|
-
boho:
|
|
83
|
-
serverTimeNonce:
|
|
83
|
+
boho: boho__default;
|
|
84
|
+
serverTimeNonce: buffer.Buffer;
|
|
84
85
|
/**
|
|
85
86
|
* Indicates if the connection is TLS (wss).
|
|
86
87
|
* @type {boolean}
|
|
@@ -322,8 +323,8 @@ declare class IOCore {
|
|
|
322
323
|
*/
|
|
323
324
|
subscribe(tag: string): void;
|
|
324
325
|
/**
|
|
325
|
-
*
|
|
326
|
-
*
|
|
326
|
+
* Sends subscriptions stored by listen()/link() on each CID-ready transition,
|
|
327
|
+
* including reconnection. This automates subscription setup for simple clients.
|
|
327
328
|
*/
|
|
328
329
|
subscribe_channels(): void;
|
|
329
330
|
/**
|
|
@@ -333,7 +334,13 @@ declare class IOCore {
|
|
|
333
334
|
*/
|
|
334
335
|
unsubscribe(tag?: string): void;
|
|
335
336
|
/**
|
|
336
|
-
*
|
|
337
|
+
* Convenience API for simple clients (for example, CLI tools): register a
|
|
338
|
+
* tag handler once and remember its subscription in channels. Register before
|
|
339
|
+
* connection readiness; the CID-ready flow subscribes on initial connection
|
|
340
|
+
* and again after reconnect, without application-level ready/subscribe code.
|
|
341
|
+
* This does not send a subscription immediately, even if already ready.
|
|
342
|
+
* For precise subscription/send ordering or dynamic subscriptions, use
|
|
343
|
+
* on() with subscribe() in a ready handler instead. Direct signals use on('@').
|
|
337
344
|
* @param {string} tag - The tag to listen on.
|
|
338
345
|
* @param {Function} handler - The callback function to handle the signal.
|
|
339
346
|
* @throws {TypeError} If tag is not a string, handler is not a function, or tag length is invalid.
|
|
@@ -404,7 +411,6 @@ declare class IOCore {
|
|
|
404
411
|
*/
|
|
405
412
|
stateChange(state: string, emitEventAndMessage?: string): void;
|
|
406
413
|
}
|
|
407
|
-
type Boho$1 = boho.Boho;
|
|
408
414
|
type Buffer$1 = boho.Buffer;
|
|
409
415
|
|
|
410
416
|
/**
|
|
@@ -424,9 +430,9 @@ declare class IO extends IOCore {
|
|
|
424
430
|
static binaryType: string;
|
|
425
431
|
/**
|
|
426
432
|
* The Boho library instance.
|
|
427
|
-
* @type {Boho}
|
|
433
|
+
* @type {typeof Boho}
|
|
428
434
|
*/
|
|
429
|
-
static Boho:
|
|
435
|
+
static Boho: typeof boho__default;
|
|
430
436
|
/**
|
|
431
437
|
* The MBP (MessagePack-Boho) instance.
|
|
432
438
|
* @type {MBP}
|
|
@@ -482,9 +488,8 @@ declare class IO extends IOCore {
|
|
|
482
488
|
*/
|
|
483
489
|
socket_send(data: BufferSource): void;
|
|
484
490
|
}
|
|
485
|
-
type
|
|
486
|
-
type MBP = typeof meta_buffer_pack;
|
|
491
|
+
type MBP = boho.MBP;
|
|
487
492
|
type Buffer = boho.Buffer;
|
|
488
493
|
|
|
489
494
|
export { IO as default };
|
|
490
|
-
export type {
|
|
495
|
+
export type { Buffer, MBP };
|