Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async _p2pSend (peerAddress, obj) {
// log.t(this.me() + ' >>> ' + this.nick(peerAddress) + ' - ' + obj.type)
return this._p2p.publishReliable(
[peerAddress],
msgpack.encode(obj).toString('base64')
)
}
async _p2pSendAll (obj) {
// log.t(this.me() + ' >>> ' + this._peerList + ' - ' + obj.type)
return this._p2p.publishReliable(
this._peerList,
msgpack.encode(obj).toString('base64')
)
}
const ipcMsg = async (type, data) => {
const resp = await client.call(
msgpack.encode({ type, data }))
if (!resp) {
console.error('bad ipc response', resp)
process.exit(1)
}
if (resp.byteLength) {
return msgpack.decode(resp)
}
}
onPressEnter = value => {
this.setState({ value: value.target.value });
storeState(this.props.uuid, this.state, { value: value.target.value });
this.props.socket.emit(this.props.uuid + '#enter', msgpack.encode(value.target.value));
};
send(message) {
const serializedMessage = msgpack.encode(message);
const header = new Uint32Array([ serializedMessage.byteLength ]);
this.pipe.write(Buffer.from(header.buffer));
this.pipe.write(serializedMessage);
}
}
write(type, payload) {
const data = msgpack.encode([ String(type), payload ]);
this.socket.write(data);
}
public write(reqId: number, method: string, args: any[]) {
const req = [0, reqId, method, args];
const encoded = msgpack.encode(req);
this.socket.send(encoded);
}
getEncodedState () {
return msgpack.encode( utils.toJSON( this.state ) )
}
_ipcSend (data) {
let msg = Buffer.from(JSON.stringify(data), 'utf8')
msg = msgpack.encode({ name: 'json', data: msg }).toString('base64')
this._ipc.send(Array.from(this._ipc.keys()), msg)
}
async _sendByCId (cIdList, msgId, fromPeerAddress, peerAddressList, type, data) {
if (!(data instanceof Buffer)) {
throw new Error('data must be a Buffer')
}
return this._con.send(cIdList, msgpack.encode([
msgId, fromPeerAddress, peerAddressList, type, data]).toString('base64'))
}