@viji-dev/core 0.3.4 → 0.3.5

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.
@@ -3444,6 +3444,8 @@ class VijiWorkerRuntime {
3444
3444
  },
3445
3445
  devices: []
3446
3446
  };
3447
+ // Map deviceId → streamIndex for O(1) device video lookup
3448
+ deviceVideoMap = /* @__PURE__ */ new Map();
3447
3449
  // Video state is now managed by the worker-side VideoSystem
3448
3450
  // Artist API object
3449
3451
  viji = {
@@ -3956,6 +3958,15 @@ class VijiWorkerRuntime {
3956
3958
  case "additional":
3957
3959
  this.updateVijiStreams();
3958
3960
  break;
3961
+ case "device":
3962
+ if (deviceId) {
3963
+ this.deviceVideoMap.set(deviceId, index);
3964
+ const device = this.viji.devices.find((d) => d.id === deviceId);
3965
+ if (device) {
3966
+ device.video = videoSystem.getVideoAPI();
3967
+ }
3968
+ }
3969
+ break;
3959
3970
  }
3960
3971
  }
3961
3972
  handleVideoFrameUpdate(message) {
@@ -3966,8 +3977,17 @@ class VijiWorkerRuntime {
3966
3977
  imageBitmap: message.data.imageBitmap,
3967
3978
  timestamp: message.data.timestamp
3968
3979
  });
3969
- if (vs.getStreamType() === "main") {
3980
+ const streamType = vs.getStreamType();
3981
+ if (streamType === "main") {
3970
3982
  Object.assign(this.viji.video, vs.getVideoAPI());
3983
+ } else if (streamType === "device") {
3984
+ const deviceId = vs.getDeviceId();
3985
+ if (deviceId) {
3986
+ const device = this.viji.devices.find((d) => d.id === deviceId);
3987
+ if (device) {
3988
+ device.video = vs.getVideoAPI();
3989
+ }
3990
+ }
3971
3991
  }
3972
3992
  }
3973
3993
  }
@@ -3975,6 +3995,15 @@ class VijiWorkerRuntime {
3975
3995
  const index = message.data.streamIndex || 0;
3976
3996
  const vs = this.videoSystems[index];
3977
3997
  if (vs) {
3998
+ const streamType = vs.getStreamType();
3999
+ const deviceId = vs.getDeviceId();
4000
+ if (message.data.disconnect && streamType === "device" && deviceId) {
4001
+ this.deviceVideoMap.delete(deviceId);
4002
+ const device = this.viji.devices.find((d) => d.id === deviceId);
4003
+ if (device) {
4004
+ device.video = null;
4005
+ }
4006
+ }
3978
4007
  vs.handleVideoConfigUpdate({
3979
4008
  ...message.data.targetFrameRate && { targetFrameRate: message.data.targetFrameRate },
3980
4009
  ...message.data.cvConfig && { cvConfig: message.data.cvConfig },
@@ -3983,8 +4012,15 @@ class VijiWorkerRuntime {
3983
4012
  ...message.data.disconnect && { disconnect: message.data.disconnect },
3984
4013
  timestamp: message.data.timestamp
3985
4014
  });
3986
- if (vs.getStreamType() === "main") {
3987
- Object.assign(this.viji.video, vs.getVideoAPI());
4015
+ if (!message.data.disconnect) {
4016
+ if (streamType === "main") {
4017
+ Object.assign(this.viji.video, vs.getVideoAPI());
4018
+ } else if (streamType === "device" && deviceId) {
4019
+ const device = this.viji.devices.find((d) => d.id === deviceId);
4020
+ if (device) {
4021
+ device.video = vs.getVideoAPI();
4022
+ }
4023
+ }
3988
4024
  }
3989
4025
  }
3990
4026
  }
@@ -4228,9 +4264,8 @@ class VijiWorkerRuntime {
4228
4264
  this.deviceState = message.data;
4229
4265
  this.viji.device = this.deviceState.device;
4230
4266
  const devicesWithVideo = this.deviceState.devices.map((device) => {
4231
- const videoSystem = this.videoSystems.find(
4232
- (vs) => vs && vs.getStreamType() === "device" && vs.getDeviceId() === device.id
4233
- );
4267
+ const streamIndex = this.deviceVideoMap.get(device.id);
4268
+ const videoSystem = streamIndex !== void 0 ? this.videoSystems[streamIndex] : void 0;
4234
4269
  return {
4235
4270
  ...device,
4236
4271
  video: videoSystem ? videoSystem.getVideoAPI() : null
@@ -4303,4 +4338,4 @@ async function setSceneCode(sceneCode) {
4303
4338
  }
4304
4339
  }
4305
4340
  self.setSceneCode = setSceneCode;
4306
- //# sourceMappingURL=viji.worker-Cx1WpxdF.js.map
4341
+ //# sourceMappingURL=viji.worker-FGKsBwO8.js.map