in remote/proxy/socket-proxy.js [47:106]
constructor(channel) {
super(channel);
/** @type {string} */
this.incomingBuffer = "";
/**
* @private
* @param {Buffer | string} data
* @returns {void}
*/
this.onChannelData = (data) => {
try {
if (Buffer.isBuffer(data)) {
data = data.toString("utf8");
}
this.incomingBuffer = this.incomingBuffer + data;
const segmentEnd = this.incomingBuffer.indexOf(";");
if (segmentEnd < 0) {
return;
}
const segments = this.incomingBuffer.split(";");
for (let dataEntryIndex = 0; dataEntryIndex < segments.length - 1; dataEntryIndex++) {
const dataEntry = segments[dataEntryIndex];
if (!dataEntry) {
continue;
}
this.triggerHandler("data", JSON.parse(Buffer.from(dataEntry, "base64").toString("utf8")));
}
this.incomingBuffer = segments.pop() || "";
} catch (error) {
Log.instance.writeExceptionAsync(error);
throw error;
}
};
this.onChannelClose = () => {
this.triggerHandler("close");
};
/**
* @param {Error} err
* @returns {void}
*/
this.onChannelError = (err) => {
this.triggerHandler("error", err);
};
this.channel.on("data", this.onChannelData);
this.channel.on("close", this.onChannelClose);
this.channel.on("error", this.onChannelError);
}