Skip to content

Commit

Permalink
v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
remocons committed Jan 6, 2024
1 parent fb7b096 commit 4913b0b
Show file tree
Hide file tree
Showing 49 changed files with 6,117 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules/
.DS_Store
.vscode/
*.log
*.tgz

171 changes: 170 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,170 @@
# iosignal
# IOSignal

This library provides a server and client for doing signaling(messaging) with peers that supports [`iosignal`](https://github.com/remocons/iosignal).

## Install

```
$ npm i iosignal
```

## Usage

NodeJS Server
```
// ESM filename.mjs
import { Server, ServerOption } from "iosignal"
// CJS filename.cjs
// let { Server, serverOption } = require('iosignal')
serverOption.showMetric = 2;
serverOption.port = 7777 // websocket port for browser and nodejs app.
serverOption.congPort = 8888 // additional TCP port for Arduino
const server = new Server( serverOption )
console.log( 'serverOption:', serverOption )
```

NodeJS Client example
```
// ESM
import { IO } from "iosignal"
// CJS
// const { IO } = require('iosignal')
const io = new IO('wss://io.remocon.kr/ws')
io.on('ready', ()=>{
console.log('ready cid:', io.cid)
io.signal('#screen','playToggle')
});
io.listen('#notify', (...args)=>{
console.log( args )
})
io.on('error',err=>{
console.log('err', err)
})
```

IIFE: WebBrowser client
```
<html>
...
<script src="../dist/iosignal.min.js"></script>
...
<script>
console.log('IO', IO) // default global variable name is capital IO
var io1 = new IO('ws://localhost:7777')
var io2 = new IO('ws://localhost:7777')
var io3 = new IO('ws://localhost:7777')
io1.on('error', errorHandler )
io2.on('error', errorHandler )
io3.on('error', errorHandler )
let channelName = 'io'
// classic style subsribing
io1.on('ready',e=>{
io1.subscribe(channelName)
io1.on(channelName, (...args)=>{
// console.log('io1 received', args )
let msg = '[io1] ' + JSON.stringify( args )
addMessage(msg)
})
})
// iosignal style subscribing
io2.listen(channelName, (...args)=>{
// console.log('io2 receive', args )
let msg = '[io2] ' + JSON.stringify( args )
addMessage(msg)
})
setInterval(e=>{
io3.signal(channelName, 'single string') // single string payload
io3.signal(channelName, Date.now(), 'a', 2 , {key: 3} ) //multiple payload
io3.signal(channelName ) // pure signal without payload.
},3000)
function addMessage(msg){
// ...
}
function errorHandler(e){
// ...
}
</script>
</html>
```

ESM: WebBrowser client
```
<html>
...
<script type="module">
import { IO, Boho, MBP, Buffer, sha256 } from "../dist/iosignal.esm.js"
console.log('sha256.hash("hi")', sha256.hash('hi'))
const = io = new IO('wss://io.remocon.kr/ws')
io.listen('target#topic', (...args)={
console.log( args )
})
io.on('ready',()=>{
console.log('ready cid:', io.cid )
})
</script>
...
</html>
```
## Features

### Built-in Message Trasport Protocol
- pub/sub multicast by channel name.
- uni-cast: one to one messaging by CID.
- `CID` is a Communication Id
- CID subscribing: subscribe one peer using CID.
- HomeChannel: group by IP address.

### Built-in Security
- Authentication
- Encryption
- E2EE
- thanks to the `Boho` [ [github](https://github.com/remocons/boho) ]

## Connection
- Web browser use WebSocket.
- Node.js use WebSocket or CongSocket.
- Arduino use CongSocket.

![IOSignal](./img/iosignal_stack.png)

## iosignal repositories.
- Javascript: `iosignal` [ [github](https://github.com/remocons/iosignal) | [npm](https://www.npmjs.com/package/iosignal) ]
- Node.js server ( WebSocket, CongSocket)
- Node.js client ( WebSocket, CongSocket)
- Web Browser client( WebSocket)
- Arduino client:
- Arduino Library Manager: `IOSignal`
- or `iosignal-arduino` [ [github](https://github.com/remocons/iosignal-arduino) ]

- IOSignal CLI program
- server and client
- support mac, linux and windows.
- `iosignal-cli` [ [github](https://github.com/remocons/iosignal-cli) | [npm](https://www.npmjs.com/package/iosignal-cli) ]
- install: `sudo npm i -g iosignal-cli` or `npm i -g iosignal-cli`

## License

This code is released under the MIT License.
13 changes: 13 additions & 0 deletions auth_file.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
["sampleid","samplekey","sample_cid",0],
["id_max8","no_key_size_limit","communication_id",0],
["device1","device1_key","device1_cid",0],
["device2","device2_key","device2_cid",0],
["uno","uno","uno",1],
["go","go","go",2],
["bro","bro","bro",3],
["admin","admin","admin",255],
["adminb","adminb","adminb",255]
]


23 changes: 23 additions & 0 deletions auth_file.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

/*
Authentication data sample.
device props: ["did", "key", "cid", level ]
did: ( device id ) authentication id. maximum 8 chars.
key: ( device key ) authentication key. no size limit.
cid: ( communication id ) signal target id. maximum 12 chars.
level:( quota level) <Number> ref. /server/quotaTable.js
*/
export const authInfo = [
["did","passowrd","cid",0],
["device1","device1_key","device1_cid",0],
["device2","device2_key","device2_cid",0],
["uno","uno-key","uno",1],
["go","go-key","go",2],
["bro","bro-key","bro",3],
["admin","admin-key","admin",255],
]


2 changes: 2 additions & 0 deletions dist/iosignal.cjs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions dist/iosignal.esm.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/iosignal.esm.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions dist/iosignal.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/iosignal.min.js.map

Large diffs are not rendered by default.

Binary file added img/iosignal_stack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export { IOCongSocket } from './src/client/IOCongSocket.js'
export { IOWS as IO } from './src/client/IOWS.js'
export { pack, CongRx } from './src/client/CongPacket.js'
export { Server } from './src/server/Server.js'
export { serverOption } from './src/server/serverOption.js'
export { FileLogger } from './src/server/FileLogger.js'
export * from './src/common/constants.js'

// boho auth
export * from 'boho'
export { BohoAuth } from './src/auth/BohoAuth.js'
export { Auth_File } from './src/auth/Auth_File.js'
export { Auth_Env } from './src/auth/Auth_Env.js'
export { Auth_Redis } from './src/auth/Auth_Redis.js'

// api
export * as api_reply from './src/api/api_reply.js'
export * as api_sudo from './src/api/api_sudo.js'
export { RedisAPI } from './src/api/RedisAPI.js'
13 changes: 13 additions & 0 deletions indexWebBrowser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { IO } from './src/client/IOWebSocket.js'
import { Boho, RAND, MBP, BohoMsg, Meta, MetaSize , sha256, Buffer } from 'boho'

Boho.RAND = RAND;
Boho.BohoMsg = BohoMsg;
Boho.Meta = Meta;
Boho.MetaSize = MetaSize;
Boho.sha256 = sha256;
IO.Boho = Boho;
IO.MBP = MBP;
IO.Buffer = Buffer;

export default IO;
Loading

0 comments on commit 4913b0b

Please sign in to comment.