@viji-dev/core 0.3.5 → 0.3.7

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.
@@ -446,16 +446,16 @@ class InteractionSystem {
446
446
  this.mouseState.rightButton = (data.buttons & 2) !== 0;
447
447
  this.mouseState.middleButton = (data.buttons & 4) !== 0;
448
448
  this.mouseState.isPressed = data.buttons > 0;
449
- this.mouseState.deltaX = data.deltaX || 0;
450
- this.mouseState.deltaY = data.deltaY || 0;
451
- this.mouseState.wheelDelta = data.wheelDeltaY || 0;
452
- this.mouseState.wheelX = data.wheelDeltaX || 0;
453
- this.mouseState.wheelY = data.wheelDeltaY || 0;
449
+ this.mouseState.deltaX += data.deltaX || 0;
450
+ this.mouseState.deltaY += data.deltaY || 0;
451
+ this.mouseState.wheelDelta += data.wheelDeltaY || 0;
452
+ this.mouseState.wheelX += data.wheelDeltaX || 0;
453
+ this.mouseState.wheelY += data.wheelDeltaY || 0;
454
454
  this.mouseState.velocity.x = data.deltaX || 0;
455
455
  this.mouseState.velocity.y = data.deltaY || 0;
456
- this.mouseState.wasPressed = data.wasPressed || false;
457
- this.mouseState.wasReleased = data.wasReleased || false;
458
- this.mouseState.wasMoved = data.deltaX !== 0 || data.deltaY !== 0;
456
+ this.mouseState.wasPressed = this.mouseState.wasPressed || (data.wasPressed || false);
457
+ this.mouseState.wasReleased = this.mouseState.wasReleased || (data.wasReleased || false);
458
+ this.mouseState.wasMoved = this.mouseState.wasMoved || (data.deltaX !== 0 || data.deltaY !== 0);
459
459
  }
460
460
  /**
461
461
  * Handle keyboard update messages from the host
@@ -3963,7 +3963,11 @@ class VijiWorkerRuntime {
3963
3963
  this.deviceVideoMap.set(deviceId, index);
3964
3964
  const device = this.viji.devices.find((d) => d.id === deviceId);
3965
3965
  if (device) {
3966
- device.video = videoSystem.getVideoAPI();
3966
+ if (device.video) {
3967
+ Object.assign(device.video, videoSystem.getVideoAPI());
3968
+ } else {
3969
+ device.video = videoSystem.getVideoAPI();
3970
+ }
3967
3971
  }
3968
3972
  }
3969
3973
  break;
@@ -3985,7 +3989,11 @@ class VijiWorkerRuntime {
3985
3989
  if (deviceId) {
3986
3990
  const device = this.viji.devices.find((d) => d.id === deviceId);
3987
3991
  if (device) {
3988
- device.video = vs.getVideoAPI();
3992
+ if (device.video) {
3993
+ Object.assign(device.video, vs.getVideoAPI());
3994
+ } else {
3995
+ device.video = vs.getVideoAPI();
3996
+ }
3989
3997
  }
3990
3998
  }
3991
3999
  }
@@ -4018,7 +4026,11 @@ class VijiWorkerRuntime {
4018
4026
  } else if (streamType === "device" && deviceId) {
4019
4027
  const device = this.viji.devices.find((d) => d.id === deviceId);
4020
4028
  if (device) {
4021
- device.video = vs.getVideoAPI();
4029
+ if (device.video) {
4030
+ Object.assign(device.video, vs.getVideoAPI());
4031
+ } else {
4032
+ device.video = vs.getVideoAPI();
4033
+ }
4022
4034
  }
4023
4035
  }
4024
4036
  }
@@ -4168,7 +4180,6 @@ class VijiWorkerRuntime {
4168
4180
  renderFrame() {
4169
4181
  if (!this.isRunning) return;
4170
4182
  const currentTime = performance.now();
4171
- this.interactionSystem.frameStart();
4172
4183
  this.updateVijiStreams();
4173
4184
  this.viji.fps = this.frameRateMode === "full" ? this.screenRefreshRate : this.screenRefreshRate / 2;
4174
4185
  let shouldRender = true;
@@ -4237,6 +4248,7 @@ class VijiWorkerRuntime {
4237
4248
  }
4238
4249
  }
4239
4250
  this.reportPerformanceStats(currentTime);
4251
+ this.interactionSystem.frameStart();
4240
4252
  requestAnimationFrame(() => this.renderFrame());
4241
4253
  }
4242
4254
  postMessage(type, data) {
@@ -4263,15 +4275,24 @@ class VijiWorkerRuntime {
4263
4275
  handleDeviceStateUpdate(message) {
4264
4276
  this.deviceState = message.data;
4265
4277
  this.viji.device = this.deviceState.device;
4266
- const devicesWithVideo = this.deviceState.devices.map((device) => {
4267
- const streamIndex = this.deviceVideoMap.get(device.id);
4268
- const videoSystem = streamIndex !== void 0 ? this.videoSystems[streamIndex] : void 0;
4269
- return {
4270
- ...device,
4271
- video: videoSystem ? videoSystem.getVideoAPI() : null
4272
- };
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
+ }
4273
4294
  });
4274
- this.viji.devices = devicesWithVideo;
4295
+ this.viji.devices = updatedDevices;
4275
4296
  }
4276
4297
  }
4277
4298
  class SceneAnalyzer {
@@ -4338,4 +4359,4 @@ async function setSceneCode(sceneCode) {
4338
4359
  }
4339
4360
  }
4340
4361
  self.setSceneCode = setSceneCode;
4341
- //# sourceMappingURL=viji.worker-FGKsBwO8.js.map
4362
+ //# sourceMappingURL=viji.worker-CariIqqP.js.map