iosignal 1.4.2 → 1.5.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.
Files changed (50) hide show
  1. package/README.md +247 -240
  2. package/auth_file.json +13 -13
  3. package/auth_file.mjs +23 -23
  4. package/dist/iosignal.cjs +1 -1
  5. package/dist/iosignal.esm.js.map +1 -1
  6. package/dist/iosignal.min.js.map +1 -1
  7. package/index.js +19 -19
  8. package/indexWebBrowser.js +13 -13
  9. package/package.json +59 -60
  10. package/rollup.config.js +69 -69
  11. package/src/api/RedisAPI.js +68 -68
  12. package/src/api/api_constant.js +7 -7
  13. package/src/api/api_reply.js +34 -34
  14. package/src/api/api_sudo.js +96 -96
  15. package/src/auth/Auth_Env.js +78 -78
  16. package/src/auth/Auth_File.js +75 -75
  17. package/src/auth/Auth_Redis.js +50 -50
  18. package/src/auth/BohoAuth.js +168 -168
  19. package/src/client/CongPacket.js +150 -150
  20. package/src/client/IOCongSocket.js +88 -88
  21. package/src/client/IOCore.js +851 -851
  22. package/src/client/IOWS.js +81 -81
  23. package/src/client/IOWebSocket.js +95 -95
  24. package/src/common/constants.js +159 -159
  25. package/src/common/payload.js +82 -82
  26. package/src/common/quotaTable.js +68 -68
  27. package/src/common/util.js +61 -61
  28. package/src/server/FileLogger.js +30 -30
  29. package/src/server/Manager.js +449 -449
  30. package/src/server/Metric.js +154 -154
  31. package/src/server/Server.js +166 -148
  32. package/src/server/ServerRemote.js +227 -227
  33. package/src/server/ServerRemoteCore.js +467 -467
  34. package/src/server/serverOption.js +56 -55
  35. package/test-browser/favicon.ico +0 -0
  36. package/test-browser/index.html +92 -92
  37. package/test-browser/server.js +11 -11
  38. package/test-client-nodejs/client.cjs +17 -17
  39. package/test-client-nodejs/client.mjs +17 -17
  40. package/test-client-nodejs/client_api_reply.mjs +15 -15
  41. package/test-client-nodejs/stateChange.mjs +19 -19
  42. package/test-server/server-Auth_Env.js +19 -19
  43. package/test-server/server-Auth_File.js +12 -12
  44. package/test-server/server-api_reply.js +6 -6
  45. package/test-server/server-api_sudo.js +7 -7
  46. package/test-server/server-commonjs.cjs +8 -8
  47. package/test-server/server-esm.mjs +19 -19
  48. package/test-server/simple-server.mjs +11 -11
  49. package/test-signal-payloadType/signalPack.js +34 -34
  50. package/test-signal-payloadType/signaling.js +60 -60
@@ -1,55 +1,56 @@
1
-
2
-
3
- export let serverOption = {
4
- clientTracking: false,
5
- port: 0,
6
- congPort: 0,
7
- timeout: 50000,
8
- showMessage: 'none',
9
- showMetric: 0,
10
- showChannel: 0,
11
- monitorPeriod: 5000,
12
- fileLogger:{
13
- connection: {
14
- use: false,
15
- path: 'connection.log'
16
- },
17
- auth: {
18
- use: false,
19
- path: 'auth.log'
20
- },
21
- attack:{
22
- use: false,
23
- path:'attack.log'
24
- }
25
- },
26
- useQuota:{
27
- signalSize: false,
28
- publishCounter: false,
29
- trafficRate: false,
30
- disconnect: false
31
- },
32
- defaultQuotaIndex: 3,
33
- adminLevel: 255,
34
-
35
- debug:{
36
- slow: false,
37
- delay: 500,
38
- showAuthInfo: false
39
- },
40
-
41
- retain:{
42
- isAvailable: true,
43
- limitSize: 100000,
44
- limitCounter: 1000
45
- },
46
-
47
- auth:{
48
- delay_auth_fail: 1000,
49
- },
50
-
51
- memberOnly: false
52
-
53
- }
54
-
55
-
1
+
2
+
3
+ export let serverOption = {
4
+ clientTracking: false,
5
+ port: 0, //wsPort
6
+ httpServer: null,
7
+ congPort: 0,
8
+ timeout: 50000,
9
+ showMessage: 'none',
10
+ showMetric: 0,
11
+ showChannel: 0,
12
+ monitorPeriod: 5000,
13
+ fileLogger:{
14
+ connection: {
15
+ use: false,
16
+ path: 'connection.log'
17
+ },
18
+ auth: {
19
+ use: false,
20
+ path: 'auth.log'
21
+ },
22
+ attack:{
23
+ use: false,
24
+ path:'attack.log'
25
+ }
26
+ },
27
+ useQuota:{
28
+ signalSize: false,
29
+ publishCounter: false,
30
+ trafficRate: false,
31
+ disconnect: false
32
+ },
33
+ defaultQuotaIndex: 3,
34
+ adminLevel: 255,
35
+
36
+ debug:{
37
+ slow: false,
38
+ delay: 500,
39
+ showAuthInfo: false
40
+ },
41
+
42
+ retain:{
43
+ isAvailable: true,
44
+ limitSize: 100000,
45
+ limitCounter: 1000
46
+ },
47
+
48
+ auth:{
49
+ delay_auth_fail: 1000,
50
+ },
51
+
52
+ memberOnly: false
53
+
54
+ }
55
+
56
+
File without changes
@@ -1,93 +1,93 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
- <title>Document</title>
8
- <style>
9
- #messageView{
10
- border: 1px solid red;
11
- padding: 2em;
12
- }
13
- </style>
14
- </head>
15
- <body>
16
- <h2>Simple pub sub example.</h2>
17
- <p>you should start server first.</p>
18
- <p>this index.html load two types of modules. </p>
19
- <h5>1. IIFE: iosignal.min.js</h5>
20
- <p>use global name: IO </p>
21
- <p>IO has props: Boho, MBP, Buffer,, </p>
22
- <h5>2. ESM: iosignal.esm.js</h5>
23
- <p> check the console.</p>
24
- <h2>message log</h2>
25
- <div id="messageView">...</div>
26
- <script src="../dist/iosignal.min.js"></script>
27
- <script>
28
- console.log('IIFE:')
29
- console.log('IO', IO)
30
- console.log('MBP', IO.MBP )
31
- console.log('Buffer', IO.Buffer)
32
- console.log('Boho', IO.Boho )
33
- console.log('sha256.hash("hi")', IO.Boho.sha256.hash('hi'))
34
-
35
- var ESM_IO ;
36
- var io1 = new IO('ws://localhost:7777')
37
- var io2 = new IO('ws://localhost:7777')
38
- var io3 = new IO('ws://localhost:7777')
39
-
40
- io1.on('error', errorHandler )
41
- io2.on('error', errorHandler )
42
- io3.on('error', errorHandler )
43
-
44
- let channelName = 'io'
45
- // classic style subsribing
46
- io1.on('ready',e=>{
47
- io1.subscribe(channelName)
48
- io1.on(channelName, (...args)=>{
49
- // console.log('io1 received', args )
50
- let msg = '[io1] ' + JSON.stringify( args )
51
- addMessage(msg)
52
- })
53
- })
54
-
55
- // modern style subscribing
56
- io2.listen(channelName, (...args)=>{
57
- // console.log('io2 receive', args )
58
- let msg = '[io2] ' + JSON.stringify( args )
59
- addMessage(msg)
60
- })
61
-
62
- setInterval(e=>{
63
- io3.signal(channelName, 'single string') // single string payload
64
- io3.signal(channelName, Date.now(), 'a', 2 , {key: 3} ) //multiple payload
65
- io3.signal(channelName ) // pure signal without payload.
66
- },3000)
67
-
68
- function addMessage(msg){
69
-
70
- let p = document.createElement('p')
71
- p.textContent = msg
72
- let v = document.querySelector('#messageView')
73
- if(v.childElementCount > 20) v.innerHTML = ""
74
- v.prepend( p )
75
- }
76
-
77
- function errorHandler(e){
78
- console.log(e.target)
79
- addMessage('ws.error')
80
- }
81
- </script>
82
- <script type="module">
83
- import { IO, Boho, MBP, Buffer, sha256 } from "../dist/iosignal.esm.js"
84
- ESM_IO = IO
85
- console.log('ESM:')
86
- console.log('IO', IO)
87
- console.log('Boho', Boho )
88
- console.log('MBP', MBP )
89
- console.log('Buffer', Buffer)
90
- console.log('sha256.hash("hi")', sha256.hash('hi'))
91
- </script>
92
- </body>
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <title>Document</title>
8
+ <style>
9
+ #messageView{
10
+ border: 1px solid red;
11
+ padding: 2em;
12
+ }
13
+ </style>
14
+ </head>
15
+ <body>
16
+ <h2>Simple pub sub example.</h2>
17
+ <p>you should start server first.</p>
18
+ <p>this index.html load two types of modules. </p>
19
+ <h5>1. IIFE: iosignal.min.js</h5>
20
+ <p>use global name: IO </p>
21
+ <p>IO has props: Boho, MBP, Buffer,, </p>
22
+ <h5>2. ESM: iosignal.esm.js</h5>
23
+ <p> check the console.</p>
24
+ <h2>message log</h2>
25
+ <div id="messageView">...</div>
26
+ <script src="../dist/iosignal.min.js"></script>
27
+ <script>
28
+ console.log('IIFE:')
29
+ console.log('IO', IO)
30
+ console.log('MBP', IO.MBP )
31
+ console.log('Buffer', IO.Buffer)
32
+ console.log('Boho', IO.Boho )
33
+ console.log('sha256.hash("hi")', IO.Boho.sha256.hash('hi'))
34
+
35
+ var ESM_IO ;
36
+ var io1 = new IO('ws://localhost:7777')
37
+ var io2 = new IO('ws://localhost:7777')
38
+ var io3 = new IO('ws://localhost:7777')
39
+
40
+ io1.on('error', errorHandler )
41
+ io2.on('error', errorHandler )
42
+ io3.on('error', errorHandler )
43
+
44
+ let channelName = 'io'
45
+ // classic style subsribing
46
+ io1.on('ready',e=>{
47
+ io1.subscribe(channelName)
48
+ io1.on(channelName, (...args)=>{
49
+ // console.log('io1 received', args )
50
+ let msg = '[io1] ' + JSON.stringify( args )
51
+ addMessage(msg)
52
+ })
53
+ })
54
+
55
+ // modern style subscribing
56
+ io2.listen(channelName, (...args)=>{
57
+ // console.log('io2 receive', args )
58
+ let msg = '[io2] ' + JSON.stringify( args )
59
+ addMessage(msg)
60
+ })
61
+
62
+ setInterval(e=>{
63
+ io3.signal(channelName, 'single string') // single string payload
64
+ io3.signal(channelName, Date.now(), 'a', 2 , {key: 3} ) //multiple payload
65
+ io3.signal(channelName ) // pure signal without payload.
66
+ },3000)
67
+
68
+ function addMessage(msg){
69
+
70
+ let p = document.createElement('p')
71
+ p.textContent = msg
72
+ let v = document.querySelector('#messageView')
73
+ if(v.childElementCount > 20) v.innerHTML = ""
74
+ v.prepend( p )
75
+ }
76
+
77
+ function errorHandler(e){
78
+ console.log(e.target)
79
+ addMessage('ws.error')
80
+ }
81
+ </script>
82
+ <script type="module">
83
+ import { IO, Boho, MBP, Buffer, sha256 } from "../dist/iosignal.esm.js"
84
+ ESM_IO = IO
85
+ console.log('ESM:')
86
+ console.log('IO', IO)
87
+ console.log('Boho', Boho )
88
+ console.log('MBP', MBP )
89
+ console.log('Buffer', Buffer)
90
+ console.log('sha256.hash("hi")', sha256.hash('hi'))
91
+ </script>
92
+ </body>
93
93
  </html>
