camstreamerlib 4.0.0-beta.70 → 4.0.0-beta.71

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -168,13 +168,20 @@ class CamOverlayDrawingAPI extends events_1.EventEmitter {
168
168
  throw new Error('No CamOverlay connection');
169
169
  }
170
170
  msgJson.call_id = ++this.callId;
171
- const jsonBuffer = Buffer.from(JSON.stringify(msgJson));
172
- const header = new ArrayBuffer(5);
173
- const headerView = new DataView(header);
174
- headerView.setInt8(0, 1);
175
- headerView.setInt32(1, jsonBuffer.byteLength);
176
- const msgBuffer = Buffer.concat([Buffer.from(header), jsonBuffer, data]);
177
- const arrayBuffer = msgBuffer.buffer.slice(msgBuffer.byteOffset, msgBuffer.byteOffset + msgBuffer.byteLength);
171
+ const jsonString = JSON.stringify(msgJson);
172
+ const jsonByteLength = Buffer.byteLength(jsonString);
173
+ const headerLength = 5;
174
+ const totalLength = headerLength + jsonByteLength + data.byteLength;
175
+ const arrayBuffer = new ArrayBuffer(totalLength);
176
+ const view = new DataView(arrayBuffer);
177
+ view.setInt8(0, 1);
178
+ view.setInt32(1, jsonByteLength);
179
+ const jsonBuffer = new Uint8Array(arrayBuffer, 5, jsonByteLength);
180
+ for (let i = 0; i < jsonString.length; i++) {
181
+ jsonBuffer[i] = jsonString.charCodeAt(i);
182
+ }
183
+ const dataBuffer = new Uint8Array(arrayBuffer, 5 + jsonByteLength, data.byteLength);
184
+ data.copy(dataBuffer);
178
185
  this.ws.send(arrayBuffer);
179
186
  this.sendMessages[this.callId] = { resolve, reject, sentTimestamp: Date.now() };
180
187
  }
@@ -165,13 +165,20 @@ export class CamOverlayDrawingAPI extends EventEmitter {
165
165
  throw new Error('No CamOverlay connection');
166
166
  }
167
167
  msgJson.call_id = ++this.callId;
168
- const jsonBuffer = Buffer.from(JSON.stringify(msgJson));
169
- const header = new ArrayBuffer(5);
170
- const headerView = new DataView(header);
171
- headerView.setInt8(0, 1);
172
- headerView.setInt32(1, jsonBuffer.byteLength);
173
- const msgBuffer = Buffer.concat([Buffer.from(header), jsonBuffer, data]);
174
- const arrayBuffer = msgBuffer.buffer.slice(msgBuffer.byteOffset, msgBuffer.byteOffset + msgBuffer.byteLength);
168
+ const jsonString = JSON.stringify(msgJson);
169
+ const jsonByteLength = Buffer.byteLength(jsonString);
170
+ const headerLength = 5;
171
+ const totalLength = headerLength + jsonByteLength + data.byteLength;
172
+ const arrayBuffer = new ArrayBuffer(totalLength);
173
+ const view = new DataView(arrayBuffer);
174
+ view.setInt8(0, 1);
175
+ view.setInt32(1, jsonByteLength);
176
+ const jsonBuffer = new Uint8Array(arrayBuffer, 5, jsonByteLength);
177
+ for (let i = 0; i < jsonString.length; i++) {
178
+ jsonBuffer[i] = jsonString.charCodeAt(i);
179
+ }
180
+ const dataBuffer = new Uint8Array(arrayBuffer, 5 + jsonByteLength, data.byteLength);
181
+ data.copy(dataBuffer);
175
182
  this.ws.send(arrayBuffer);
176
183
  this.sendMessages[this.callId] = { resolve, reject, sentTimestamp: Date.now() };
177
184
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "camstreamerlib",
3
- "version": "4.0.0-beta.70",
3
+ "version": "4.0.0-beta.71",
4
4
  "description": "Helper library for CamStreamer ACAP applications.",
5
5
  "prettier": "@camstreamer/prettier-config",
6
6
  "engine": {