-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v1.4.0 fix signal MBA paylod type handler
- Loading branch information
Showing
14 changed files
with
155 additions
and
26 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { parsePayload, getSignalPack, getPayloadFromSignalPack, PAYLOAD_TYPE, MBP } from 'iosignal' | ||
|
||
const type0 = [] | ||
const type1t = ['a1'] | ||
const type1n = [11] | ||
const type2 = [new Uint8Array(5)] | ||
const type3 = [{ name: 'type3' }] | ||
const type4a = ['a2', 222] | ||
const type4b = [{ name: 'a3' }, 333] | ||
const type5 = [{ a: 1 }, Buffer.from('BBBBBB')] | ||
|
||
// zero or one argument support: 0:EMPTY, 1:TEXT , 2:BINARY signal payload type | ||
console.log(PAYLOAD_TYPE[parsePayload(type0).type], type0) // empty | ||
console.log(PAYLOAD_TYPE[parsePayload(type1t).type], type1t) // text | ||
console.log(PAYLOAD_TYPE[parsePayload(type1n).type], type1n) // number text. there is no Number type of signalPaylod. | ||
console.log(PAYLOAD_TYPE[parsePayload(type2).type], type2) // binary. | ||
|
||
// over two arguments support: 3:Object, 4:MJSON and 5:MBA can hold Number item. | ||
console.log(PAYLOAD_TYPE[parsePayload(type3).type], type3) // Object | ||
console.log(PAYLOAD_TYPE[parsePayload(type4a).type], type4a) // MJSON | ||
console.log(PAYLOAD_TYPE[parsePayload(type4b).type], type4b) // MJSON | ||
console.log(PAYLOAD_TYPE[parsePayload(type5).type], type5) // MBA | ||
|
||
|
||
let signalTag = 'channel' | ||
let signalPack = getSignalPack( signalTag, ...type5) | ||
console.log('signalPack', signalPack) | ||
|
||
let payloadBuffer = getPayloadFromSignalPack(signalPack) | ||
let unpack = MBP.unpack(payloadBuffer) | ||
console.log(unpack) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { IO, Server} from 'iosignal' | ||
|
||
let url = 'ws://localhost:5555' | ||
let server = new Server({ | ||
port: 5555 | ||
// ,showMessage: 'message' | ||
}) | ||
let done = false; | ||
|
||
let tx = new IO(url) | ||
tx.on('ready', () => { | ||
console.log('tx ready', tx.cid) | ||
}) | ||
|
||
|
||
let rx = new IO(url) | ||
rx.on('ready', () => { | ||
console.log('rx ready', rx.cid) | ||
}) | ||
|
||
rx.listen('@', (...args) => { | ||
console.log('uni-cast rxi', args) | ||
}) | ||
|
||
rx.listen('channel', (...args) => { | ||
console.log('multi-cast rxi', args) | ||
}) | ||
|
||
function sendSignals() { | ||
// uni-casting: tag is receiver CID@. | ||
let tag = rx.cid + '@topic' | ||
tx.signal(tag, ...arg1) | ||
tx.signal(tag, ...arg2) | ||
tx.signal(tag, ...arg3) | ||
tx.signal(tag, ...arg4) | ||
tx.signal(tag, ...arg5) | ||
|
||
// multi-casting: tag is channel name. | ||
tag = 'channel' | ||
tx.signal(tag, ...arg1) | ||
tx.signal(tag, ...arg2) | ||
tx.signal(tag, ...arg3) | ||
tx.signal(tag, ...arg4) | ||
tx.signal(tag, ...arg5) | ||
} | ||
|
||
|
||
const arg1 = ['a1'] | ||
const arg2 = ['a2', 222] | ||
const arg3 = [{ name: 'a3' }, 333] | ||
const arg4 = [{a:1}, Buffer.from('KKKKK')] | ||
const arg5 = [new Uint8Array(20)] | ||
|
||
|
||
setTimeout(() => { | ||
sendSignals(); | ||
}, 1000) | ||
|
||
setTimeout(() => { | ||
process.exit() | ||
}, 2000) |