overte/examples/tests/testBaton.js
Howard Stearns 287d91d4b2 better
2016-02-03 20:57:35 -08:00

35 lines
1.1 KiB
JavaScript

"use strict";
/*jslint nomen: true, plusplus: true, vars: true*/
var Vec3, Quat, MyAvatar, Entities, Camera, Script, print;
//
// Created by Howard Stearns
// Copyright 2016 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
// test libraries/virtualBaton.js
// All participants should run the test script.
Script.include("../libraries/virtualBaton.31.js");
var TICKER_INTERVAL = 1000; // ms
var baton = virtualBaton({key: 'io.highfidelity.testBaton', debugSend: true, debugFlow: true, debugReceive: true});
var ticker, countDown;
// Tick every TICKER_INTERVAL.
function gotBaton(key) {
print("gotBaton", key);
countDown = 20;
ticker = Script.setInterval(function () {
print("tick");
}, 1000);
}
// If we've lost the baton (e.g., to network problems), stop ticking
// but ask for the baton back (waiting indefinitely to get it).
function lostBaton(key) {
print("lostBaton", key);
Script.clearInterval(ticker);
baton.claim(gotBaton, lostBaton);
}
baton.claim(gotBaton, lostBaton);