mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 11:17:34 +02:00
globalServicesExample.js
This commit is contained in:
parent
807173ae0a
commit
e62380a171
1 changed files with 57 additions and 0 deletions
57
examples/globalServicesExample.js
Normal file
57
examples/globalServicesExample.js
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
//
|
||||||
|
// globalServicesExample.js
|
||||||
|
// examples
|
||||||
|
//
|
||||||
|
// Created by Thijs Wenker on 9/12/14.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Example usage of the GlobalServices object. You could use it to make your own chatbox.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
function onConnected() {
|
||||||
|
if (GlobalServices.onlineUsers.length > 0) {
|
||||||
|
sendMessageForm()
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Script.setTimeout(function() { sendMessageForm(); }, 5000);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onDisconnected(reason) {
|
||||||
|
switch(reason) {
|
||||||
|
case "logout":
|
||||||
|
Window.alert("logged out!");
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onOnlineUsersChanged(users) {
|
||||||
|
print(users);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onIncommingMessage(user, message) {
|
||||||
|
print(user + ": " + message);
|
||||||
|
if (message === "hello") {
|
||||||
|
GlobalServices.chat("hello, @" + user + "!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendMessageForm() {
|
||||||
|
var form =
|
||||||
|
[
|
||||||
|
{ label: "To:", options: ["(noone)"].concat(GlobalServices.onlineUsers) },
|
||||||
|
{ label: "Message:", value: "Enter message here" }
|
||||||
|
];
|
||||||
|
if (Window.form("Send message on public chat", form)) {
|
||||||
|
GlobalServices.chat(form[0].value == "(noone)" ? form[1].value : "@" + form[0].value + ", " + form[1].value);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GlobalServices.connected.connect(onConnected);
|
||||||
|
GlobalServices.disconnected.connect(onDisconnected);
|
||||||
|
GlobalServices.onlineUsersChanged.connect(onOnlineUsersChanged);
|
||||||
|
GlobalServices.incomingMessage.connect(onIncommingMessage);
|
Loading…
Reference in a new issue