Created
February 19, 2017 11:01
-
-
Save djungelorm/90fd690db0af5d01f4a31a3b811165b2 to your computer and use it in GitHub Desktop.
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
'use strict'; | |
var WebSocket = require('ws'); | |
var ProtoBuf = require('protobufjs') | |
var builder = ProtoBuf.loadProtoFile('krpc.proto'), | |
proto = builder.build(); | |
function decodeBytes(buffer) { | |
return buffer.slice(5) | |
} | |
var rpcSock = new WebSocket('ws://127.0.0.1:50000') | |
rpcSock.binaryType = 'arraybuffer' | |
rpcSock.onopen = (ev) => { | |
console.log('Connected to RPC server...') | |
console.log('Call KRPC.GetClientID...') | |
let call = new proto.krpc.schema.ProcedureCall('KRPC', 'GetClientID'); | |
let req = new proto.krpc.schema.Request([call]); | |
rpcSock.send(req.toArrayBuffer()); | |
}; | |
rpcSock.onmessage = (ev) => { | |
let resp = proto.krpc.schema.Response.decode(ev.data); | |
let id = decodeBytes(resp.results[0].value).toString('base64'); | |
console.log('Client ID =', id); | |
console.log('Connecting to Stream server...'); | |
var streamSock = new WebSocket('ws://127.0.0.1:50001?id=' + id); | |
streamSock.binaryType = 'arraybuffer'; | |
streamSock.onopen = (ev) => { | |
console.log('Successfully connected!'); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment