From cd58dc11ceb92bf3a4c0e959a41f2ddaeb3a0f7c Mon Sep 17 00:00:00 2001 From: "Kevin M. Thomas" Date: Tue, 21 Jul 2015 18:10:13 -0400 Subject: [PATCH 1/4] Initial file placement into job. --- .../jsstreamplayerdomain-zone-entity.js | 33 +++ examples/example/jsstreamplayerdomain-zone.js | 203 ++++++++++++++++++ examples/html/jsstreamplayerdomain-zone.html | 42 ++++ 3 files changed, 278 insertions(+) create mode 100644 examples/example/entities/jsstreamplayerdomain-zone-entity.js create mode 100644 examples/example/jsstreamplayerdomain-zone.js create mode 100644 examples/html/jsstreamplayerdomain-zone.html diff --git a/examples/example/entities/jsstreamplayerdomain-zone-entity.js b/examples/example/entities/jsstreamplayerdomain-zone-entity.js new file mode 100644 index 0000000000..9a8cb8b8b4 --- /dev/null +++ b/examples/example/entities/jsstreamplayerdomain-zone-entity.js @@ -0,0 +1,33 @@ +// +// #20628: JS Stream Player Domain-Zone-Entity +// ******************************************** +// +// Created by Kevin M. Thomas and Thoys 07/20/15. +// Copyright 2015 High Fidelity, Inc. +// kevintown.net +// +// JavaScript for the High Fidelity interface that is an entity script to be placed in a chosen entity inside a domain-zone. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + + +// Function which exists inside of an entity which triggers as a user approches it. +(function() { + const SCRIPT_NAME = "https://dl.dropboxusercontent.com/u/17344741/jsstreamplayer/jsstreamplayerdomain-zone.js"; + function isScriptRunning(script) { + script = script.toLowerCase().trim(); + var runningScripts = ScriptDiscoveryService.getRunning(); + for (i in runningScripts) { + if (runningScripts[i].url.toLowerCase().trim() == script) { + return true; + } + } + return false; + }; + + if (!isScriptRunning(SCRIPT_NAME)) { + Script.load(SCRIPT_NAME); + } +}) \ No newline at end of file diff --git a/examples/example/jsstreamplayerdomain-zone.js b/examples/example/jsstreamplayerdomain-zone.js new file mode 100644 index 0000000000..fab5792dd7 --- /dev/null +++ b/examples/example/jsstreamplayerdomain-zone.js @@ -0,0 +1,203 @@ +// +// #20628: JS Stream Player Domain-Zone +// ************************************* +// +// Created by Kevin M. Thomas and Thoys 07/20/15. +// Copyright 2015 High Fidelity, Inc. +// kevintown.net +// +// JavaScript for the High Fidelity interface that creates a stream player with a UI for playing a domain-zone specificed stream URL in addition to play, stop and volume functionality which is resident only in the domain-zone. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + + +// Declare variables and set up new WebWindow. +var stream = "http://listen.radionomy.com/80sMixTape"; +var volume; +var streamWindow = new WebWindow('Stream', "https://dl.dropboxusercontent.com/u/17344741/jsstreamplayer/jsstreamplayerdomain-zone.html", 0, 0, false); +var visible = false; + +// Set up toggleStreamPlayButton overlay. +var toggleStreamPlayButton = Overlays.addOverlay("text", { + x: 122, + y: 310, + width: 38, + height: 28, + backgroundColor: { red: 0, green: 0, blue: 0}, + color: { red: 255, green: 255, blue: 0}, + font: {size: 15}, + topMargin: 8, + visible: false, + text: " Play" +}); + +// Set up toggleStreamStopButton overlay. +var toggleStreamStopButton = Overlays.addOverlay("text", { + x: 166, + y: 310, + width: 40, + height: 28, + backgroundColor: { red: 0, green: 0, blue: 0}, + color: { red: 255, green: 255, blue: 0}, + font: {size: 15}, + topMargin: 8, + visible: false, + text: " Stop" +}); + +// Set up increaseVolumeButton overlay. +var toggleIncreaseVolumeButton = Overlays.addOverlay("text", { + x: 211, + y: 310, + width: 18, + height: 28, + backgroundColor: { red: 0, green: 0, blue: 0}, + color: { red: 255, green: 255, blue: 0}, + font: {size: 15}, + topMargin: 8, + visible: false, + text: " +" +}); + +// Set up decreaseVolumeButton overlay. +var toggleDecreaseVolumeButton = Overlays.addOverlay("text", { + x: 234, + y: 310, + width: 15, + height: 28, + backgroundColor: { red: 0, green: 0, blue: 0}, + color: { red: 255, green: 255, blue: 0}, + font: {size: 15}, + topMargin: 8, + visible: false, + text: " -" +}); + +// Function to change JSON object stream. +function changeStream(stream) { + var streamJSON = { + action: "changeStream", + stream: stream + } + streamWindow.eventBridge.emitScriptEvent(JSON.stringify(streamJSON)); +} + +// Function to change JSON object volume. +function changeVolume(volume) { + var volumeJSON = { + action: "changeVolume", + volume: volume + } + streamWindow.eventBridge.emitScriptEvent(JSON.stringify(volumeJSON)); +} + +// Function that adds mousePressEvent functionality to connect UI to enter stream URL, play and stop stream. +function mousePressEvent(event) { + if (Overlays.getOverlayAtPoint({x: event.x, y: event.y}) == toggleStreamPlayButton) { + changeStream(stream); + volume = 0.25; + changeVolume(volume); + } + if (Overlays.getOverlayAtPoint({x: event.x, y: event.y}) == toggleStreamStopButton) { + changeStream(""); + } + if (Overlays.getOverlayAtPoint({x: event.x, y: event.y}) == toggleIncreaseVolumeButton) { + volume += 0.25; + changeVolume(volume); + } + if (Overlays.getOverlayAtPoint({x: event.x, y: event.y}) == toggleDecreaseVolumeButton) { + volume -= 0.25; + changeVolume(volume); + } +} + +// Function checking bool if in proper zone. +function isOurZone(properties) { + return properties.type == "Zone" && properties.name == "Zone2"; +} + +// Function checking if avatar is in zone. +function isInZone() { + var entities = Entities.findEntities(MyAvatar.position, 10000); + + for (var i in entities) { + var properties = Entities.getEntityProperties(entities[i]); + + if (isOurZone(properties)) { + var minX = properties.position.x - (properties.dimensions.x / 2); + var maxX = properties.position.x + (properties.dimensions.x / 2); + var minY = properties.position.y - (properties.dimensions.y / 2); + var maxY = properties.position.y + (properties.dimensions.y / 2); + var minZ = properties.position.z - (properties.dimensions.z / 2); + var maxZ = properties.position.z + (properties.dimensions.z / 2); + + if (MyAvatar.position.x >= minX && MyAvatar.position.x <= maxX && MyAvatar.position.y >= minY && MyAvatar.position.y <= maxY && MyAvatar.position.z >= minZ && MyAvatar.position.z <= maxZ) { + return true; + } + } + } + return false; +} + +// Function to toggle visibile the overlay. +function toggleVisible(newVisibility) { + if (newVisibility != visible) { + visible = newVisibility; + Overlays.editOverlay(toggleStreamPlayButton, {visible: visible}); + Overlays.editOverlay(toggleStreamStopButton, {visible: visible}); + Overlays.editOverlay(toggleIncreaseVolumeButton, {visible: visible}); + Overlays.editOverlay(toggleDecreaseVolumeButton, {visible: visible}); + } +} + +// Function to check if avatar is in proper domain. +Window.domainChanged.connect(function() { + if (Window.location.hostname != "Music" && Window.location.hostname != "LiveMusic") { + Script.stop(); + } +}); + +// Function to check if avatar is within zone. +Entities.enterEntity.connect(function(entityID) { + print("Entered..." + JSON.stringify(entityID)); + var properties = Entities.getEntityProperties(entityID); + if (isOurZone(properties)) { + print("Entering Zone!"); + toggleVisible(true); + } +}) + +// Function to check if avatar is leaving zone. +Entities.leaveEntity.connect(function(entityID) { + print("Left..." + JSON.stringify(entityID)); + var properties = Entities.getEntityProperties(entityID); + if (isOurZone(properties)) { + print("Leaving Zone!"); + toggleVisible(false); + changeStream(""); + } +}) + +// Function to delete overlays upon exit. +function onScriptEnding() { + Overlays.deleteOverlay(toggleStreamPlayButton); + Overlays.deleteOverlay(toggleStreamStopButton); + Overlays.deleteOverlay(toggleIncreaseVolumeButton); + Overlays.deleteOverlay(toggleDecreaseVolumeButton); + changeStream(""); + streamWindow.deleteLater(); +} + +// Function call to ensure that if you log in to the zone visibility is true. +if (isInZone()) { + toggleVisible(true); +} + +// Connect mouse and hide WebWindow. +Controller.mousePressEvent.connect(mousePressEvent); +streamWindow.setVisible(false); + +// Call function upon ending script. +Script.scriptEnding.connect(onScriptEnding); \ No newline at end of file diff --git a/examples/html/jsstreamplayerdomain-zone.html b/examples/html/jsstreamplayerdomain-zone.html new file mode 100644 index 0000000000..28b2202591 --- /dev/null +++ b/examples/html/jsstreamplayerdomain-zone.html @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 75fa789b79591b25d6240479d74c671ba2eb0b2d Mon Sep 17 00:00:00 2001 From: "Kevin M. Thomas" Date: Tue, 21 Jul 2015 18:13:26 -0400 Subject: [PATCH 2/4] Changeable zone var declaration. --- examples/example/jsstreamplayerdomain-zone.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/example/jsstreamplayerdomain-zone.js b/examples/example/jsstreamplayerdomain-zone.js index fab5792dd7..543a95b839 100644 --- a/examples/example/jsstreamplayerdomain-zone.js +++ b/examples/example/jsstreamplayerdomain-zone.js @@ -14,6 +14,7 @@ // Declare variables and set up new WebWindow. +var zone = "Zone2"; var stream = "http://listen.radionomy.com/80sMixTape"; var volume; var streamWindow = new WebWindow('Stream', "https://dl.dropboxusercontent.com/u/17344741/jsstreamplayer/jsstreamplayerdomain-zone.html", 0, 0, false); @@ -115,7 +116,7 @@ function mousePressEvent(event) { // Function checking bool if in proper zone. function isOurZone(properties) { - return properties.type == "Zone" && properties.name == "Zone2"; + return properties.type == "Zone" && properties.name == zone; } // Function checking if avatar is in zone. From d4d5c9f9359729cf97bec92cd5a920f1730529b6 Mon Sep 17 00:00:00 2001 From: "Kevin M. Thomas" Date: Fri, 24 Jul 2015 15:43:50 -0400 Subject: [PATCH 3/4] Created a folder in examples called "zones" then moved files to location. --- examples/example/jsstreamplayerdomain-zone.js | 204 ------------------ examples/html/jsstreamplayerdomain-zone.html | 42 ---- 2 files changed, 246 deletions(-) delete mode 100644 examples/example/jsstreamplayerdomain-zone.js delete mode 100644 examples/html/jsstreamplayerdomain-zone.html diff --git a/examples/example/jsstreamplayerdomain-zone.js b/examples/example/jsstreamplayerdomain-zone.js deleted file mode 100644 index 543a95b839..0000000000 --- a/examples/example/jsstreamplayerdomain-zone.js +++ /dev/null @@ -1,204 +0,0 @@ -// -// #20628: JS Stream Player Domain-Zone -// ************************************* -// -// Created by Kevin M. Thomas and Thoys 07/20/15. -// Copyright 2015 High Fidelity, Inc. -// kevintown.net -// -// JavaScript for the High Fidelity interface that creates a stream player with a UI for playing a domain-zone specificed stream URL in addition to play, stop and volume functionality which is resident only in the domain-zone. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - - -// Declare variables and set up new WebWindow. -var zone = "Zone2"; -var stream = "http://listen.radionomy.com/80sMixTape"; -var volume; -var streamWindow = new WebWindow('Stream', "https://dl.dropboxusercontent.com/u/17344741/jsstreamplayer/jsstreamplayerdomain-zone.html", 0, 0, false); -var visible = false; - -// Set up toggleStreamPlayButton overlay. -var toggleStreamPlayButton = Overlays.addOverlay("text", { - x: 122, - y: 310, - width: 38, - height: 28, - backgroundColor: { red: 0, green: 0, blue: 0}, - color: { red: 255, green: 255, blue: 0}, - font: {size: 15}, - topMargin: 8, - visible: false, - text: " Play" -}); - -// Set up toggleStreamStopButton overlay. -var toggleStreamStopButton = Overlays.addOverlay("text", { - x: 166, - y: 310, - width: 40, - height: 28, - backgroundColor: { red: 0, green: 0, blue: 0}, - color: { red: 255, green: 255, blue: 0}, - font: {size: 15}, - topMargin: 8, - visible: false, - text: " Stop" -}); - -// Set up increaseVolumeButton overlay. -var toggleIncreaseVolumeButton = Overlays.addOverlay("text", { - x: 211, - y: 310, - width: 18, - height: 28, - backgroundColor: { red: 0, green: 0, blue: 0}, - color: { red: 255, green: 255, blue: 0}, - font: {size: 15}, - topMargin: 8, - visible: false, - text: " +" -}); - -// Set up decreaseVolumeButton overlay. -var toggleDecreaseVolumeButton = Overlays.addOverlay("text", { - x: 234, - y: 310, - width: 15, - height: 28, - backgroundColor: { red: 0, green: 0, blue: 0}, - color: { red: 255, green: 255, blue: 0}, - font: {size: 15}, - topMargin: 8, - visible: false, - text: " -" -}); - -// Function to change JSON object stream. -function changeStream(stream) { - var streamJSON = { - action: "changeStream", - stream: stream - } - streamWindow.eventBridge.emitScriptEvent(JSON.stringify(streamJSON)); -} - -// Function to change JSON object volume. -function changeVolume(volume) { - var volumeJSON = { - action: "changeVolume", - volume: volume - } - streamWindow.eventBridge.emitScriptEvent(JSON.stringify(volumeJSON)); -} - -// Function that adds mousePressEvent functionality to connect UI to enter stream URL, play and stop stream. -function mousePressEvent(event) { - if (Overlays.getOverlayAtPoint({x: event.x, y: event.y}) == toggleStreamPlayButton) { - changeStream(stream); - volume = 0.25; - changeVolume(volume); - } - if (Overlays.getOverlayAtPoint({x: event.x, y: event.y}) == toggleStreamStopButton) { - changeStream(""); - } - if (Overlays.getOverlayAtPoint({x: event.x, y: event.y}) == toggleIncreaseVolumeButton) { - volume += 0.25; - changeVolume(volume); - } - if (Overlays.getOverlayAtPoint({x: event.x, y: event.y}) == toggleDecreaseVolumeButton) { - volume -= 0.25; - changeVolume(volume); - } -} - -// Function checking bool if in proper zone. -function isOurZone(properties) { - return properties.type == "Zone" && properties.name == zone; -} - -// Function checking if avatar is in zone. -function isInZone() { - var entities = Entities.findEntities(MyAvatar.position, 10000); - - for (var i in entities) { - var properties = Entities.getEntityProperties(entities[i]); - - if (isOurZone(properties)) { - var minX = properties.position.x - (properties.dimensions.x / 2); - var maxX = properties.position.x + (properties.dimensions.x / 2); - var minY = properties.position.y - (properties.dimensions.y / 2); - var maxY = properties.position.y + (properties.dimensions.y / 2); - var minZ = properties.position.z - (properties.dimensions.z / 2); - var maxZ = properties.position.z + (properties.dimensions.z / 2); - - if (MyAvatar.position.x >= minX && MyAvatar.position.x <= maxX && MyAvatar.position.y >= minY && MyAvatar.position.y <= maxY && MyAvatar.position.z >= minZ && MyAvatar.position.z <= maxZ) { - return true; - } - } - } - return false; -} - -// Function to toggle visibile the overlay. -function toggleVisible(newVisibility) { - if (newVisibility != visible) { - visible = newVisibility; - Overlays.editOverlay(toggleStreamPlayButton, {visible: visible}); - Overlays.editOverlay(toggleStreamStopButton, {visible: visible}); - Overlays.editOverlay(toggleIncreaseVolumeButton, {visible: visible}); - Overlays.editOverlay(toggleDecreaseVolumeButton, {visible: visible}); - } -} - -// Function to check if avatar is in proper domain. -Window.domainChanged.connect(function() { - if (Window.location.hostname != "Music" && Window.location.hostname != "LiveMusic") { - Script.stop(); - } -}); - -// Function to check if avatar is within zone. -Entities.enterEntity.connect(function(entityID) { - print("Entered..." + JSON.stringify(entityID)); - var properties = Entities.getEntityProperties(entityID); - if (isOurZone(properties)) { - print("Entering Zone!"); - toggleVisible(true); - } -}) - -// Function to check if avatar is leaving zone. -Entities.leaveEntity.connect(function(entityID) { - print("Left..." + JSON.stringify(entityID)); - var properties = Entities.getEntityProperties(entityID); - if (isOurZone(properties)) { - print("Leaving Zone!"); - toggleVisible(false); - changeStream(""); - } -}) - -// Function to delete overlays upon exit. -function onScriptEnding() { - Overlays.deleteOverlay(toggleStreamPlayButton); - Overlays.deleteOverlay(toggleStreamStopButton); - Overlays.deleteOverlay(toggleIncreaseVolumeButton); - Overlays.deleteOverlay(toggleDecreaseVolumeButton); - changeStream(""); - streamWindow.deleteLater(); -} - -// Function call to ensure that if you log in to the zone visibility is true. -if (isInZone()) { - toggleVisible(true); -} - -// Connect mouse and hide WebWindow. -Controller.mousePressEvent.connect(mousePressEvent); -streamWindow.setVisible(false); - -// Call function upon ending script. -Script.scriptEnding.connect(onScriptEnding); \ No newline at end of file diff --git a/examples/html/jsstreamplayerdomain-zone.html b/examples/html/jsstreamplayerdomain-zone.html deleted file mode 100644 index 28b2202591..0000000000 --- a/examples/html/jsstreamplayerdomain-zone.html +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file From ca8d0d542012f93dea2be32d2ea066d7bd1b1eca Mon Sep 17 00:00:00 2001 From: "Kevin M. Thomas" Date: Sat, 25 Jul 2015 07:56:57 -0400 Subject: [PATCH 4/4] Added files to zone folder and made change to jstreamplayerdomain-zone.js to allow for zone entity data field to load a stream url rather than have it hard coded in the js file. This allows for many zones to be created and simply having to put a new stream url in each data field in each zone to work. --- .../zones/jsstreamplayerdomain-zone-entity.js | 33 ++++ examples/zones/jsstreamplayerdomain-zone.html | 42 +++++ examples/zones/jsstreamplayerdomain-zone.js | 176 ++++++++++++++++++ 3 files changed, 251 insertions(+) create mode 100644 examples/zones/jsstreamplayerdomain-zone-entity.js create mode 100644 examples/zones/jsstreamplayerdomain-zone.html create mode 100644 examples/zones/jsstreamplayerdomain-zone.js diff --git a/examples/zones/jsstreamplayerdomain-zone-entity.js b/examples/zones/jsstreamplayerdomain-zone-entity.js new file mode 100644 index 0000000000..9a8cb8b8b4 --- /dev/null +++ b/examples/zones/jsstreamplayerdomain-zone-entity.js @@ -0,0 +1,33 @@ +// +// #20628: JS Stream Player Domain-Zone-Entity +// ******************************************** +// +// Created by Kevin M. Thomas and Thoys 07/20/15. +// Copyright 2015 High Fidelity, Inc. +// kevintown.net +// +// JavaScript for the High Fidelity interface that is an entity script to be placed in a chosen entity inside a domain-zone. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + + +// Function which exists inside of an entity which triggers as a user approches it. +(function() { + const SCRIPT_NAME = "https://dl.dropboxusercontent.com/u/17344741/jsstreamplayer/jsstreamplayerdomain-zone.js"; + function isScriptRunning(script) { + script = script.toLowerCase().trim(); + var runningScripts = ScriptDiscoveryService.getRunning(); + for (i in runningScripts) { + if (runningScripts[i].url.toLowerCase().trim() == script) { + return true; + } + } + return false; + }; + + if (!isScriptRunning(SCRIPT_NAME)) { + Script.load(SCRIPT_NAME); + } +}) \ No newline at end of file diff --git a/examples/zones/jsstreamplayerdomain-zone.html b/examples/zones/jsstreamplayerdomain-zone.html new file mode 100644 index 0000000000..28b2202591 --- /dev/null +++ b/examples/zones/jsstreamplayerdomain-zone.html @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/zones/jsstreamplayerdomain-zone.js b/examples/zones/jsstreamplayerdomain-zone.js new file mode 100644 index 0000000000..33d7364709 --- /dev/null +++ b/examples/zones/jsstreamplayerdomain-zone.js @@ -0,0 +1,176 @@ +// +// #20628: JS Stream Player Domain-Zone +// ************************************* +// +// Created by Kevin M. Thomas, Thoys and Konstantin 07/24/15. +// Copyright 2015 High Fidelity, Inc. +// kevintown.net +// +// JavaScript for the High Fidelity interface that creates a stream player with a UI for playing a domain-zone specificed stream URL in addition to play, stop and volume functionality which is resident only in the domain-zone. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + + +// Declare variables and set up new WebWindow. +var lastZone = ""; +var volume = 0.5; +var stream = ""; +var streamWindow = new WebWindow('Stream', "https://dl.dropboxusercontent.com/u/17344741/jsstreamplayer/jsstreamplayerdomain-zone.html", 0, 0, false); +var visible = false; + +// Set up toggleStreamPlayButton overlay. +var toggleStreamPlayButton = Overlays.addOverlay("text", { + x: 122, + y: 310, + width: 38, + height: 28, + backgroundColor: { red: 0, green: 0, blue: 0}, + color: { red: 255, green: 255, blue: 0}, + font: {size: 15}, + topMargin: 8, + visible: false, + text: " Play" +}); + +// Set up toggleStreamStopButton overlay. +var toggleStreamStopButton = Overlays.addOverlay("text", { + x: 166, + y: 310, + width: 40, + height: 28, + backgroundColor: { red: 0, green: 0, blue: 0}, + color: { red: 255, green: 255, blue: 0}, + font: {size: 15}, + topMargin: 8, + visible: false, + text: " Stop" +}); + +// Set up increaseVolumeButton overlay. +var toggleIncreaseVolumeButton = Overlays.addOverlay("text", { + x: 211, + y: 310, + width: 18, + height: 28, + backgroundColor: { red: 0, green: 0, blue: 0}, + color: { red: 255, green: 255, blue: 0}, + font: {size: 15}, + topMargin: 8, + visible: false, + text: " +" +}); + +// Set up decreaseVolumeButton overlay. +var toggleDecreaseVolumeButton = Overlays.addOverlay("text", { + x: 234, + y: 310, + width: 15, + height: 28, + backgroundColor: { red: 0, green: 0, blue: 0}, + color: { red: 255, green: 255, blue: 0}, + font: {size: 15}, + topMargin: 8, + visible: false, + text: " -" +}); + +// Function to change JSON object stream. +function changeStream(stream) { + var streamJSON = { + action: "changeStream", + stream: stream + } + streamWindow.eventBridge.emitScriptEvent(JSON.stringify(streamJSON)); +} + +// Function to change JSON object volume. +function changeVolume(volume) { + var volumeJSON = { + action: "changeVolume", + volume: volume + } + streamWindow.eventBridge.emitScriptEvent(JSON.stringify(volumeJSON)); +} + +// Function that adds mousePressEvent functionality to connect UI to enter stream URL, play and stop stream. +function mousePressEvent(event) { + if (Overlays.getOverlayAtPoint({x: event.x, y: event.y}) == toggleStreamPlayButton) { + changeStream(stream); + volume = 0.25; + changeVolume(volume); + } + if (Overlays.getOverlayAtPoint({x: event.x, y: event.y}) == toggleStreamStopButton) { + changeStream(""); + } + if (Overlays.getOverlayAtPoint({x: event.x, y: event.y}) == toggleIncreaseVolumeButton) { + volume += 0.25; + changeVolume(volume); + } + if (Overlays.getOverlayAtPoint({x: event.x, y: event.y}) == toggleDecreaseVolumeButton) { + volume -= 0.25; + changeVolume(volume); + } +} + +// Function checking bool if in proper zone. +function isOurZone(properties) { + return stream != "" && properties.type == "Zone"; +} + +// Function to toggle visibile the overlay. +function toggleVisible(newVisibility) { + if (newVisibility != visible) { + visible = newVisibility; + Overlays.editOverlay(toggleStreamPlayButton, {visible: visible}); + Overlays.editOverlay(toggleStreamStopButton, {visible: visible}); + Overlays.editOverlay(toggleIncreaseVolumeButton, {visible: visible}); + Overlays.editOverlay(toggleDecreaseVolumeButton, {visible: visible}); + } +} + +// Function to check if avatar is in proper domain. +Window.domainChanged.connect(function() { + Script.stop(); +}); + +// Function to check if avatar is within zone. +Entities.enterEntity.connect(function(entityID) { + print("Entered..." + JSON.stringify(entityID)); + var properties = Entities.getEntityProperties(entityID); + stream = properties.userData; + if(isOurZone(properties)) + { + lastZone = properties.name; + toggleVisible(true); + } +}) + +// Function to check if avatar is leaving zone. +Entities.leaveEntity.connect(function(entityID) { + print("Left..." + JSON.stringify(entityID)); + var properties = Entities.getEntityProperties(entityID); + if (properties.name == lastZone && properties.type == "Zone") { + print("Leaving Zone!"); + toggleVisible(false); + changeStream(""); + } +}) + +// Function to delete overlays upon exit. +function onScriptEnding() { + Overlays.deleteOverlay(toggleStreamPlayButton); + Overlays.deleteOverlay(toggleStreamStopButton); + Overlays.deleteOverlay(toggleIncreaseVolumeButton); + Overlays.deleteOverlay(toggleDecreaseVolumeButton); + changeStream(""); + streamWindow.deleteLater(); +} + +// Connect mouse and hide WebWindow. +Controller.mousePressEvent.connect(mousePressEvent); +streamWindow.setVisible(false); + +// Call function upon ending script. +Script.scriptEnding.connect(onScriptEnding); \ No newline at end of file