commit 30790d588aa2d3ccdaab1975d88651b1ff292b31 Author: Darlingnotin Date: Sat Oct 3 20:45:54 2020 -0400 Adding initial files diff --git a/assets/WaitingOnVideo.xcf b/assets/WaitingOnVideo.xcf new file mode 100644 index 0000000..f6abe7f Binary files /dev/null and b/assets/WaitingOnVideo.xcf differ diff --git a/assets/WaitingOnVideoAfterClick.png b/assets/WaitingOnVideoAfterClick.png new file mode 100644 index 0000000..9eff981 Binary files /dev/null and b/assets/WaitingOnVideoAfterClick.png differ diff --git a/assets/WaitingOnVideoAfterClick.xcf b/assets/WaitingOnVideoAfterClick.xcf new file mode 100644 index 0000000..c236736 Binary files /dev/null and b/assets/WaitingOnVideoAfterClick.xcf differ diff --git a/assets/clickToWatch.png b/assets/clickToWatch.png new file mode 100644 index 0000000..0b6999f Binary files /dev/null and b/assets/clickToWatch.png differ diff --git a/assets/clickToWatch.xcf b/assets/clickToWatch.xcf new file mode 100644 index 0000000..6141818 Binary files /dev/null and b/assets/clickToWatch.xcf differ diff --git a/assets/leave.fbx b/assets/leave.fbx new file mode 100644 index 0000000..1f5b384 Binary files /dev/null and b/assets/leave.fbx differ diff --git a/assets/pauseButton.fbx b/assets/pauseButton.fbx new file mode 100644 index 0000000..bc3807d Binary files /dev/null and b/assets/pauseButton.fbx differ diff --git a/assets/playButton.fbx b/assets/playButton.fbx new file mode 100644 index 0000000..1c3a5f9 Binary files /dev/null and b/assets/playButton.fbx differ diff --git a/assets/play_btn.png b/assets/play_btn.png new file mode 100644 index 0000000..21c2115 Binary files /dev/null and b/assets/play_btn.png differ diff --git a/assets/videoInProgress.png b/assets/videoInProgress.png new file mode 100644 index 0000000..2892527 Binary files /dev/null and b/assets/videoInProgress.png differ diff --git a/assets/videoInProgress.xcf b/assets/videoInProgress.xcf new file mode 100644 index 0000000..0183d3a Binary files /dev/null and b/assets/videoInProgress.xcf differ diff --git a/assets/videoInterfaceButton.fbx b/assets/videoInterfaceButton.fbx new file mode 100644 index 0000000..ffe4318 Binary files /dev/null and b/assets/videoInterfaceButton.fbx differ diff --git a/assets/videoSyncInterface.html b/assets/videoSyncInterface.html new file mode 100644 index 0000000..f60a556 --- /dev/null +++ b/assets/videoSyncInterface.html @@ -0,0 +1,248 @@ + + + + Video Sync Interface + + + + +

Enter new video URL

+

+

+
+

Video slider

+ +
+

+

+ + + + \ No newline at end of file diff --git a/assets/volumeButtonMinus.fbx b/assets/volumeButtonMinus.fbx new file mode 100644 index 0000000..8a5dd09 Binary files /dev/null and b/assets/volumeButtonMinus.fbx differ diff --git a/assets/volumeButtonPlus.fbx b/assets/volumeButtonPlus.fbx new file mode 100644 index 0000000..95f9837 Binary files /dev/null and b/assets/volumeButtonPlus.fbx differ diff --git a/assets/volumeSlider.html b/assets/volumeSlider.html new file mode 100644 index 0000000..1cb8831 --- /dev/null +++ b/assets/volumeSlider.html @@ -0,0 +1,73 @@ + + + + Video Sync Interface + + + + +
+

Volume

