iosignal 5.0.1 → 5.1.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 +3 -3
- package/dist/io.js +3 -3
- package/dist/io.js.map +1 -1
- package/dist/io.min.js +4 -4
- package/dist/io.min.js.map +1 -1
- package/dist/iosignal.js +5 -4
- package/dist/types/common/payload.d.ts +1 -1
- package/index.js +1 -1
- package/package.json +6 -6
- package/rollup.config.js +1 -1
- package/test/attach-services/RedisService.js +46 -0
- package/test/attach-services/replyService.js +46 -0
- package/test/auth_server_client/auth_server_client.js +45 -0
- package/test/pubsub-counter/pubsub-counter.js +61 -0
- package/test/subscribe-signal/cid-a-b.js +94 -0
- package/test/subscribe-signal/cs-signal-test.js +47 -0
- package/test/subscribe-signal/meta.js +61 -0
- package/test/subscribe-signal/self-listen.js +40 -0
- package/test/subscribe-signal/self-subscribe.js +35 -0
- package/test/subscribe-signal/signal-MBA.js +15 -0
- package/test/subscribe-signal/signalPack.js +34 -0
- package/test/subscribe-signal/signaling.js +61 -0
- package/.vscode/settings.json +0 -3
- package/src/server/Metric.js +0 -154
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "iosignal",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.1.1",
|
|
4
4
|
"description": "iosignal",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -37,9 +37,9 @@
|
|
|
37
37
|
"typescript": "^5.8.3"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"boho": "^2.
|
|
40
|
+
"boho": "^2.1.1",
|
|
41
41
|
"eventemitter3": "^5.0.1",
|
|
42
|
-
"meta-buffer-pack": "^2.1.
|
|
42
|
+
"meta-buffer-pack": "^2.1.1",
|
|
43
43
|
"ws": "^8.18.3"
|
|
44
44
|
},
|
|
45
45
|
"optionalDependencies": {
|
|
@@ -48,9 +48,9 @@
|
|
|
48
48
|
},
|
|
49
49
|
"repository": {
|
|
50
50
|
"type": "git",
|
|
51
|
-
"url": "
|
|
51
|
+
"url": "https://github.com/remocons/iosignal.git",
|
|
52
|
+
"directory": "packages/iosignal"
|
|
52
53
|
},
|
|
53
|
-
"homepage": "https://iosignal.net",
|
|
54
54
|
"keywords": [
|
|
55
55
|
"websocket",
|
|
56
56
|
"pubsub",
|
|
@@ -65,4 +65,4 @@
|
|
|
65
65
|
"arduino",
|
|
66
66
|
"auth"
|
|
67
67
|
]
|
|
68
|
-
}
|
|
68
|
+
}
|
package/rollup.config.js
CHANGED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* api/RediService.js 테스트
|
|
3
|
+
*
|
|
4
|
+
* 사전준비.
|
|
5
|
+
* localhost 에 redis-server 운영
|
|
6
|
+
* some sample data 저장.
|
|
7
|
+
*/
|
|
8
|
+
import { RedisService, Server , IO } from 'iosignal'
|
|
9
|
+
import { createClient } from 'redis'
|
|
10
|
+
|
|
11
|
+
const redisClient = createClient() // default redis. localhost:6379
|
|
12
|
+
redisClient.connect();
|
|
13
|
+
|
|
14
|
+
redisClient.on('error', (err)=>{
|
|
15
|
+
console.log('redisCleint err: ', err)
|
|
16
|
+
})
|
|
17
|
+
redisClient.on('ready', ()=>{
|
|
18
|
+
console.log('redisClient is ready.')
|
|
19
|
+
})
|
|
20
|
+
redisClient.on('end', ()=>{
|
|
21
|
+
console.log('redisClient is end.')
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
const server = new Server({port:0, showMessage: 'message'})
|
|
25
|
+
.attach('redis', new RedisService( redisClient , -1))
|
|
26
|
+
|
|
27
|
+
server.on('ready',()=>{
|
|
28
|
+
let io = new IO('ws://localhost:'+server.port)
|
|
29
|
+
io.on('ready', async ()=>{
|
|
30
|
+
console.log('io ready. cid: ', io.cid )
|
|
31
|
+
let apiResult;
|
|
32
|
+
try {
|
|
33
|
+
apiResult = await io.call('redis','hGetAll','device:one')
|
|
34
|
+
console.log(apiResult)
|
|
35
|
+
apiResult = await io.call('redis','HGETALL','device:one')
|
|
36
|
+
console.log(apiResult)
|
|
37
|
+
apiResult = await io.call('redis','save')
|
|
38
|
+
console.log(apiResult)
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.log('io api req err', error)
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
io.on('error',(err)=>{
|
|
44
|
+
console.log('io client error: ', err)
|
|
45
|
+
})
|
|
46
|
+
})
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
|
|
2
|
+
import { IO, Server, replyService } from "iosignal"
|
|
3
|
+
|
|
4
|
+
const server = new Server({
|
|
5
|
+
port: 0,
|
|
6
|
+
// showMessage: 'message'
|
|
7
|
+
})
|
|
8
|
+
server.attach('reply', replyService)
|
|
9
|
+
|
|
10
|
+
server.on('ready', () => {
|
|
11
|
+
console.log('server is ready', server.port)
|
|
12
|
+
|
|
13
|
+
const io = new IO('ws://localhost:' + server.port)
|
|
14
|
+
io.on('ready', async () => {
|
|
15
|
+
console.log('ready cid', io.cid)
|
|
16
|
+
|
|
17
|
+
let result;
|
|
18
|
+
try {
|
|
19
|
+
result = await io.call('reply', 'echo', 'hello')
|
|
20
|
+
if (result.ok) console.log('[echo respose] ', result.body)
|
|
21
|
+
|
|
22
|
+
result = await io.call('reply', 'date')
|
|
23
|
+
if (result.ok) console.log('[date respose] ', result.body)
|
|
24
|
+
|
|
25
|
+
result = await io.call('reply', 'unixtime')
|
|
26
|
+
if (result.ok) console.log('[unixtime respose] ', result.body)
|
|
27
|
+
} catch (error) {
|
|
28
|
+
console.log('error:', error)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// UNKNOWN_COMMAND ERROR
|
|
32
|
+
try {
|
|
33
|
+
result = await io.call('reply', 'Unknown_command')
|
|
34
|
+
if (result.ok) console.log(result.body)
|
|
35
|
+
} catch (error) {
|
|
36
|
+
console.log('error:', error)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
server.close()
|
|
40
|
+
setTimeout(() => {
|
|
41
|
+
process.exit();
|
|
42
|
+
}, 1000)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
})
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Server , IO, BohoAuth, StringKeyProvider} from 'iosignal'
|
|
2
|
+
|
|
3
|
+
// serverOption.showMetric = 2;
|
|
4
|
+
|
|
5
|
+
const authManager = new BohoAuth( new StringKeyProvider('io.key.io.3,io2.password.io2.3'))
|
|
6
|
+
const s = new Server({
|
|
7
|
+
port: 0,
|
|
8
|
+
// showMetric: 2,
|
|
9
|
+
showMessage: 'message'
|
|
10
|
+
}, authManager);
|
|
11
|
+
// s.attach('sudo', sudoService );
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
|
|
15
|
+
|
|
16
|
+
s.on('ready',async ()=>{
|
|
17
|
+
// 서버 listen 포트가 0으로 설정된경우, 자동설정된 값이 s.port 속성으로 확정됨.
|
|
18
|
+
console.log('listening port: ', s.port )
|
|
19
|
+
|
|
20
|
+
let io = new IO('ws://localhost:'+ s.port)
|
|
21
|
+
.on('error',(err)=>{
|
|
22
|
+
console.log(err)
|
|
23
|
+
}).on('change',(name)=>{
|
|
24
|
+
console.log(`<io(${name}:${io.state})`)
|
|
25
|
+
}).on('ready',()=>{
|
|
26
|
+
console.log('#ready cid:', io.cid )
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
let io2 = new IO('ws://localhost:'+ s.port)
|
|
30
|
+
.on('error',(err)=>{
|
|
31
|
+
console.log(err)
|
|
32
|
+
}).on('change',(name)=>{
|
|
33
|
+
console.log(`<io2(${name}:${io2.state})`)
|
|
34
|
+
}).on('ready',()=>{
|
|
35
|
+
console.log('#ready cid:', io2.cid )
|
|
36
|
+
}).on('auth_fail',()=>{
|
|
37
|
+
console.log('#auth_fail: io2')
|
|
38
|
+
}).auth('io2.password')
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
// await delay(2000)
|
|
44
|
+
// process.exit()
|
|
45
|
+
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
|
|
2
|
+
import { IO } from 'iosignal'
|
|
3
|
+
const ch_base = 'ch_'
|
|
4
|
+
const url = 'wss://io.remocon.kr/ws'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
시그널 서버 연결된 노드들의 pub/sub 전달 상태 테스트
|
|
9
|
+
|
|
10
|
+
2025. Aug 16.
|
|
11
|
+
여러개의 장치가 하나의 채널을 공유한다.
|
|
12
|
+
하나의 채널당 연결된 node 개수는 nodePerChannel
|
|
13
|
+
총 채널의 개수가 channels
|
|
14
|
+
총 노드수는 channels * nodePerChannel
|
|
15
|
+
|
|
16
|
+
모든 노드가 수신하는 메시지 수를 rCounter 에 누적하고, 1초마다 출력.
|
|
17
|
+
*/
|
|
18
|
+
const channels = 20;
|
|
19
|
+
const nodePerChannel = 5;
|
|
20
|
+
|
|
21
|
+
let remotes = [];
|
|
22
|
+
let rCounter = 0;
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
for( let j= 0; j < channels ; j++){
|
|
26
|
+
let ch = ch_base + j;
|
|
27
|
+
|
|
28
|
+
console.log( j, ch)
|
|
29
|
+
for(let i = 0; i < nodePerChannel ; i++){
|
|
30
|
+
|
|
31
|
+
let io = new IO(url);
|
|
32
|
+
|
|
33
|
+
let range = 10000; // msec
|
|
34
|
+
let minPeriod = 500; //msec
|
|
35
|
+
let randRange = Math.ceil( Math.random() * range );
|
|
36
|
+
if( i == 0){
|
|
37
|
+
setInterval( ()=>{
|
|
38
|
+
io.signal(ch, 'hello')
|
|
39
|
+
}, minPeriod + randRange)
|
|
40
|
+
}
|
|
41
|
+
io.on('ready',()=>{
|
|
42
|
+
io.subscribe(ch)
|
|
43
|
+
})
|
|
44
|
+
io.on( 'message', (tag, msg )=>{
|
|
45
|
+
rCounter++;
|
|
46
|
+
})
|
|
47
|
+
remotes.push(io)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
console.log('total remotes: ', remotes.length )
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
setInterval( ()=>{
|
|
57
|
+
console.log('rcounter/sec', rCounter )
|
|
58
|
+
rCounter = 0;
|
|
59
|
+
}, 1000)
|
|
60
|
+
|
|
61
|
+
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/*
|
|
2
|
+
unicast using cid
|
|
3
|
+
A,B ready 되면 cidA, cidB에 저장
|
|
4
|
+
A는 B에게, B는 A에게 unicast 1:1 시그널 전송
|
|
5
|
+
|
|
6
|
+
A -> B
|
|
7
|
+
B -> A
|
|
8
|
+
|
|
9
|
+
2. cid 구독, cid 발행
|
|
10
|
+
C는 A의 cid를 구독, C가 cid 발행하면 수신.
|
|
11
|
+
|
|
12
|
+
A cid publish -> C
|
|
13
|
+
|
|
14
|
+
채널 시그널
|
|
15
|
+
유니캐스트 시그널
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
*/
|
|
19
|
+
import { Server , IO, MBP , StringKeyProvider, BohoAuth} from 'iosignal'
|
|
20
|
+
const stringKey = 'A.akey.A.3,B.bkey.B.3,C.ckey.C.3'
|
|
21
|
+
const authManager = new BohoAuth(new StringKeyProvider(stringKey) )
|
|
22
|
+
const tag = 'channel'
|
|
23
|
+
const s = new Server({
|
|
24
|
+
port: 0,
|
|
25
|
+
// congPort: 55488,
|
|
26
|
+
// showMessage: 'message'
|
|
27
|
+
}, authManager);
|
|
28
|
+
|
|
29
|
+
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
s.on('ready',async ()=>{
|
|
33
|
+
// 서버 listen 포트가 0으로 설정된경우, 자동설정된 값이 s.port 속성으로 확정됨.
|
|
34
|
+
console.log('listening port: ', s.port )
|
|
35
|
+
|
|
36
|
+
const A = new IO('ws://localhost:'+ s.port)
|
|
37
|
+
A.on('ready', async ()=>{
|
|
38
|
+
console.log('ready A:', A.cid)
|
|
39
|
+
})
|
|
40
|
+
A.on('message',( tag, ...args )=>{
|
|
41
|
+
console.log('[Am]', tag, ...args)
|
|
42
|
+
})
|
|
43
|
+
A.on('@',( tag, ...args )=>{
|
|
44
|
+
console.log('[A@]',tag, ...args)
|
|
45
|
+
}).auth('A.akey')
|
|
46
|
+
|
|
47
|
+
const B = new IO('ws://localhost:'+ s.port)
|
|
48
|
+
.on('ready', async ()=>{
|
|
49
|
+
console.log('ready B:', B.cid)
|
|
50
|
+
B.subscribe('A@news')
|
|
51
|
+
})
|
|
52
|
+
.on('message',( tag, ...args )=>{
|
|
53
|
+
console.log('[Bm]', tag, ...args)
|
|
54
|
+
})
|
|
55
|
+
.on( 'A@news',( tag, ...args )=>{
|
|
56
|
+
console.log('[Bs]', tag, ...args)
|
|
57
|
+
})
|
|
58
|
+
.on('@',( tag, ...args )=>{
|
|
59
|
+
console.log('[B@]', tag, ...args)
|
|
60
|
+
}).auth('B.bkey')
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
const C = new IO('ws://localhost:'+ s.port)
|
|
64
|
+
C.on('ready', async ()=>{
|
|
65
|
+
console.log('ready C:', C.cid)
|
|
66
|
+
C.subscribe('A@news')
|
|
67
|
+
})
|
|
68
|
+
C.on( 'A@news',( tag, ...args )=>{
|
|
69
|
+
console.log('[Cs]', tag, ...args)
|
|
70
|
+
})
|
|
71
|
+
C.on('message',( tag, ...args )=>{
|
|
72
|
+
console.log('[Cm]', tag, ...args)
|
|
73
|
+
})
|
|
74
|
+
C.on('@',( tag, ...args )=>{
|
|
75
|
+
console.log('[C@]', tag, ...args)
|
|
76
|
+
}).auth('C.ckey')
|
|
77
|
+
|
|
78
|
+
await delay(200)
|
|
79
|
+
// unicast A -> B@
|
|
80
|
+
A.signal( 'B@', 'A -> B@')
|
|
81
|
+
|
|
82
|
+
// cid_subscribe A -> A@ subscirbers
|
|
83
|
+
A.signal( '@news', 'A -> A@news -> B,C')
|
|
84
|
+
|
|
85
|
+
// unicast B -> A@
|
|
86
|
+
B.signal( 'A@', 'B -> A@')
|
|
87
|
+
|
|
88
|
+
// unicast B -> A@topic
|
|
89
|
+
B.signal( 'A@topic', 'B -> A@topic')
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
await delay(3000)
|
|
93
|
+
process.exit()
|
|
94
|
+
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Server , IO, MBP ,delay } from 'iosignal'
|
|
2
|
+
|
|
3
|
+
const tag = 'ch1'
|
|
4
|
+
const tag2 = 'ch2'
|
|
5
|
+
|
|
6
|
+
const s = new Server({port:0, showMessage: 'message'});
|
|
7
|
+
|
|
8
|
+
s.on('ready',async ()=>{
|
|
9
|
+
// 서버 listen 포트가 0으로 설정된경우, 자동설정된 값이 s.port 속성으로 확정됨.
|
|
10
|
+
console.log('listening port: ', s.port )
|
|
11
|
+
|
|
12
|
+
const io = new IO('ws://localhost:'+ s.port)
|
|
13
|
+
|
|
14
|
+
io.on('message',( tag, ...args )=>{
|
|
15
|
+
console.log('io message: ', tag, ...args)
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
io.on('ready',()=>{
|
|
19
|
+
io.subscribe(tag + ',' + tag2 )
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
await delay(1000)
|
|
23
|
+
io.signal(tag, 'text', 'hello')
|
|
24
|
+
io.signal(tag) //empty
|
|
25
|
+
io.signal(tag, 'number', 123)
|
|
26
|
+
io.signal(tag, 'object', {key:'str value', key2: 123 })
|
|
27
|
+
io.signal(tag, 'buffer', Buffer.from('aaaaa'))
|
|
28
|
+
io.signal(tag, 'buffer,str,number', Buffer.from('aaaaa'),'hello', 123)
|
|
29
|
+
let u8 = new Uint8Array(4)
|
|
30
|
+
u8[0] = 1;
|
|
31
|
+
let u32 = new Uint32Array(4)
|
|
32
|
+
u32[0] = 1;
|
|
33
|
+
u32[1] = 2;
|
|
34
|
+
io.signal(tag, 'uit8,uint32', u8, u32 )
|
|
35
|
+
|
|
36
|
+
let mbp = MBP.pack(
|
|
37
|
+
MBP.MB('name8','8', 200),
|
|
38
|
+
MBP.MB('name32', '32', 256 + 200)
|
|
39
|
+
)
|
|
40
|
+
io.signal(tag2 , mbp )
|
|
41
|
+
|
|
42
|
+
io.signal(tag , '1k',Buffer.alloc(1000))
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
await delay(3000)
|
|
47
|
+
process.exit()
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {MBP} from 'iosignal'
|
|
2
|
+
|
|
3
|
+
export const Meta = {
|
|
4
|
+
|
|
5
|
+
SERVER_TIME_NONCE: MBP.meta( // 13
|
|
6
|
+
MBP.MB('header','8', 0),
|
|
7
|
+
MBP.MB('unixTime','32L', 0),
|
|
8
|
+
MBP.MB('milTime','32L', 0 ),
|
|
9
|
+
MBP.MB('nonce', Buffer.alloc(4))
|
|
10
|
+
),
|
|
11
|
+
|
|
12
|
+
AUTH_REQ: MBP.meta( // 45
|
|
13
|
+
MBP.MB('header','8', 0),
|
|
14
|
+
MBP.MB('id8',Buffer.alloc(8)),
|
|
15
|
+
MBP.MB('nonce', Buffer.alloc(4)),
|
|
16
|
+
MBP.MB('hmac32', Buffer.alloc(32))
|
|
17
|
+
),
|
|
18
|
+
|
|
19
|
+
AUTH_RES: MBP.meta( // 33
|
|
20
|
+
MBP.MB('header','8', 0),
|
|
21
|
+
MBP.MB('hmac32', Buffer.alloc(32))
|
|
22
|
+
),
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
ENC_PACK: MBP.meta( //25 + payload
|
|
26
|
+
MBP.MB('type','8',0),
|
|
27
|
+
MBP.MB('len','32L',0), // pure xdata size.
|
|
28
|
+
MBP.MB('salt12', Buffer.alloc(12)), // sec,mil,rand
|
|
29
|
+
MBP.MB('hmac',8,0)
|
|
30
|
+
// MBP.MB( 'xdata', encData )
|
|
31
|
+
),
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
ENC_488: MBP.meta( // 21 + payload
|
|
35
|
+
MBP.MB('type','8', 0 ),
|
|
36
|
+
MBP.MB('len','32L', 0 ),
|
|
37
|
+
MBP.MB('otpSrc8', Buffer.alloc(8) ),
|
|
38
|
+
MBP.MB('hmac8', Buffer.alloc(8) )
|
|
39
|
+
// MBP.MB('xdata', encData )
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
console.log( Meta.ENC_488 )
|
|
45
|
+
|
|
46
|
+
const MB = MBP.MB;
|
|
47
|
+
|
|
48
|
+
let mbPack = MBP.pack(
|
|
49
|
+
MB('a','8',120),
|
|
50
|
+
MB('b','16',64000),
|
|
51
|
+
MB('c', Buffer.alloc(1000) ),
|
|
52
|
+
MB('c2', 1000, 0) //c와 동일한 역활.
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
let mbObj = MBP.unpack( mbPack)
|
|
56
|
+
let a = mbObj.a
|
|
57
|
+
console.log('a', a)
|
|
58
|
+
|
|
59
|
+
let metaDetail = MBP.getMeta(mbPack ,true)
|
|
60
|
+
|
|
61
|
+
console.log(metaDetail)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Server , IO, MBP ,delay } from 'iosignal'
|
|
2
|
+
|
|
3
|
+
const tag = 'channel1'
|
|
4
|
+
const s = new Server({
|
|
5
|
+
port:0,
|
|
6
|
+
showMessage: 'message'
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
s.on('ready',async ()=>{
|
|
10
|
+
// 서버 listen 포트가 0으로 설정된경우, 자동설정된 값이 s.port 속성으로 확정됨.
|
|
11
|
+
console.log('listening port: ', s.port )
|
|
12
|
+
|
|
13
|
+
const io = new IO('ws://localhost:'+ s.port)
|
|
14
|
+
io.on('change',(name)=>{
|
|
15
|
+
console.log(`(${name}:${io.state})`)
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
io.on('ready',()=>{
|
|
19
|
+
console.log('io is ready. cid:', io.cid )
|
|
20
|
+
io.subscribe(tag)
|
|
21
|
+
io.signal(tag, 'hi')
|
|
22
|
+
})
|
|
23
|
+
io.on('message',( tag, ...args )=>{
|
|
24
|
+
console.log('io message: ', tag, ...args)
|
|
25
|
+
})
|
|
26
|
+
io.listen(tag,( tag, ...args )=>{
|
|
27
|
+
console.log('io listen tag h1: ', tag, ...args)
|
|
28
|
+
})
|
|
29
|
+
io.listen(tag,( tag, ...args )=>{
|
|
30
|
+
console.log('io listen tag h2: ', tag, ...args)
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
console.log('listeners', io.listeners( tag ) )
|
|
34
|
+
await delay(200)
|
|
35
|
+
io.signal(tag, 'hello')
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
await delay(1000)
|
|
39
|
+
process.exit()
|
|
40
|
+
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Server , IO, MBP } from 'iosignal'
|
|
2
|
+
|
|
3
|
+
const tag = 'aaaaaaaa'
|
|
4
|
+
const s = new Server({
|
|
5
|
+
port:0,
|
|
6
|
+
showMessage: 'message'
|
|
7
|
+
});
|
|
8
|
+
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
|
|
9
|
+
|
|
10
|
+
s.on('ready',async ()=>{
|
|
11
|
+
// 서버 listen 포트가 0으로 설정된경우, 자동설정된 값이 s.port 속성으로 확정됨.
|
|
12
|
+
console.log('listening port: ', s.port )
|
|
13
|
+
|
|
14
|
+
const io = new IO('ws://localhost:'+ s.port)
|
|
15
|
+
io.on('change',(name)=>{
|
|
16
|
+
console.log(`(${name}:${io.state})`)
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
io.on('ready',()=>{
|
|
20
|
+
console.log('ready cid:', io.cid )
|
|
21
|
+
io.subscribe(tag)
|
|
22
|
+
io.signal(tag, io.cid + ' is ready.')
|
|
23
|
+
})
|
|
24
|
+
io.on('message',( tag, msg )=>{
|
|
25
|
+
console.log('rx tag, message', tag, msg)
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
await delay(200)
|
|
30
|
+
io.signal(tag, 'hello')
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
await delay(1000)
|
|
34
|
+
process.exit()
|
|
35
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Server , IO, MBP } from 'iosignal'
|
|
2
|
+
|
|
3
|
+
let mbaPack = MBP.pack(
|
|
4
|
+
MBP.MBA(
|
|
5
|
+
'name', 'hong',
|
|
6
|
+
'age', 33,
|
|
7
|
+
Buffer.alloc(10000),
|
|
8
|
+
Buffer.alloc(10000),
|
|
9
|
+
)
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
let mbaMeta = MBP.getMetaDetail( mbaPack)
|
|
13
|
+
console.log('mbaMeta', mbaMeta )
|
|
14
|
+
// console.log('unpackMba', MBP.unpack( mbaPack ))
|
|
15
|
+
console.log('size', mbaPack.byteLength)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { parsePayload, getSignalPack, getPayloadFromSignalPack, PAYLOAD_TYPE, MBP } from 'iosignal'
|
|
2
|
+
|
|
3
|
+
const type0 = []
|
|
4
|
+
const type1t = ['a1']
|
|
5
|
+
const type1n = [11]
|
|
6
|
+
const type2 = [new Uint8Array(5)]
|
|
7
|
+
const type3 = [{ name: 'type3' }]
|
|
8
|
+
const type4a = ['a2', 222]
|
|
9
|
+
const type4b = [{ name: 'a3' }, 333]
|
|
10
|
+
const type5 = [{ a: 1 }, Buffer.from('BBBBBB')]
|
|
11
|
+
|
|
12
|
+
// zero or one argument support: 0:EMPTY, 1:TEXT , 2:BINARY signal payload type
|
|
13
|
+
console.log(PAYLOAD_TYPE[parsePayload(type0).type], type0) // empty
|
|
14
|
+
console.log(PAYLOAD_TYPE[parsePayload(type1t).type], type1t) // text
|
|
15
|
+
console.log(PAYLOAD_TYPE[parsePayload(type1n).type], type1n) // number text. there is no Number type of signalPaylod.
|
|
16
|
+
console.log(PAYLOAD_TYPE[parsePayload(type2).type], type2) // binary.
|
|
17
|
+
|
|
18
|
+
// over two arguments support: 3:Object, 4:MJSON and 5:MBA can hold Number item.
|
|
19
|
+
console.log(PAYLOAD_TYPE[parsePayload(type3).type], type3) // Object
|
|
20
|
+
console.log(PAYLOAD_TYPE[parsePayload(type4a).type], type4a) // MJSON
|
|
21
|
+
console.log(PAYLOAD_TYPE[parsePayload(type4b).type], type4b) // MJSON
|
|
22
|
+
console.log(PAYLOAD_TYPE[parsePayload(type5).type], type5) // MBA
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
let signalTag = 'channel'
|
|
26
|
+
let signalPack = getSignalPack(signalTag, ...type5)
|
|
27
|
+
console.log('signalPack', signalPack)
|
|
28
|
+
|
|
29
|
+
let payloadBuffer = getPayloadFromSignalPack(signalPack)
|
|
30
|
+
let unpack = MBP.unpack(payloadBuffer)
|
|
31
|
+
console.log(unpack)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { IO, Server } from 'iosignal'
|
|
2
|
+
|
|
3
|
+
let url = 'ws://localhost:5555'
|
|
4
|
+
let server = new Server({
|
|
5
|
+
port: 5555
|
|
6
|
+
// ,showMessage: 'message'
|
|
7
|
+
})
|
|
8
|
+
let done = false;
|
|
9
|
+
|
|
10
|
+
let tx = new IO(url)
|
|
11
|
+
tx.on('ready', () => {
|
|
12
|
+
console.log('tx ready', tx.cid)
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
let rx = new IO(url)
|
|
17
|
+
rx.on('ready', () => {
|
|
18
|
+
console.log('rx ready', rx.cid)
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
rx.listen('@', (tag, ...args) => {
|
|
22
|
+
console.log('uni-cast rxi', args)
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
rx.listen('channel', (tag, ...args) => {
|
|
26
|
+
console.log('multi-cast rxi', args)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
function sendSignals() {
|
|
30
|
+
// uni-casting: tag is receiver CID@.
|
|
31
|
+
let tag = rx.cid + '@topic'
|
|
32
|
+
tx.signal(tag, ...arg1)
|
|
33
|
+
tx.signal(tag, ...arg2)
|
|
34
|
+
tx.signal(tag, ...arg3)
|
|
35
|
+
tx.signal(tag, ...arg4)
|
|
36
|
+
tx.signal(tag, ...arg5)
|
|
37
|
+
|
|
38
|
+
// multi-casting: tag is channel name.
|
|
39
|
+
tag = 'channel'
|
|
40
|
+
tx.signal(tag, ...arg1)
|
|
41
|
+
tx.signal(tag, ...arg2)
|
|
42
|
+
tx.signal(tag, ...arg3)
|
|
43
|
+
tx.signal(tag, ...arg4)
|
|
44
|
+
tx.signal(tag, ...arg5)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
const arg1 = ['a1']
|
|
49
|
+
const arg2 = ['a2', 222]
|
|
50
|
+
const arg3 = [{ name: 'a3' }, 333]
|
|
51
|
+
const arg4 = [{ a: 1 }, Buffer.from('KKKKK')]
|
|
52
|
+
const arg5 = [new Uint8Array(20)]
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
setTimeout(() => {
|
|
56
|
+
sendSignals();
|
|
57
|
+
}, 1000)
|
|
58
|
+
|
|
59
|
+
setTimeout(() => {
|
|
60
|
+
process.exit()
|
|
61
|
+
}, 2000)
|
package/.vscode/settings.json
DELETED