Skip to content

Instantly share code, notes, and snippets.

@hediet
Created March 15, 2019 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hediet/4911f69320a4e1904a3fb2f6059f2372 to your computer and use it in GitHub Desktop.
Save hediet/4911f69320a4e1904a3fb2f6059f2372 to your computer and use it in GitHub Desktop.
// shared
export const debuggerProxyContract = contract({
server: {
keepAlive: notificationContract({}),
},
client: {
serverStarted: notificationContract({ params: type({ port: number }) }),
clientConnected: notificationContract({}),
},
});
// client
const proc = spawn("node", ["server.js"]);
const { server } = debuggerProxyContract.getServerFromStream(
NodeJsMessageStream.connectToProcess(proc),
undefined,
{
serverStarted: ({ port }) => {
// ...
},
clientConnected: () => {
// ...
}
}
);
// server
const { client } = debuggerProxyContract.registerServerToStream(
NodeJsMessageStream.connectToThisProcess(),
{
keepAlive: () => {
timeout.reset();
},
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment