mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-04-13 10:32:16 +02:00
Move WebSocketServer to be accessable from Assignment-Client:Agent only.
This commit is contained in:
parent
d3a6833133
commit
d89ecc1e42
3 changed files with 42 additions and 39 deletions
|
@ -24,6 +24,7 @@
|
|||
#include <SoundCache.h>
|
||||
#include <UUID.h>
|
||||
|
||||
#include <WebSocketServerClass.h>
|
||||
#include <EntityScriptingInterface.h> // TODO: consider moving to scriptengine.h
|
||||
|
||||
#include "avatars/ScriptableAvatar.h"
|
||||
|
@ -184,6 +185,9 @@ void Agent::run() {
|
|||
|
||||
_scriptEngine.registerGlobalObject("SoundCache", DependencyManager::get<SoundCache>().data());
|
||||
|
||||
QScriptValue webSocketServerConstructorValue = _scriptEngine.newFunction(WebSocketServerClass::constructor);
|
||||
_scriptEngine.globalObject().setProperty("WebSocketServer", webSocketServerConstructorValue);
|
||||
|
||||
auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
|
||||
|
||||
_scriptEngine.registerGlobalObject("EntityViewer", &_entityViewer);
|
||||
|
|
|
@ -61,40 +61,43 @@ unitTests.addTest("Test WebSocket invalid URL", function(finished) {
|
|||
this.assertEquals(WEBSOCKET_INVALID_URL, webSocket.url, "url should be '" + WEBSOCKET_INVALID_URL + "'");
|
||||
}, UNITTEST_TIMEOUT);
|
||||
|
||||
|
||||
unitTests.addTest("Test WebSocketServer with three clients", function(finished) {
|
||||
var _this = this;
|
||||
const NUMBER_OF_CLIENTS = 3;
|
||||
var connectedClients = 0;
|
||||
var respondedClients = 0;
|
||||
var webSocketServer = new WebSocketServer();
|
||||
_this.assertEquals(true, webSocketServer.listening, "listening should be true");
|
||||
webSocketServer.newConnection.connect(this.registerCallbackFunction(function(newClient) {
|
||||
connectedClients++;
|
||||
newClient.onmessage = _this.registerCallbackFunction(function(event) {
|
||||
var data = JSON.parse(event.data);
|
||||
_this.assertEquals(TEST_MESSAGE, data.message, "data.message should be '" + TEST_MESSAGE + "'");
|
||||
respondedClients++;
|
||||
if (respondedClients === NUMBER_OF_CLIENTS) {
|
||||
webSocketServer.close();
|
||||
_this.assertEquals(false, webSocketServer.listening, "listening should be false");
|
||||
_this.done();
|
||||
}
|
||||
});
|
||||
newClient.send(JSON.stringify({message: TEST_MESSAGE, client: connectedClients}));
|
||||
}));
|
||||
var newSocket1 = new WebSocket(webSocketServer.url);
|
||||
newSocket1.onmessage = this.registerCallbackFunction(function(event) {
|
||||
newSocket1.send(event.data);
|
||||
});
|
||||
var newSocket2 = new WebSocket(webSocketServer.url);
|
||||
newSocket2.onmessage = this.registerCallbackFunction(function(event) {
|
||||
newSocket2.send(event.data);
|
||||
});
|
||||
var newSocket3 = new WebSocket(webSocketServer.url);
|
||||
newSocket3.onmessage = this.registerCallbackFunction(function(event) {
|
||||
newSocket3.send(event.data);
|
||||
});
|
||||
}, UNITTEST_TIMEOUT);
|
||||
if (this.WebSocketServer === undefined) {
|
||||
print("Skipping WebSocketServer tests.");
|
||||
} else {
|
||||
unitTests.addTest("Test WebSocketServer with three clients", function(finished) {
|
||||
var _this = this;
|
||||
const NUMBER_OF_CLIENTS = 3;
|
||||
var connectedClients = 0;
|
||||
var respondedClients = 0;
|
||||
var webSocketServer = new WebSocketServer();
|
||||
_this.assertEquals(true, webSocketServer.listening, "listening should be true");
|
||||
webSocketServer.newConnection.connect(this.registerCallbackFunction(function(newClient) {
|
||||
connectedClients++;
|
||||
newClient.onmessage = _this.registerCallbackFunction(function(event) {
|
||||
var data = JSON.parse(event.data);
|
||||
_this.assertEquals(TEST_MESSAGE, data.message, "data.message should be '" + TEST_MESSAGE + "'");
|
||||
respondedClients++;
|
||||
if (respondedClients === NUMBER_OF_CLIENTS) {
|
||||
webSocketServer.close();
|
||||
_this.assertEquals(false, webSocketServer.listening, "listening should be false");
|
||||
_this.done();
|
||||
}
|
||||
});
|
||||
newClient.send(JSON.stringify({message: TEST_MESSAGE, client: connectedClients}));
|
||||
}));
|
||||
var newSocket1 = new WebSocket(webSocketServer.url);
|
||||
newSocket1.onmessage = this.registerCallbackFunction(function(event) {
|
||||
newSocket1.send(event.data);
|
||||
});
|
||||
var newSocket2 = new WebSocket(webSocketServer.url);
|
||||
newSocket2.onmessage = this.registerCallbackFunction(function(event) {
|
||||
newSocket2.send(event.data);
|
||||
});
|
||||
var newSocket3 = new WebSocket(webSocketServer.url);
|
||||
newSocket3.onmessage = this.registerCallbackFunction(function(event) {
|
||||
newSocket3.send(event.data);
|
||||
});
|
||||
}, UNITTEST_TIMEOUT);
|
||||
}
|
||||
|
||||
unitTests.run();
|
||||
|
|
|
@ -39,7 +39,6 @@
|
|||
#include "TypedArrays.h"
|
||||
#include "XMLHttpRequestClass.h"
|
||||
#include "WebSocketClass.h"
|
||||
#include "WebSocketServerClass.h"
|
||||
|
||||
#include "SceneScriptingInterface.h"
|
||||
|
||||
|
@ -348,9 +347,6 @@ void ScriptEngine::init() {
|
|||
QScriptValue webSocketConstructorValue = newFunction(WebSocketClass::constructor);
|
||||
globalObject().setProperty("WebSocket", webSocketConstructorValue);
|
||||
|
||||
QScriptValue webSocketServerConstructorValue = newFunction(WebSocketServerClass::constructor);
|
||||
globalObject().setProperty("WebSocketServer", webSocketServerConstructorValue);
|
||||
|
||||
QScriptValue printConstructorValue = newFunction(debugPrint);
|
||||
globalObject().setProperty("print", printConstructorValue);
|
||||
|
||||
|
|
Loading…
Reference in a new issue