From 900ed963c0d25f0500b7ebaea0bfa3eb9ac26def Mon Sep 17 00:00:00 2001 From: Michael Mainguy Date: Tue, 17 Oct 2023 10:24:53 -0500 Subject: [PATCH] Updated OPTIONS method for user function --- netlify/functions/users/users.ts | 10 +++++ src/controllers/functions/wheelHandler.ts | 6 +++ src/controllers/webController.ts | 47 ++++++++++++++++++-- src/integration/pouchdbPersistenceManager.ts | 22 ++++++--- 4 files changed, 75 insertions(+), 10 deletions(-) create mode 100644 src/controllers/functions/wheelHandler.ts diff --git a/netlify/functions/users/users.ts b/netlify/functions/users/users.ts index 312fcc7..a4cf863 100644 --- a/netlify/functions/users/users.ts +++ b/netlify/functions/users/users.ts @@ -4,6 +4,16 @@ import axios from 'axios'; export const handler: Handler = async (event: HandlerEvent, context: HandlerContext) => { try { const origin = event.headers.origin; + if (event.httpMethod == 'OPTIONS') { + return { + headers: { + 'Content-Type': 'application/json', + 'Access-Control-Allow-Origin': origin ? origin : 'https://cameras.immersiveidea.com', + 'Access-Control-Allow-Credentials': 'true' + }, + statusCode: 200 + }; + } const baseurl = 'https://syncdb-service-d3f974de56ef.herokuapp.com/'; const params = JSON.parse(event.body); const dbKey = params.shareKey; diff --git a/src/controllers/functions/wheelHandler.ts b/src/controllers/functions/wheelHandler.ts new file mode 100644 index 0000000..e2730f7 --- /dev/null +++ b/src/controllers/functions/wheelHandler.ts @@ -0,0 +1,6 @@ +export function wheelHandler() { + this.upDownWheel = false; + this.fowardBackWheel = false; + this.rig.updown(0); + this.rig.forwardback(0); +} \ No newline at end of file diff --git a/src/controllers/webController.ts b/src/controllers/webController.ts index 15ec302..74a6a88 100644 --- a/src/controllers/webController.ts +++ b/src/controllers/webController.ts @@ -4,9 +4,11 @@ import {ControllerEventType, Controllers} from "./controllers"; import {DiagramManager} from "../diagram/diagramManager"; import {GridMaterial} from "@babylonjs/materials"; import {setMenuPosition} from "../util/functions/setMenuPosition"; +import {wheelHandler} from "./functions/wheelHandler"; export class WebController { private scene: Scene; + private speed: number = 1; private readonly referencePlane: AbstractMesh; private grabbedMesh: AbstractMesh; private pickedMesh: AbstractMesh; @@ -14,6 +16,8 @@ export class WebController { private diagramManager: DiagramManager; private mouseDown: boolean = false; private controllers: Controllers; + private upDownWheel: boolean = false; + private fowardBackWheel: boolean = false; constructor(scene: Scene, rig: Rigplatform, diagramManager: DiagramManager, controllers: Controllers) { this.scene = scene; @@ -36,16 +40,22 @@ export class WebController { if (kbInfo.type == 1) { switch (kbInfo.event.key) { case "ArrowUp": - this.rig.forwardback(-1); + this.rig.forwardback(-this.speed); break; case "ArrowDown": - this.rig.forwardback(1); + this.rig.forwardback(this.speed); break; case "ArrowLeft": - this.rig.leftright(-1); + this.rig.leftright(-this.speed); break; case "ArrowRight": - this.rig.leftright(1); + this.rig.leftright(this.speed); + break; + case "]": + this.speed *= 1.5; + break; + case "[": + this.speed *= .5; break; case " ": if (kbInfo.event.ctrlKey) { @@ -81,6 +91,35 @@ export class WebController { this.rig.turn(0); }; + + window.addEventListener('wheel', (evt) => { + switch (evt.buttons) { + case 0: + if (this.fowardBackWheel == false) { + this.fowardBackWheel = true; + const reset = wheelHandler.bind(this); + setTimeout(reset, 500); + } + if (Math.sign(evt.deltaY) != 0) { + this.rig.forwardback(evt.deltaY / 100); + } + break; + case 1: + if (this.upDownWheel == false) { + this.upDownWheel = true; + const reset = wheelHandler.bind(this); + setTimeout(reset, 500); + } + if (Math.sign(evt.deltaY) != 0) { + this.rig.updown(evt.deltaY / 100); + } + + break; + + } + + + }); this.scene.onPointerDown = (evt, state, type) => { if (evt.pointerType == "mouse") { if (evt.shiftKey) { diff --git a/src/integration/pouchdbPersistenceManager.ts b/src/integration/pouchdbPersistenceManager.ts index 15bcfc5..1ab7122 100644 --- a/src/integration/pouchdbPersistenceManager.ts +++ b/src/integration/pouchdbPersistenceManager.ts @@ -115,10 +115,15 @@ export class PouchdbPersistenceManager implements IPersistenceManager { } - public async setConfig(config: any): Promise { - const doc = await this.config.get('1'); - const newConf = {...config, _id: '1', _rev: doc._rev}; - return this.config.put(newConf); + public async setConfig(config: any, initial: boolean = false): Promise { + if (!initial) { + const doc = await this.config.get('1'); + const newConf = {...config, _id: '1', _rev: doc._rev}; + return this.config.put(newConf); + } else { + const newConf = {...config, _id: '1'}; + return this.config.put(newConf); + } } public async getConfig(): Promise { @@ -150,7 +155,7 @@ export class PouchdbPersistenceManager implements IPersistenceManager { currentDiagramId: uuidv4() } try { - await this.setConfig(defaultConfig); + await this.setConfig(defaultConfig, true); } catch (err) { console.log(err); } @@ -214,7 +219,12 @@ export class PouchdbPersistenceManager implements IPersistenceManager { const dbs = await axios.get('https://syncdb-service-d3f974de56ef.herokuapp.com/_all_dbs'); if (dbs.data.indexOf(syncTarget) == -1) { console.log('sync target missing'); - return; + const buildTarget = await axios.post('https://deepdiagram.com/.netlify/functions/users', + {username: syncTarget, password: 'password'}); + if (buildTarget.status != 200) { + console.log(buildTarget.statusText); + return; + } } console.log(dbs);