1
0

Update videoSync.js

This commit is contained in:
Darlingnotin 2020-10-09 17:45:53 -04:00
parent ad7b5a9808
commit ec7c54125d

View File

@ -24,6 +24,8 @@
var hasInteractedWithWebPage = false; var hasInteractedWithWebPage = false;
var webPanelTimeStamp; var webPanelTimeStamp;
var interfaceButtonActive = false; var interfaceButtonActive = false;
var videoPlayerChannel;
var tabletOpen = false;
function openVideoInter() { function openVideoInter() {
if (buttonsAreActive || interfaceButtonActive) { if (buttonsAreActive || interfaceButtonActive) {
@ -36,16 +38,23 @@
function onTabletWebEvent(event) { function onTabletWebEvent(event) {
var webEventData = JSON.parse(event); var webEventData = JSON.parse(event);
console.log(JSON.stringify(webEventData)); console.log(JSON.stringify(webEventData));
if (webEventData.action == "nowVideoFromTablet") { if (webEventData.tabletId == videoPlayerChannel) {
sendMessage(event); if (webEventData.action == "nowVideoFromTablet") {
sendMessage(event);
} else if (webEventData.action == "play") {
Messages.sendMessage(videoPlayerChannel, event);
}
} else if (webEventData.action == "RequestVideoLengthAndTimeStamp") { } else if (webEventData.action == "RequestVideoLengthAndTimeStamp") {
sendMessage(event); if (tabletOpen) {
} else if (webEventData.action == "play") { tabletOpen = false;
Messages.sendMessage("videoPlayOnEntity", event); sendMessage(event);
}
} }
} }
script.preload = function (entityID) { script.preload = function (entityID) {
videoPlayerChannel = entityID;
Messages.subscribe(videoPlayerChannel);
entity = Entities.getEntityProperties(entityID, ["position", "dimensions", "rotation", "serverScripts"]); entity = Entities.getEntityProperties(entityID, ["position", "dimensions", "rotation", "serverScripts"]);
Entities.editEntity(entityID, { Entities.editEntity(entityID, {
sourceUrl: sourceUrl, sourceUrl: sourceUrl,
@ -72,18 +81,19 @@
if (messageData.action == "requestSync") { if (messageData.action == "requestSync") {
webPanelTimeStamp = messageData.myTimeStamp; webPanelTimeStamp = messageData.myTimeStamp;
} else if (messageData.action == "RequestVideoLengthAndTimeStampResponse") { } else if (messageData.action == "RequestVideoLengthAndTimeStampResponse") {
tablet.emitScriptEvent(event); messageData.tabletId = videoPlayerChannel;
tablet.emitScriptEvent(JSON.stringify(messageData));
return; return;
} else if (messageData.action == "volumeSlider") { } else if (messageData.action == "volumeSlider") {
sendMessage(event); sendMessage(event);
return; return;
} }
Messages.sendMessage("videoPlayOnEntity", event); Messages.sendMessage(videoPlayerChannel, event);
} }
} }
function onMessageReceived(channel, message, sender, localOnly) { function onMessageReceived(channel, message, sender, localOnly) {
if (channel != "videoPlayOnEntity") { if (channel != videoPlayerChannel) {
return; return;
} }
var messageData = JSON.parse(message); var messageData = JSON.parse(message);
@ -214,7 +224,7 @@
type: "Web", type: "Web",
dpi: 8, dpi: 8,
sourceUrl: volumeSliderSourceUrl, sourceUrl: volumeSliderSourceUrl,
parentID: uuid, parentID: _entityID,
//visible: false, //visible: false,
dimensions: { dimensions: {
"x": 1.3687, "x": 1.3687,
@ -258,6 +268,7 @@
break; break;
case videoInterfaceButtonUuid: case videoInterfaceButtonUuid:
console.log("videoInterfaceButton Yes"); console.log("videoInterfaceButton Yes");
tabletOpen = true;
openVideoInter(); openVideoInter();
break; break;
} }
@ -268,6 +279,10 @@
visible: true, 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 })) 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(leaveButtonUuid, {
visible: 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 }))
});
} }
function hideAndRevealButtons(hideOrReveal) { function hideAndRevealButtons(hideOrReveal) {
@ -330,10 +345,9 @@
Script.removeEventHandler(playButtonUuid, "mousePressOnEntity", evaluateWhichButtonPressed); Script.removeEventHandler(playButtonUuid, "mousePressOnEntity", evaluateWhichButtonPressed);
} }
Messages.subscribe("videoPlayOnEntity");
Messages.messageReceived.connect(onMessageReceived); Messages.messageReceived.connect(onMessageReceived);
script.unload = function (entityID) { script.unload = function (entityID) {
Messages.unsubscribe("videoPlayOnEntity"); Messages.unsubscribe(videoPlayerChannel);
Entities.deleteEntity(uuid); Entities.deleteEntity(uuid);
Messages.messageReceived.disconnect(onMessageReceived); Messages.messageReceived.disconnect(onMessageReceived);
Entities.webEventReceived.disconnect(onWebEvent); Entities.webEventReceived.disconnect(onWebEvent);