|
|
|
import { IHeartbeat } from 'heartbeat.ts'; |
|
|
|
export class HeartbeatClientRPCImpl implements IHeartbeatClient { |
|
|
|
static bindImpl(pipe: Pipe, pipePool: PipePool, impl: IHeartbeatClient) { |
|
const peer = new RPCPeer(); |
|
peer.addHander('bx.heartbeat.HeartbeatClient.OnHeartbeat', async () => { |
|
return await impl.onHeartbeat(); |
|
}); |
|
this.peer.pipe(pipe); |
|
} |
|
|
|
constructor (pipe: Pipe, pipePool: PipePool) { |
|
this.pipe = pipe; |
|
this.pipePool = pipePool; |
|
|
|
this.peer = new RPCPeer(); |
|
this.peer.pipe(pipte) |
|
} |
|
|
|
onHeartbeat() { |
|
return this.peer.request('bx.heartbeat.HeartbeatClient.OnHeartbeat'); |
|
} |
|
|
|
|
|
} |
|
|
|
export class HeartbeatRPCImpl implements IHeartbeat { |
|
static module = 'bx.heartbeat'; |
|
static interfaceName = 'Heartbeat'; |
|
|
|
static bindImpl(pipe: Pipe, pipePool: PipePool, impl: Heartbeat) { |
|
const peer = new RPCPeer(); |
|
peer.addHander('bx.heartbeat.Heartbeat.RequestNotifications', async (r) => { |
|
const pipe = pipePool.get(r.client.$$pipeRef); |
|
const client = new HeartbeatClientRPCImpl(pipe, pipePool); |
|
return await impl.requestNotifications(client); |
|
}) |
|
|
|
} |
|
|
|
constructor(pipe: Pipe, pipePool: PipePool) { |
|
this.pipe = pipe; |
|
this.pipePool = pipePool; |
|
|
|
this.peer = new RPCPeer(); |
|
this.peer.pipe(pipte) |
|
} |
|
|
|
requestNotifications(r) { |
|
const { client } = r; |
|
// will create and open a new pipe (aka DuplexStream) |
|
const pipe = this.pipePool.createPipe(); |
|
HeartbeatRPCImpl.bindImpl(pipe, this.pipePool, client); |
|
return this.peer.request('bx.heartbeat.Heartbeat.RequestNotifications', { client : { $$pipeRef: pipe.id }}) |
|
} |
|
} |
|
|