@@ -1,11 +1,11 @@
1
- import { Server } from 'iosignal'
2
-
3
- const options = {
4
- port: 7777,
5
- showMetric: 2,
6
- showMessage: 'message'
7
- }
8
-
9
- const server = new Server( options )
10
-
11
-
1
+ import { Server } from 'iosignal'
2
+
3
+ const options = {
4
+ port: 7777,
5
+ showMetric: 2,
6
+ showMessage: 'message'
7
+ }
8
+
9
+ const server = new Server( options )
10
+
11
+
@@ -1,17 +1,17 @@
1
-
2
- const { IO } = require('iosignal')
3
-
4
- const io = new IO('ws://localhost:7777')
5
-
6
- io.on('ready', ()=>{
7
- console.log('ready cid:', io.cid)
8
- io.signal('#screen','playToggle')
9
- });
10
-
11
- io.listen('#notify', (...args)=>{
12
- console.log( args )
13
- })
14
-
15
- io.on('error',err=>{
16
- console.log('err', err)
17
- })
1
+
2
+ const { IO } = require('iosignal')
3
+
4
+ const io = new IO('ws://localhost:7777')
5
+
6
+ io.on('ready', ()=>{
7
+ console.log('ready cid:', io.cid)
8
+ io.signal('#screen','playToggle')
9
+ });
10
+
11
+ io.listen('#notify', (...args)=>{
12
+ console.log( args )
13
+ })
14
+
15
+ io.on('error',err=>{
16
+ console.log('err', err)
17
+ })
@@ -1,17 +1,17 @@
1
-
2
- import { IO } from "iosignal"
3
-
4
- const io = new IO('ws://localhost:7777')
5
-
6
- io.on('ready', ()=>{
7
- console.log('ready cid:', io.cid)
8
- io.signal('#screen','playToggle')
9
- });
10
-
11
- io.listen('#notify', (...args)=>{
12
- console.log( args )
13
- })
14
-
15
- io.on('error',err=>{
16
- console.log('err', err)
17
- })
1
+
2
+ import { IO } from "iosignal"
3
+
4
+ const io = new IO('ws://localhost:7777')
5
+
6
+ io.on('ready', ()=>{
7
+ console.log('ready cid:', io.cid)
8
+ io.signal('#screen','playToggle')
9
+ });
10
+
11
+ io.listen('#notify', (...args)=>{
12
+ console.log( args )
13
+ })
14
+
15
+ io.on('error',err=>{
16
+ console.log('err', err)
17
+ })
@@ -1,15 +1,15 @@
1
-
2
- import { IO } from "iosignal"
3
-
4
- const io = new IO('ws://localhost:7777')
5
-
6
- io.on('ready', async ()=>{
7
- let res_echo = await io.req('reply', 'echo', 'hello' )
8
- let res_date = await io.req('reply', 'date' )
9
- let res_unixtime = await io.req('reply', 'unixtime' )
10
-
11
- if( res_echo.ok ) console.log( res_echo.body )
12
- if( res_date.ok ) console.log( res_date.body )
13
- if( res_unixtime.ok ) console.log( res_unixtime.body )
14
-
15
- });
1
+
2
+ import { IO } from "iosignal"
3
+
4
+ const io = new IO('ws://localhost:7777')
5
+
6
+ io.on('ready', async ()=>{
7
+ let res_echo = await io.req('reply', 'echo', 'hello' )
8
+ let res_date = await io.req('reply', 'date' )
9
+ let res_unixtime = await io.req('reply', 'unixtime' )
10
+
11
+ if( res_echo.ok ) console.log( res_echo.body )
12
+ if( res_date.ok ) console.log( res_date.body )
13
+ if( res_unixtime.ok ) console.log( res_unixtime.body )
14
+
15
+ });
@@ -1,19 +1,19 @@
1
-
2
- import { IO } from "iosignal"
3
-
4
- const io = new IO('ws://localhost:7777')
5
-
6
- io.on('ready', ()=>{
7
- console.log('ready cid:', io.cid)
8
- });
9
-
10
- io.on('change', ( evt )=>{
11
- console.log('\nchange event:', evt )
12
- console.log('io.state<Number>', io.state )
13
- console.log('io.stateName<String>:', io.stateName )
14
- });
15
-
16
-
17
- io.on('error',err=>{
18
- console.log('err', err)
19
- })
1
+
2
+ import { IO } from "iosignal"
3
+
4
+ const io = new IO('ws://localhost:7777')
5
+
6
+ io.on('ready', ()=>{
7
+ console.log('ready cid:', io.cid)
8
+ });
9
+
10
+ io.on('change', ( evt )=>{
11
+ console.log('\nchange event:', evt )
12
+ console.log('io.state<Number>', io.state )
13
+ console.log('io.stateName<String>:', io.stateName )
14
+ });
15
+
16
+
17
+ io.on('error',err=>{
18
+ console.log('err', err)
19
+ })
@@ -1,19 +1,19 @@
1
- import { Server, Auth_Env } from '../index.js'
2
-
3
- const options = {
4
- port: 7777,
5
- showMetric: 2,
6
- showMessage: 'message'
7
- }
8
- // You can use environment variable BOHO_AUTH
9
-
10
- // $ BOHO_AUTH=id1.key1.255,id2.key2.200 node app.js
11
- // process.env.BOHO_AUTH=id1.key1.255,id2.key2.200
12
-
13
- // or, as constructor argument.
14
- let authInfo = 'id1.key1.255,id2.key2.200'
15
-
16
- let authManager = new Auth_Env( authInfo )
17
- const server = new Server( options, authManager )
18
-
19
-
1
+ import { Server, Auth_Env } from '../index.js'
2
+
3
+ const options = {
4
+ port: 7777,
5
+ showMetric: 2,
6
+ showMessage: 'message'
7
+ }
8
+ // You can use environment variable BOHO_AUTH
9
+
10
+ // $ BOHO_AUTH=id1.key1.255,id2.key2.200 node app.js
11
+ // process.env.BOHO_AUTH=id1.key1.255,id2.key2.200
12
+
13
+ // or, as constructor argument.
14
+ let authInfo = 'id1.key1.255,id2.key2.200'
15
+
16
+ let authManager = new Auth_Env( authInfo )
17
+ const server = new Server( options, authManager )
18
+
19
+
@@ -1,12 +1,12 @@
1
- import { Server, Auth_File } from '../index.js'
2
-
3
- const options = {
4
- port: 7777,
5
- showMetric: 2,
6
- showMessage: 'message'
7
- }
8
-
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.mjs') ) // JS version. it support comments.
11
-
12
-
1
+ import { Server, Auth_File } from '../index.js'
2
+
3
+ const options = {
4
+ port: 7777,
5
+ showMetric: 2,
6
+ showMessage: 'message'
7
+ }
8
+
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.mjs') ) // JS version. it support comments.
11
+
12
+
@@ -1,6 +1,6 @@
1
- import { Server ,api_reply } from 'iosignal'
2
-
3
- const server = new Server( { port: 7777 } )
4
-
5
- // api response module
6
- server.api('reply', api_reply)
1
+ import { Server ,api_reply } from 'iosignal'
2
+
3
+ const server = new Server( { port: 7777 } )
4
+
5
+ // api response module
6
+ server.api('reply', api_reply)
@@ -1,7 +1,7 @@
1
- import { Server ,api_sudo , Auth_Env } from 'iosignal'
2
-
3
- let authManager = new Auth_Env('admin.adminkey.255')
4
- const server = new Server( { port: 7777 } ,authManager )
5
-
6
- // api response module
7
- server.api('sudo', api_sudo )
1
+ import { Server ,api_sudo , Auth_Env } from 'iosignal'
2
+
3
+ let authManager = new Auth_Env('admin.adminkey.255')
4
+ const server = new Server( { port: 7777 } ,authManager )
5
+
6
+ // api response module
7
+ server.api('sudo', api_sudo )
@@ -1,9 +1,9 @@
1
- let { Server } = require('iosignal')
2
-
3
- const server = new Server(
4
- {
5
- port: 7777, // WebSocket
6
- congPort: 8888, // CongSocket
7
- showMetric: 2, // show clients cid(state) info
8
- showMessage: 'message' // show raw signal buffer
1
+ let { Server } = require('iosignal')
2
+
3
+ const server = new Server(
4
+ {
5
+ port: 7777, // WebSocket
6
+ congPort: 8888, // CongSocket
7
+ showMetric: 2, // show clients cid(state) info
8
+ showMessage: 'message' // show raw signal buffer
9
9
  })
@@ -1,19 +1,19 @@
1
- import { Server } from '../index.js'
2
-
3
- const server = new Server(
4
- { port: 7777, // WebSocket
5
- congPort: 8888, // CongSocket
6
- showMetric: 2,
7
- showMessage: 'message'
8
- } )
9
-
10
-
11
- // text message handler (No binary message)
12
- // print text message
13
- // then reply.
14
- server.on('text_message', (msg, remote)=>{
15
- console.log('text_message from(cid): ', remote.cid, msg.toString() )
16
- let result = { msg: msg, yourcid: remote.cid , date: new Date().toUTCString() }
17
- let res = JSON.stringify( result )
18
- remote.send( res )
19
- })
1
+ import { Server } from '../index.js'
2
+
3
+ const server = new Server(
4
+ { port: 7777, // WebSocket
5
+ congPort: 8888, // CongSocket
6
+ showMetric: 2,
7
+ showMessage: 'message'
8
+ } )
9
+
10
+
11
+ // text message handler (No binary message)
12
+ // print text message
13
+ // then reply.
14
+ server.on('text_message', (msg, remote)=>{
15
+ console.log('text_message from(cid): ', remote.cid, msg.toString() )
16
+ let result = { msg: msg, yourcid: remote.cid , date: new Date().toUTCString() }
17
+ let res = JSON.stringify( result )
18
+ remote.send( res )
19
+ })
@@ -1,12 +1,12 @@
1
- import { Server } from '../index.js'
2
-
3
- const server = new Server({
4
- port: 7777 ,
5
- congPort: 8888,
6
- showMessage: 'message'
7
- } )
8
-
9
- server.on('text_message', (data, client)=>{
10
- console.log( 'text_message', data ,'from', client.cid )
11
- client.send('from server. your cid is '+ client.cid + ".")
1
+ import { Server } from '../index.js'
2
+
3
+ const server = new Server({
4
+ port: 7777 ,
5
+ congPort: 8888,
6
+ showMessage: 'message'
7
+ } )
8
+
9
+ server.on('text_message', (data, client)=>{
10
+ console.log( 'text_message', data ,'from', client.cid )
11
+ client.send('from server. your cid is '+ client.cid + ".")
12
12
  })