+ +
+ + + + \ No newline at end of file diff --git a/assets/waitingOnVideo.png b/assets/waitingOnVideo.png new file mode 100644 index 0000000..97d3af4 Binary files /dev/null and b/assets/waitingOnVideo.png differ diff --git a/videoSync.html b/videoSync.html new file mode 100644 index 0000000..868db2f --- /dev/null +++ b/videoSync.html @@ -0,0 +1,181 @@ + + + + Video Sync + + + + +
+ +
+ + + + + + \ No newline at end of file diff --git a/videoSync.js b/videoSync.js new file mode 100644 index 0000000..a710ee2 --- /dev/null +++ b/videoSync.js @@ -0,0 +1,343 @@ +(function () { + var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); + var videoSyncInterface = Script.resolvePath("assets/videoSyncInterface.html"); + var videoSyncServerScriptUrl = Script.resolvePath("videoSyncServerScript.js"); + var volumeSliderSourceUrl = Script.resolvePath("assets/volumeSlider.html"); + var uuid; + var script = this; + var entity; + var _entityID; + var sourceUrl = Script.resolvePath("videoSync.html" + "?" + Date.now()); + var leaveButtonFbxUrl = Script.resolvePath("assets/leave.fbx"); + var playButtonFbxUrl = Script.resolvePath("assets/playButton.fbx"); + var pauseButtonURL = Script.resolvePath("assets/pauseButton.fbx"); + var volumeButtonPlusUrl = Script.resolvePath("assets/volumeButtonPlus.fbx"); + var videoInterfaceButton = Script.resolvePath("assets/videoInterfaceButton.fbx"); + var volumeButtonPlus; + var volumeButtonMinus; + var playButtonUuid; + var pauseButtonUuid; + var leaveButtonUuid; + var videoInterfaceButtonUuid; + var volumeSliderUuid; + var buttonsAreActive = false; + var hasInteractedWithWebPage = false; + var webPanelTimeStamp; + var interfaceButtonActive = false; + + function openVideoInter() { + if (buttonsAreActive || interfaceButtonActive) { + tablet.gotoWebScreen(videoSyncInterface); + } + }; + + tablet.webEventReceived.connect(onTabletWebEvent); + + function onTabletWebEvent(event) { + var webEventData = JSON.parse(event); + console.log(JSON.stringify(webEventData)); + if (webEventData.action == "nowVideoFromTablet") { + sendMessage(event); + } else if (webEventData.action == "RequestVideoLengthAndTimeStamp") { + sendMessage(event); + } else if (webEventData.action == "play") { + Messages.sendMessage("videoPlayOnEntity", event); + } + } + + script.preload = function (entityID) { + entity = Entities.getEntityProperties(entityID, ["position", "dimensions", "rotation", "serverScripts"]); + Entities.editEntity(entityID, { + sourceUrl: sourceUrl, + dpi: 8, + maxFPS: 60, + grab: { + "grabbable": false, + }, + }); + if (entity.serverScripts == "") { + Entities.editEntity(entityID, { + serverScripts: videoSyncServerScriptUrl + }); + } + _entityID = entityID; + Entities.webEventReceived.connect(onWebEvent); + addButtons(); + } + + function onWebEvent(uuid, event) { + if (uuid == _entityID || volumeSliderUuid == uuid) { + var messageData = JSON.parse(event); + console.log("Web Event " + JSON.stringify(messageData)); + if (messageData.action == "requestSync") { + webPanelTimeStamp = messageData.myTimeStamp; + } else if (messageData.action == "RequestVideoLengthAndTimeStampResponse") { + tablet.emitScriptEvent(event); + return; + } else if (messageData.action == "volumeSlider") { + sendMessage(event); + return; + } + Messages.sendMessage("videoPlayOnEntity", event); + } + } + + function onMessageReceived(channel, message, sender, localOnly) { + if (channel != "videoPlayOnEntity") { + return; + } + var messageData = JSON.parse(message); + console.log("Message Received " + JSON.stringify(messageData)); + if (messageData.action == "sync" && webPanelTimeStamp == messageData.myTimeStamp) { + if (messageData.videoUrl != "") { + buttonsAreActive = true; + hideAndRevealButtons(buttonsAreActive); + } else if (messageData.videoUrl == "") { + hasInteractedWithWebPage = true; + interfaceButtonActive = true; + addInterfaceButton(); + } + } else if (messageData.action == "now" && hasInteractedWithWebPage) { + buttonsAreActive = true; + hideAndRevealButtons(buttonsAreActive); + } + sendMessage(message); + } + + function sendMessage(message) { + Entities.emitScriptEvent(_entityID, message); + } + + function addButtons() { + leaveButtonUuid = Entities.addEntity({ + type: "Model", + modelURL: leaveButtonFbxUrl, + parentID: _entityID, + triggerable: true, + position: Vec3.sum(entity.position, Vec3.multiplyQbyV(entity.rotation, { x: entity.dimensions.x / 2 - entity.dimensions.x - -0.2, y: entity.dimensions.y / 2 - entity.dimensions.y - 0.2, z: 0 })), + dimensions: { + "x": 0.22840283811092377, + "y": 0.22654350101947784, + "z": 0.019338179379701614 + }, + grab: { + "grabbable": false, + }, + visible: false + }, "local"); + Script.addEventHandler(leaveButtonUuid, "mousePressOnEntity", evaluateWhichButtonPressed); + + pauseButtonUuid = Entities.addEntity({ + type: "Model", + modelURL: pauseButtonURL, + parentID: _entityID, + triggerable: true, + position: Vec3.sum(entity.position, Vec3.multiplyQbyV(entity.rotation, { x: entity.dimensions.x / 2 - entity.dimensions.x - -0.8, y: entity.dimensions.y / 2 - entity.dimensions.y - 0.2, z: 0 })), + dimensions: { + "x": 0.22840283811092377, + "y": 0.22654350101947784, + "z": 0.019338179379701614 + }, + grab: { + "grabbable": false, + }, + visible: false + }, "local"); + Script.addEventHandler(pauseButtonUuid, "mousePressOnEntity", evaluateWhichButtonPressed); + + playButtonUuid = Entities.addEntity({ + type: "Model", + modelURL: playButtonFbxUrl, + parentID: _entityID, + triggerable: true, + position: Vec3.sum(entity.position, Vec3.multiplyQbyV(entity.rotation, { x: entity.dimensions.x / 2 - entity.dimensions.x - -0.5, y: entity.dimensions.y / 2 - entity.dimensions.y - 0.2, z: 0 })), + dimensions: { + "x": 0.22840283811092377, + "y": 0.22654350101947784, + "z": 0.019338179379701614 + }, + grab: { + "grabbable": false, + }, + visible: false + }, "local"); + Script.addEventHandler(playButtonUuid, "mousePressOnEntity", evaluateWhichButtonPressed); + + volumeButtonMinus = Entities.addEntity({ + type: "Model", + modelURL: leaveButtonFbxUrl, + parentID: _entityID, + triggerable: true, + position: Vec3.sum(entity.position, Vec3.multiplyQbyV(entity.rotation, { x: entity.dimensions.x / 2 - 0.2, y: entity.dimensions.y / 2 - entity.dimensions.y - 0.2, z: 0 })), + dimensions: { + "x": 0.2284, + "y": 0.0779, + "z": 0.0193 + }, + grab: { + "grabbable": false, + }, + }, "local"); + Script.addEventHandler(volumeButtonMinus, "mousePressOnEntity", evaluateWhichButtonPressed); + + volumeButtonPlus = Entities.addEntity({ + type: "Model", + modelURL: volumeButtonPlusUrl, + parentID: _entityID, + triggerable: true, + position: Vec3.sum(entity.position, Vec3.multiplyQbyV(entity.rotation, { x: entity.dimensions.x / 2 - 0.5, y: entity.dimensions.y / 2 - entity.dimensions.y - 0.2, z: 0 })), + dimensions: { + "x": 0.22840283811092377, + "y": 0.22654350101947784, + "z": 0.019338179379701614 + }, + grab: { + "grabbable": false, + }, + }, "local"); + Script.addEventHandler(volumeButtonPlus, "mousePressOnEntity", evaluateWhichButtonPressed); + + videoInterfaceButtonUuid = Entities.addEntity({ + type: "Model", + modelURL: videoInterfaceButton, + parentID: _entityID, + triggerable: true, + position: Vec3.sum(entity.position, Vec3.multiplyQbyV(entity.rotation, { x: entity.dimensions.x / 2 - entity.dimensions.x + 0.5, y: entity.dimensions.y / 2 + 0.4, z: 0 })), + grab: { + "grabbable": false, + }, + visible: false + }, "local"); + Script.addEventHandler(videoInterfaceButtonUuid, "mousePressOnEntity", evaluateWhichButtonPressed); + + volumeSliderUuid = Entities.addEntity({ + type: "Web", + dpi: 8, + sourceUrl: volumeSliderSourceUrl, + parentID: uuid, + //visible: false, + dimensions: { + "x": 1.3687, + "y": 0.3429, + "z": 0.0010 + }, + registrationPoint: { + "x": 0.5, + "y": 0.5, + "z": 0 + }, + position: Vec3.sum(entity.position, Vec3.multiplyQbyV(entity.rotation, { x: entity.dimensions.x / 2 - 1.4, y: entity.dimensions.y / 2 - entity.dimensions.y - 0.2, z: 0 })), + rotation: entity.rotation + }, "local"); + } + + function evaluateWhichButtonPressed(mousePressEntityID, event) { + switch (mousePressEntityID) { + case pauseButtonUuid: + console.log("PauseButtonUuid Yes"); + actOnButtonPressed("pause"); + break; + case leaveButtonUuid: + console.log("LeaveButtonUuid Yes"); + actOnButtonPressed("leave"); + buttonsAreActive = false; + interfaceButtonActive = false; + hideAndRevealButtons(buttonsAreActive); + break; + case playButtonUuid: + console.log("playButtonUuid Yes"); + actOnButtonPressed("play"); + break; + case volumeButtonMinus: + console.log("volumeButtonMinus Yes"); + actOnButtonPressed("volumeButtonMinus"); + break; + case volumeButtonPlus: + console.log("volumeButtonPlus Yes"); + actOnButtonPressed("volumeButtonPlus"); + break; + case videoInterfaceButtonUuid: + console.log("videoInterfaceButton Yes"); + openVideoInter(); + break; + } + } + + function addInterfaceButton() { + Entities.editEntity(videoInterfaceButtonUuid, { + visible: true, + position: Vec3.sum(entity.position, Vec3.multiplyQbyV(entity.rotation, { x: entity.dimensions.x / 2 - entity.dimensions.x + 0.5, y: entity.dimensions.y / 2 + 0.4, z: 0 })) + }); + } + + function hideAndRevealButtons(hideOrReveal) { + entity = Entities.getEntityProperties(_entityID, ["position", "dimensions", "rotation"]); + Entities.editEntity(leaveButtonUuid, { + visible: hideOrReveal, + position: Vec3.sum(entity.position, Vec3.multiplyQbyV(entity.rotation, { x: entity.dimensions.x / 2 - entity.dimensions.x - -0.2, y: entity.dimensions.y / 2 - entity.dimensions.y - 0.2, z: 0 })) + }); + + Entities.editEntity(pauseButtonUuid, { + visible: hideOrReveal, + position: Vec3.sum(entity.position, Vec3.multiplyQbyV(entity.rotation, { x: entity.dimensions.x / 2 - entity.dimensions.x - -0.8, y: entity.dimensions.y / 2 - entity.dimensions.y - 0.2, z: 0 })) + }); + + Entities.editEntity(playButtonUuid, { + visible: hideOrReveal, + position: Vec3.sum(entity.position, Vec3.multiplyQbyV(entity.rotation, { x: entity.dimensions.x / 2 - entity.dimensions.x - -0.5, y: entity.dimensions.y / 2 - entity.dimensions.y - 0.2, z: 0 })) + }); + + Entities.editEntity(volumeButtonMinus, { + position: Vec3.sum(entity.position, Vec3.multiplyQbyV(entity.rotation, { x: entity.dimensions.x / 2 - 0.2, y: entity.dimensions.y / 2 - entity.dimensions.y - 0.2, z: 0 })) + }); + + Entities.editEntity(volumeButtonPlus, { + position: Vec3.sum(entity.position, Vec3.multiplyQbyV(entity.rotation, { x: entity.dimensions.x / 2 - 0.5, y: entity.dimensions.y / 2 - entity.dimensions.y - 0.2, z: 0 })) + }); + + Entities.editEntity(videoInterfaceButtonUuid, { + visible: hideOrReveal, + position: Vec3.sum(entity.position, Vec3.multiplyQbyV(entity.rotation, { x: entity.dimensions.x / 2 - entity.dimensions.x + 0.5, y: entity.dimensions.y / 2 + 0.4, z: 0 })) + }); + + Entities.editEntity(volumeSliderUuid, { + position: Vec3.sum(entity.position, Vec3.multiplyQbyV(entity.rotation, { x: entity.dimensions.x / 2 - 1.4, y: entity.dimensions.y / 2 - entity.dimensions.y - 0.2, z: 0 })), + rotation: entity.rotation + }); + } + + function actOnButtonPressed(buttonAction) { + var readyEvent = { + "action": "buttonAction", + "buttonAction": buttonAction + }; + sendMessage(JSON.stringify(readyEvent)); + } + + function removeButtons() { + Entities.deleteEntity(leaveButtonUuid); + Entities.deleteEntity(pauseButtonUuid); + Entities.deleteEntity(playButtonUuid); + Entities.deleteEntity(volumeButtonMinus); + Entities.deleteEntity(volumeButtonPlus); + Entities.deleteEntity(videoInterfaceButtonUuid); + Entities.deleteEntity(volumeSliderUuid); + Script.removeEventHandler(videoInterfaceButtonUuid, "mousePressOnEntity", evaluateWhichButtonPressed); + Script.removeEventHandler(volumeButtonPlus, "mousePressOnEntity", evaluateWhichButtonPressed); + Script.removeEventHandler(volumeButtonMinus, "mousePressOnEntity", evaluateWhichButtonPressed); + Script.removeEventHandler(leaveButtonUuid, "mousePressOnEntity", evaluateWhichButtonPressed); + Script.removeEventHandler(pauseButtonUuid, "mousePressOnEntity", evaluateWhichButtonPressed); + Script.removeEventHandler(playButtonUuid, "mousePressOnEntity", evaluateWhichButtonPressed); + } + + Messages.subscribe("videoPlayOnEntity"); + Messages.messageReceived.connect(onMessageReceived); + script.unload = function (entityID) { + Messages.unsubscribe("videoPlayOnEntity"); + Entities.deleteEntity(uuid); + Messages.messageReceived.disconnect(onMessageReceived); + Entities.webEventReceived.disconnect(onWebEvent); + tablet.webEventReceived.disconnect(onTabletWebEvent); + removeButtons(); + } +}); diff --git a/videoSyncServerScript.js b/videoSyncServerScript.js new file mode 100644 index 0000000..4e1c16b --- /dev/null +++ b/videoSyncServerScript.js @@ -0,0 +1,84 @@ +(function () { + var timeStamp; + var messageData; + var pingTimer = 0; + var intervalIsRunning = false; + var videoUrl = ""; + var timeStampInterval; + var thisTimeout; + var videoLength; + var videoPlaying = false; + var newVideoSent = false; + var newVideoSender; + + function onMessageReceived(channel, message, sender, localOnly) { + if (channel != "videoPlayOnEntity") { + return; + } + messageData = JSON.parse(message); + if (messageData.action == "now") { + videoPlaying = true; + newVideoSent = true; + newVideoSender = messageData.myTimeStamp; + timeStamp = messageData.timeStamp; + videoUrl = messageData.videoUrl; + videoLength = messageData.length; + if (intervalIsRunning) { + Script.clearInterval(timeStampInterval); + } + intervalIsRunning = true; + ping(); + } else if (messageData.action == "play") { + timeStamp = messageData.timeStamp; + if (intervalIsRunning) { + Script.clearInterval(timeStampInterval); + } + intervalIsRunning = true; + videoPlaying = true; + ping(); + } else if (messageData.action == "pause") { + Script.clearInterval(timeStampInterval); + intervalIsRunning = false; + } else if (messageData.action == "sync") { + timeStamp = messageData.timeStamp; + } else if (messageData.action == "requestSync") { + Script.setTimeout(function () { + var readyEvent = { + action: "sync", + timeStamp: timeStamp, + videoUrl: videoUrl, + nowVideo: "false", + videoPlaying: intervalIsRunning, + myTimeStamp: messageData.myTimeStamp + }; + var message = JSON.stringify(readyEvent); + Messages.sendMessage("videoPlayOnEntity", message); + }, 600); + } + } + + function ping() { + timeStampInterval = Script.setInterval(function () { + timeStamp = timeStamp + 1; + pingTimer = pingTimer + 1; + if (pingTimer == 60) { + pingTimer = 0; + messageData.timeStamp = timeStamp; + messageData.action = "ping"; + var message = JSON.stringify(messageData); + Messages.sendMessage("videoPlayOnEntity", message); + } + }, 1000); + } + + Messages.subscribe("videoPlayOnEntity"); + Messages.messageReceived.connect(onMessageReceived); + + this.unload = function () { + Messages.unsubscribe("videoPlayOnEntity"); + Messages.messageReceived.disconnect(onMessageReceived); + if (intervalIsRunning) { + Script.clearInterval(timeStampInterval); + } + } +});