mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 04:48:09 +02:00
add a receiver example
This commit is contained in:
parent
2d3fe497e4
commit
2f142eb088
2 changed files with 23 additions and 4 deletions
22
examples/example/messagesReceiverExample.js
Normal file
22
examples/example/messagesReceiverExample.js
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
var totalTime = 0;
|
||||||
|
var subscribed = false;
|
||||||
|
var WAIT_FOR_SUBSCRIPTION_TIME = 10;
|
||||||
|
function myUpdate(deltaTime) {
|
||||||
|
var channel = "example";
|
||||||
|
totalTime += deltaTime;
|
||||||
|
|
||||||
|
if (totalTime > WAIT_FOR_SUBSCRIPTION_TIME && !subscribed) {
|
||||||
|
|
||||||
|
print("---- subscribing ----");
|
||||||
|
Messages.subscribe(channel);
|
||||||
|
subscribed = true;
|
||||||
|
Script.update.disconnect(myUpdate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Script.update.connect(myUpdate);
|
||||||
|
|
||||||
|
Messages.messageReceived.connect(function (channel, message) {
|
||||||
|
print("message received on channel:" + channel + ", message:" + message);
|
||||||
|
});
|
||||||
|
|
|
@ -367,6 +367,7 @@ void ScriptEngine::init() {
|
||||||
registerGlobalObject("Vec3", &_vec3Library);
|
registerGlobalObject("Vec3", &_vec3Library);
|
||||||
registerGlobalObject("Uuid", &_uuidLibrary);
|
registerGlobalObject("Uuid", &_uuidLibrary);
|
||||||
registerGlobalObject("AnimationCache", DependencyManager::get<AnimationCache>().data());
|
registerGlobalObject("AnimationCache", DependencyManager::get<AnimationCache>().data());
|
||||||
|
registerGlobalObject("Messages", DependencyManager::get<MessagesClient>().data());
|
||||||
qScriptRegisterMetaType(this, animVarMapToScriptValue, animVarMapFromScriptValue);
|
qScriptRegisterMetaType(this, animVarMapToScriptValue, animVarMapFromScriptValue);
|
||||||
qScriptRegisterMetaType(this, resultHandlerToScriptValue, resultHandlerFromScriptValue);
|
qScriptRegisterMetaType(this, resultHandlerToScriptValue, resultHandlerFromScriptValue);
|
||||||
|
|
||||||
|
@ -376,10 +377,6 @@ void ScriptEngine::init() {
|
||||||
auto scriptingInterface = DependencyManager::get<controller::ScriptingInterface>();
|
auto scriptingInterface = DependencyManager::get<controller::ScriptingInterface>();
|
||||||
registerGlobalObject("Controller", scriptingInterface.data());
|
registerGlobalObject("Controller", scriptingInterface.data());
|
||||||
UserInputMapper::registerControllerTypes(this);
|
UserInputMapper::registerControllerTypes(this);
|
||||||
|
|
||||||
|
|
||||||
registerGlobalObject("Messages", DependencyManager::get<MessagesClient>().data());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptEngine::registerValue(const QString& valueName, QScriptValue value) {
|
void ScriptEngine::registerValue(const QString& valueName, QScriptValue value) {
|
||||||
|
|
Loading…
Reference in a new issue