@napolab/texture-bridge-renderer 0.6.6 → 0.7.1

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.
package/dist/index.cjs CHANGED
@@ -266,19 +266,28 @@ var TextureReceiverBridgeImpl = class extends events.EventEmitter {
266
266
  super();
267
267
  this.fpsCounter = new FpsCounter();
268
268
  this._disposed = false;
269
+ this._started = false;
269
270
  this._timer = null;
270
271
  this.receiver = receiver;
271
272
  this.pollIntervalMs = pollIntervalMs;
273
+ const platform = (0, _napolab_texture_bridge_core.getPlatform)();
274
+ this.useEventDriven = platform === "spout" || platform === "syphon-metal";
272
275
  }
273
276
  get isDisposed() {
274
277
  return this._disposed;
275
278
  }
276
279
  start() {
277
- if (this._disposed || this._timer) return;
280
+ if (this._disposed || this._started) return;
281
+ this._started = true;
278
282
  this.fpsCounter.reset();
279
- this._timer = setInterval(() => this._poll(), this.pollIntervalMs);
283
+ if (this.useEventDriven) this.receiver.startListening((frame) => {
284
+ if (this._disposed) return;
285
+ this._onFrame(frame);
286
+ });
287
+ else this._timer = setInterval(() => this._poll(), this.pollIntervalMs);
280
288
  }
281
289
  stop() {
290
+ this._started = false;
282
291
  if (this._timer) {
283
292
  clearInterval(this._timer);
284
293
  this._timer = null;
@@ -295,14 +304,22 @@ var TextureReceiverBridgeImpl = class extends events.EventEmitter {
295
304
  [Symbol.dispose]() {
296
305
  this.dispose();
297
306
  }
307
+ _onFrame(frame) {
308
+ try {
309
+ this.emit("frame", frame);
310
+ const fps = this.fpsCounter.tick();
311
+ if (fps !== null) this.emit("fps", fps);
312
+ } catch (err) {
313
+ const error = err instanceof Error ? err : new Error(String(err));
314
+ this.emit("error", error);
315
+ }
316
+ }
298
317
  _poll() {
299
318
  if (this._disposed) return;
300
319
  try {
301
320
  const frame = this.receiver.receiveFrame();
302
321
  if (!frame) return;
303
- this.emit("frame", frame);
304
- const fps = this.fpsCounter.tick();
305
- if (fps !== null) this.emit("fps", fps);
322
+ this._onFrame(frame);
306
323
  } catch (err) {
307
324
  const error = err instanceof Error ? err : new Error(String(err));
308
325
  this.emit("error", error);
package/dist/index.d.cts CHANGED
@@ -72,6 +72,7 @@ interface TextureReceiverBridgeOptions {
72
72
  senderName: string;
73
73
  appName?: string;
74
74
  serverUuid?: string;
75
+ /** Polling interval in ms (only used on platforms without event-driven support). */
75
76
  pollIntervalMs?: number;
76
77
  }
77
78
  interface ReceiverBridgeEvents {
package/dist/index.d.mts CHANGED
@@ -72,6 +72,7 @@ interface TextureReceiverBridgeOptions {
72
72
  senderName: string;
73
73
  appName?: string;
74
74
  serverUuid?: string;
75
+ /** Polling interval in ms (only used on platforms without event-driven support). */
75
76
  pollIntervalMs?: number;
76
77
  }
77
78
  interface ReceiverBridgeEvents {
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { EventEmitter } from "events";
2
2
  import { BrowserWindow, app, ipcMain, sharedTexture } from "electron";
3
- import { TextureReceiver, TextureSender, listSenders, sendTextureFromPaintEvent } from "@napolab/texture-bridge-core";
3
+ import { TextureReceiver, TextureSender, getPlatform, listSenders, sendTextureFromPaintEvent } from "@napolab/texture-bridge-core";
4
4
  import path from "path";
5
5
 
6
6
  //#region src/preview-manager.ts
@@ -237,19 +237,28 @@ var TextureReceiverBridgeImpl = class extends EventEmitter {
237
237
  super();
238
238
  this.fpsCounter = new FpsCounter();
239
239
  this._disposed = false;
240
+ this._started = false;
240
241
  this._timer = null;
241
242
  this.receiver = receiver;
242
243
  this.pollIntervalMs = pollIntervalMs;
244
+ const platform = getPlatform();
245
+ this.useEventDriven = platform === "spout" || platform === "syphon-metal";
243
246
  }
244
247
  get isDisposed() {
245
248
  return this._disposed;
246
249
  }
247
250
  start() {
248
- if (this._disposed || this._timer) return;
251
+ if (this._disposed || this._started) return;
252
+ this._started = true;
249
253
  this.fpsCounter.reset();
250
- this._timer = setInterval(() => this._poll(), this.pollIntervalMs);
254
+ if (this.useEventDriven) this.receiver.startListening((frame) => {
255
+ if (this._disposed) return;
256
+ this._onFrame(frame);
257
+ });
258
+ else this._timer = setInterval(() => this._poll(), this.pollIntervalMs);
251
259
  }
252
260
  stop() {
261
+ this._started = false;
253
262
  if (this._timer) {
254
263
  clearInterval(this._timer);
255
264
  this._timer = null;
@@ -266,14 +275,22 @@ var TextureReceiverBridgeImpl = class extends EventEmitter {
266
275
  [Symbol.dispose]() {
267
276
  this.dispose();
268
277
  }
278
+ _onFrame(frame) {
279
+ try {
280
+ this.emit("frame", frame);
281
+ const fps = this.fpsCounter.tick();
282
+ if (fps !== null) this.emit("fps", fps);
283
+ } catch (err) {
284
+ const error = err instanceof Error ? err : new Error(String(err));
285
+ this.emit("error", error);
286
+ }
287
+ }
269
288
  _poll() {
270
289
  if (this._disposed) return;
271
290
  try {
272
291
  const frame = this.receiver.receiveFrame();
273
292
  if (!frame) return;
274
- this.emit("frame", frame);
275
- const fps = this.fpsCounter.tick();
276
- if (fps !== null) this.emit("fps", fps);
293
+ this._onFrame(frame);
277
294
  } catch (err) {
278
295
  const error = err instanceof Error ? err : new Error(String(err));
279
296
  this.emit("error", error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@napolab/texture-bridge-renderer",
3
- "version": "0.6.6",
3
+ "version": "0.7.1",
4
4
  "description": "High-level factory API for GPU texture bridge (BrowserWindow + Preview + Sender)",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -25,7 +25,7 @@
25
25
  "./package.json": "./package.json"
26
26
  },
27
27
  "dependencies": {
28
- "@napolab/texture-bridge-core": "0.6.6"
28
+ "@napolab/texture-bridge-core": "0.7.1"
29
29
  },
30
30
  "peerDependencies": {
31
31
  "electron": ">=40.0.0"