2018-01-27 23:20:33 -08:00
|
|
|
import Base from '../src/base'
|
|
|
|
|
|
|
|
const USOCKET = __dirname + '/sample.sock'
|
2018-01-30 21:12:38 -08:00
|
|
|
|
2018-02-04 14:18:21 -08:00
|
|
|
const socketfuncs = {
|
2018-01-30 21:12:38 -08:00
|
|
|
write: function(packet){
|
2018-02-04 14:18:21 -08:00
|
|
|
packet.cmd='reply'
|
2018-01-30 21:12:38 -08:00
|
|
|
packet.response='return of write command'
|
|
|
|
return packet
|
|
|
|
},
|
|
|
|
write2: function(packet){
|
2018-02-04 14:18:21 -08:00
|
|
|
packet.cmd='reply'
|
2018-01-30 21:12:38 -08:00
|
|
|
packet.response='return of write2 command'
|
|
|
|
return packet
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-27 23:20:33 -08:00
|
|
|
;
|
|
|
|
(async () => {
|
|
|
|
|
2018-01-29 21:51:13 -08:00
|
|
|
const delay = time => new Promise(res=>setTimeout(()=>res(),time))
|
2018-01-27 23:20:33 -08:00
|
|
|
|
2018-01-29 21:51:13 -08:00
|
|
|
// let app = new Base({com:'us,uc,ts,tc', id:'example', path: USOCKET, log:false})
|
2018-02-04 14:18:21 -08:00
|
|
|
let fio = new Base({sockets:'uc#c>n,us#s>n,tc#c>t,ts#s>t', id:'four-in-one'})
|
2018-01-30 21:12:38 -08:00
|
|
|
|
2018-02-04 14:18:21 -08:00
|
|
|
// app.amendPacketProcessing(basefuncs)
|
2018-01-27 23:20:33 -08:00
|
|
|
|
2018-02-04 14:18:21 -08:00
|
|
|
await fio.init()
|
2018-01-30 21:12:38 -08:00
|
|
|
|
2018-02-04 14:18:21 -08:00
|
|
|
fio.amendNamedProcessing('tc',{
|
|
|
|
reply: packet => {
|
|
|
|
console.log('==============Packet returned to nameed consumer tc==========')
|
2018-01-29 21:51:13 -08:00
|
|
|
console.dir(packet)
|
|
|
|
console.log('===========================')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-02-04 14:18:21 -08:00
|
|
|
fio.reply = packet =>{
|
|
|
|
console.log('==============Packet Displayed by Generic reply function')
|
|
|
|
console.dir(packet)
|
|
|
|
}
|
|
|
|
|
2018-01-29 21:51:13 -08:00
|
|
|
|
|
|
|
let packet = {}
|
2018-01-30 21:12:38 -08:00
|
|
|
console.log('=============sending============')
|
|
|
|
packet = {cmd:'echo', data:'some data to echo'}
|
2018-02-04 14:18:21 -08:00
|
|
|
console.log(packet)
|
|
|
|
await fio.send(packet)
|
|
|
|
|
|
|
|
fio.amendSocketProcessing(socketfuncs)
|
2018-01-29 21:51:13 -08:00
|
|
|
|
2018-01-27 23:20:33 -08:00
|
|
|
packet = {cmd:'write', data:'data to write'}
|
2018-02-04 14:18:21 -08:00
|
|
|
console.log(packet)
|
|
|
|
await fio.send(packet)
|
|
|
|
// await app.send(packet)
|
|
|
|
// await delay(500)
|
|
|
|
// app.amendPacketContext(
|
|
|
|
// {write: function(packet){
|
|
|
|
// packet.cmd='log'
|
|
|
|
// packet.response='return of AMMEDED write command'
|
|
|
|
// return packet
|
|
|
|
// }}
|
|
|
|
// )
|
|
|
|
// await delay(500)
|
|
|
|
// packet = {cmd:'write', data:'2ND data to write'}
|
|
|
|
// await app.sendIPC(packet)
|
|
|
|
// packet = {cmd:'write2', data:'data to write'}
|
|
|
|
// await app.send(packet)
|
|
|
|
// //
|
2018-01-27 23:20:33 -08:00
|
|
|
await delay(2000)
|
|
|
|
process.kill(process.pid, 'SIGTERM')
|
|
|
|
|
|
|
|
|
|
|
|
})().catch(err => {
|
|
|
|
console.error('FATAL: UNABLE TO START SYSTEM!\n',err)
|
2018-01-29 21:51:13 -08:00
|
|
|
process.kill(process.pid, 'SIGTERM')
|
2018-01-27 23:20:33 -08:00
|
|
|
})
|
2018-01-29 21:51:13 -08:00
|
|
|
|
2018-01-30 21:12:38 -08:00
|
|
|
|
2018-01-29 21:51:13 -08:00
|
|
|
|
|
|
|
const tcpfuncs = {
|
|
|
|
write: function(packet){
|
|
|
|
packet.cmd='log'
|
|
|
|
packet.response='return of write command'
|
|
|
|
packet.via = 'tcp write'
|
|
|
|
return packet
|
|
|
|
},
|
|
|
|
write2: function(packet){
|
|
|
|
packet.cmd='log'
|
|
|
|
packet.response='return of write2 command'
|
|
|
|
packet.via = 'tcp write2'
|
|
|
|
return packet
|
|
|
|
}
|
|
|
|
}
|