mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-05-28 22:29:54 +02:00
simplify notifications.js after chat removal
This commit is contained in:
parent
cf227b94de
commit
03de43d451
1 changed files with 18 additions and 83 deletions
|
@ -14,32 +14,28 @@
|
||||||
// This script generates notifications created via a number of ways, such as:
|
// This script generates notifications created via a number of ways, such as:
|
||||||
// keystroke:
|
// keystroke:
|
||||||
//
|
//
|
||||||
// "q" returns number of users currently online (for debug purposes)
|
|
||||||
|
|
||||||
// CTRL/s for snapshot.
|
// CTRL/s for snapshot.
|
||||||
// CTRL/m for mic mute and unmute.
|
// CTRL/m for mic mute and unmute.
|
||||||
|
|
||||||
// System generated notifications:
|
// System generated notifications:
|
||||||
// Displays users online at startup.
|
|
||||||
// If Screen is resized.
|
// If Screen is resized.
|
||||||
// Triggers notification if @MyUserName is mentioned in chat.
|
|
||||||
// Announces existing user logging out.
|
|
||||||
// Announces new user logging in.
|
|
||||||
// If mic is muted for any reason.
|
// If mic is muted for any reason.
|
||||||
//
|
//
|
||||||
// To add a new System notification type:
|
// To add a new System notification type:
|
||||||
//
|
//
|
||||||
// 1. Set the Event Connector at the bottom of the script.
|
// 1. Set the Event Connector at the bottom of the script.
|
||||||
// example:
|
// example:
|
||||||
// GlobalServices.incomingMessage.connect(onIncomingMessage);
|
// AudioDevice.muteToggled.connect(onMuteStateChanged);
|
||||||
//
|
//
|
||||||
// 2. Create a new function to produce a text string, do not include new line returns.
|
// 2. Create a new function to produce a text string, do not include new line returns.
|
||||||
// example:
|
// example:
|
||||||
// function onIncomingMessage(user, message) {
|
// function onMuteStateChanged() {
|
||||||
// //do stuff here;
|
// var muteState,
|
||||||
// var text = "This is a notification";
|
// muteString;
|
||||||
// var wrappedText = wordWrap(text);
|
//
|
||||||
// createNotification(wrappedText, NotificationType.SNAPSHOT);
|
// muteState = AudioDevice.getMuted() ? "muted" : "unmuted";
|
||||||
|
// muteString = "Microphone is now " + muteState;
|
||||||
|
// createNotification(muteString, NotificationType.MUTE_TOGGLE);
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// This new function must call wordWrap(text) if the length of message is longer than 42 chars or unknown.
|
// This new function must call wordWrap(text) if the length of message is longer than 42 chars or unknown.
|
||||||
|
@ -54,11 +50,12 @@
|
||||||
// 2. Declare a text string.
|
// 2. Declare a text string.
|
||||||
// 3. Call createNotifications(text, NotificationType) parsing the text.
|
// 3. Call createNotifications(text, NotificationType) parsing the text.
|
||||||
// example:
|
// example:
|
||||||
// var welcome;
|
// if (key.text === "s") {
|
||||||
// if (key.text == "q") { //queries number of users online
|
// if (ctrlIsPressed === true) {
|
||||||
// var welcome = "There are " + GlobalServices.onlineUsers.length + " users online now.";
|
// noteString = "Snapshot taken.";
|
||||||
// createNotification(welcome, NotificationType.USERS_ONLINE);
|
// createNotification(noteString, NotificationType.SNAPSHOT);
|
||||||
// }
|
// }
|
||||||
|
// }
|
||||||
Script.include("./libraries/globals.js");
|
Script.include("./libraries/globals.js");
|
||||||
Script.include("./libraries/soundArray.js");
|
Script.include("./libraries/soundArray.js");
|
||||||
|
|
||||||
|
@ -81,8 +78,6 @@ var frame = 0;
|
||||||
var ourWidth = Window.innerWidth;
|
var ourWidth = Window.innerWidth;
|
||||||
var ourHeight = Window.innerHeight;
|
var ourHeight = Window.innerHeight;
|
||||||
var text = "placeholder";
|
var text = "placeholder";
|
||||||
var last_users = GlobalServices.onlineUsers;
|
|
||||||
var users = [];
|
|
||||||
var ctrlIsPressed = false;
|
var ctrlIsPressed = false;
|
||||||
var ready = true;
|
var ready = true;
|
||||||
var MENU_NAME = 'Tools > Notifications';
|
var MENU_NAME = 'Tools > Notifications';
|
||||||
|
@ -93,19 +88,11 @@ var PLAY_NOTIFICATION_SOUNDS_TYPE_SETTING_PRE = "play_notification_sounds_type_"
|
||||||
|
|
||||||
var NotificationType = {
|
var NotificationType = {
|
||||||
UNKNOWN: 0,
|
UNKNOWN: 0,
|
||||||
USER_JOINS: 1,
|
MUTE_TOGGLE: 1,
|
||||||
USER_LEAVES: 2,
|
SNAPSHOT: 2,
|
||||||
MUTE_TOGGLE: 3,
|
WINDOW_RESIZE: 3,
|
||||||
CHAT_MENTION: 4,
|
|
||||||
USERS_ONLINE: 5,
|
|
||||||
SNAPSHOT: 6,
|
|
||||||
WINDOW_RESIZE: 7,
|
|
||||||
properties: [
|
properties: [
|
||||||
{ text: "User Join" },
|
|
||||||
{ text: "User Leave" },
|
|
||||||
{ text: "Mute Toggle" },
|
{ text: "Mute Toggle" },
|
||||||
{ text: "Chat Mention" },
|
|
||||||
{ text: "Users Online" },
|
|
||||||
{ text: "Snapshot" },
|
{ text: "Snapshot" },
|
||||||
{ text: "Window Resize" }
|
{ text: "Window Resize" }
|
||||||
],
|
],
|
||||||
|
@ -476,15 +463,9 @@ var STARTUP_TIMEOUT = 500, // ms
|
||||||
startingUp = true,
|
startingUp = true,
|
||||||
startupTimer = null;
|
startupTimer = null;
|
||||||
|
|
||||||
// This reports the number of users online at startup
|
|
||||||
function reportUsers() {
|
|
||||||
createNotification("Welcome! There are " + GlobalServices.onlineUsers.length + " users online now.", NotificationType.USERS_ONLINE);
|
|
||||||
}
|
|
||||||
|
|
||||||
function finishStartup() {
|
function finishStartup() {
|
||||||
startingUp = false;
|
startingUp = false;
|
||||||
Script.clearTimeout(startupTimer);
|
Script.clearTimeout(startupTimer);
|
||||||
reportUsers();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function isStartingUp() {
|
function isStartingUp() {
|
||||||
|
@ -498,42 +479,6 @@ function isStartingUp() {
|
||||||
return startingUp;
|
return startingUp;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Triggers notification if a user logs on or off
|
|
||||||
function onOnlineUsersChanged(users) {
|
|
||||||
var i;
|
|
||||||
|
|
||||||
if (!isStartingUp()) { // Skip user notifications at startup.
|
|
||||||
for (i = 0; i < users.length; i += 1) {
|
|
||||||
if (last_users.indexOf(users[i]) === -1.0) {
|
|
||||||
createNotification(users[i] + " has joined", NotificationType.USER_JOINS);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < last_users.length; i += 1) {
|
|
||||||
if (users.indexOf(last_users[i]) === -1.0) {
|
|
||||||
createNotification(last_users[i] + " has left", NotificationType.USER_LEAVES);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
last_users = users;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Triggers notification if @MyUserName is mentioned in chat and returns the message to the notification.
|
|
||||||
function onIncomingMessage(user, message) {
|
|
||||||
var myMessage,
|
|
||||||
alertMe,
|
|
||||||
thisAlert;
|
|
||||||
|
|
||||||
myMessage = message;
|
|
||||||
alertMe = "@" + GlobalServices.myUsername;
|
|
||||||
thisAlert = user + ": " + myMessage;
|
|
||||||
|
|
||||||
if (myMessage.indexOf(alertMe) > -1.0) {
|
|
||||||
CreateNotification(wordWrap(thisAlert), NotificationType.CHAT_MENTION);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Triggers mic mute notification
|
// Triggers mic mute notification
|
||||||
function onMuteStateChanged() {
|
function onMuteStateChanged() {
|
||||||
var muteState,
|
var muteState,
|
||||||
|
@ -573,20 +518,12 @@ function keyReleaseEvent(key) {
|
||||||
|
|
||||||
// Triggers notification on specific key driven events
|
// Triggers notification on specific key driven events
|
||||||
function keyPressEvent(key) {
|
function keyPressEvent(key) {
|
||||||
var numUsers,
|
var noteString;
|
||||||
welcome,
|
|
||||||
noteString;
|
|
||||||
|
|
||||||
if (key.key === 16777249) {
|
if (key.key === 16777249) {
|
||||||
ctrlIsPressed = true;
|
ctrlIsPressed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key.text === "q") { //queries number of users online
|
|
||||||
numUsers = GlobalServices.onlineUsers.length;
|
|
||||||
welcome = "There are " + numUsers + " users online now.";
|
|
||||||
createNotification(welcome, NotificationType.USERS_ONLINE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (key.text === "s") {
|
if (key.text === "s") {
|
||||||
if (ctrlIsPressed === true) {
|
if (ctrlIsPressed === true) {
|
||||||
noteString = "Snapshot taken.";
|
noteString = "Snapshot taken.";
|
||||||
|
@ -641,8 +578,6 @@ function menuItemEvent(menuItem) {
|
||||||
AudioDevice.muteToggled.connect(onMuteStateChanged);
|
AudioDevice.muteToggled.connect(onMuteStateChanged);
|
||||||
Controller.keyPressEvent.connect(keyPressEvent);
|
Controller.keyPressEvent.connect(keyPressEvent);
|
||||||
Controller.mousePressEvent.connect(mousePressEvent);
|
Controller.mousePressEvent.connect(mousePressEvent);
|
||||||
GlobalServices.onlineUsersChanged.connect(onOnlineUsersChanged);
|
|
||||||
GlobalServices.incomingMessage.connect(onIncomingMessage);
|
|
||||||
Controller.keyReleaseEvent.connect(keyReleaseEvent);
|
Controller.keyReleaseEvent.connect(keyReleaseEvent);
|
||||||
Script.update.connect(update);
|
Script.update.connect(update);
|
||||||
Script.scriptEnding.connect(scriptEnding);
|
Script.scriptEnding.connect(scriptEnding);
|
||||||
|
|
Loading…
Reference in a new issue