@viji-dev/core 0.3.4 → 0.3.6

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,19 @@ 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
+ if (device.video) {
3967
+ Object.assign(device.video, videoSystem.getVideoAPI());
3968
+ } else {
3969
+ device.video = videoSystem.getVideoAPI();
3970
+ }
3971
+ }
3972
+ }
3973
+ break;
3959
3974
  }
3960
3975
  }
3961
3976
  handleVideoFrameUpdate(message) {
@@ -3966,8 +3981,21 @@ class VijiWorkerRuntime {
3966
3981
  imageBitmap: message.data.imageBitmap,
3967
3982
  timestamp: message.data.timestamp
3968
3983
  });
3969
- if (vs.getStreamType() === "main") {
3984
+ const streamType = vs.getStreamType();
3985
+ if (streamType === "main") {
3970
3986
  Object.assign(this.viji.video, vs.getVideoAPI());
3987
+ } else if (streamType === "device") {
3988
+ const deviceId = vs.getDeviceId();
3989
+ if (deviceId) {
3990
+ const device = this.viji.devices.find((d) => d.id === deviceId);
3991
+ if (device) {
3992
+ if (device.video) {
3993
+ Object.assign(device.video, vs.getVideoAPI());
3994
+ } else {
3995
+ device.video = vs.getVideoAPI();
3996
+ }
3997
+ }
3998
+ }
3971
3999
  }
3972
4000
  }
3973
4001
  }
@@ -3975,6 +4003,15 @@ class VijiWorkerRuntime {
3975
4003
  const index = message.data.streamIndex || 0;
3976
4004
  const vs = this.videoSystems[index];
3977
4005
  if (vs) {
4006
+ const streamType = vs.getStreamType();
4007
+ const deviceId = vs.getDeviceId();
4008
+ if (message.data.disconnect && streamType === "device" && deviceId) {
4009
+ this.deviceVideoMap.delete(deviceId);
4010
+ const device = this.viji.devices.find((d) => d.id === deviceId);
4011
+ if (device) {
4012
+ device.video = null;
4013
+ }
4014
+ }
3978
4015
  vs.handleVideoConfigUpdate({
3979
4016
  ...message.data.targetFrameRate && { targetFrameRate: message.data.targetFrameRate },
3980
4017
  ...message.data.cvConfig && { cvConfig: message.data.cvConfig },
@@ -3983,8 +4020,19 @@ class VijiWorkerRuntime {
3983
4020
  ...message.data.disconnect && { disconnect: message.data.disconnect },
3984
4021
  timestamp: message.data.timestamp
3985
4022
  });
3986
- if (vs.getStreamType() === "main") {
3987
- Object.assign(this.viji.video, vs.getVideoAPI());
4023
+ if (!message.data.disconnect) {
4024
+ if (streamType === "main") {
4025
+ Object.assign(this.viji.video, vs.getVideoAPI());
4026
+ } else if (streamType === "device" && deviceId) {
4027
+ const device = this.viji.devices.find((d) => d.id === deviceId);
4028
+ if (device) {
4029
+ if (device.video) {
4030
+ Object.assign(device.video, vs.getVideoAPI());
4031
+ } else {
4032
+ device.video = vs.getVideoAPI();
4033
+ }
4034
+ }
4035
+ }
3988
4036
  }
3989
4037
  }
3990
4038
  }
@@ -4227,16 +4275,24 @@ class VijiWorkerRuntime {
4227
4275
  handleDeviceStateUpdate(message) {
4228
4276
  this.deviceState = message.data;
4229
4277
  this.viji.device = this.deviceState.device;
4230
- const devicesWithVideo = this.deviceState.devices.map((device) => {
4231
- const videoSystem = this.videoSystems.find(
4232
- (vs) => vs && vs.getStreamType() === "device" && vs.getDeviceId() === device.id
4233
- );
4234
- return {
4235
- ...device,
4236
- video: videoSystem ? videoSystem.getVideoAPI() : null
4237
- };
4278
+ const updatedDevices = this.deviceState.devices.map((deviceData) => {
4279
+ const existingDevice = this.viji.devices.find((d) => d.id === deviceData.id);
4280
+ if (existingDevice) {
4281
+ existingDevice.name = deviceData.name;
4282
+ existingDevice.motion = deviceData.motion;
4283
+ existingDevice.orientation = deviceData.orientation;
4284
+ existingDevice.geolocation = deviceData.geolocation;
4285
+ return existingDevice;
4286
+ } else {
4287
+ const streamIndex = this.deviceVideoMap.get(deviceData.id);
4288
+ const videoSystem = streamIndex !== void 0 ? this.videoSystems[streamIndex] : void 0;
4289
+ return {
4290
+ ...deviceData,
4291
+ video: videoSystem ? videoSystem.getVideoAPI() : null
4292
+ };
4293
+ }
4238
4294
  });
4239
- this.viji.devices = devicesWithVideo;
4295
+ this.viji.devices = updatedDevices;
4240
4296
  }
4241
4297
  }
4242
4298
  class SceneAnalyzer {
@@ -4303,4 +4359,4 @@ async function setSceneCode(sceneCode) {
4303
4359
  }
4304
4360
  }
4305
4361
  self.setSceneCode = setSceneCode;
4306
- //# sourceMappingURL=viji.worker-Cx1WpxdF.js.map
4362
+ //# sourceMappingURL=viji.worker-C3iqy9t2.js.map