feat: Модифицирована Squirrel сторона под новый формат сообщений
This commit is contained in:
@@ -10,14 +10,12 @@ class PyG2O
|
||||
_max_reconnect_attempts = 0;
|
||||
|
||||
_constantsInitialized = false;
|
||||
_messageHandlers = null;
|
||||
|
||||
constructor(url, silent = false, max_reconnect_attempts = 0)
|
||||
{
|
||||
_url = url;
|
||||
_max_reconnect_attempts = max_reconnect_attempts;
|
||||
_silent = silent;
|
||||
_messageHandlers = {};
|
||||
|
||||
_connection = WebsocketClient();
|
||||
_connection.silent = _silent;
|
||||
@@ -27,8 +25,6 @@ class PyG2O
|
||||
_connection.onClose = _onClose.bindenv(this);
|
||||
_connection.onMessage = _onMessage.bindenv(this);
|
||||
|
||||
_registerMessage("call", _message_call.bindenv(this));
|
||||
|
||||
if (_globalInstance == -1)
|
||||
_globalInstance = this;
|
||||
}
|
||||
@@ -47,28 +43,11 @@ class PyG2O
|
||||
print("[PyG2O] Stopped connection");
|
||||
}
|
||||
|
||||
function _registerMessage(type, handler)
|
||||
{
|
||||
if (type in _messageHandlers)
|
||||
return;
|
||||
|
||||
_messageHandlers[type] <- handler;
|
||||
}
|
||||
|
||||
function _callMessage(type, data)
|
||||
{
|
||||
if(!(type in _messageHandlers))
|
||||
return;
|
||||
|
||||
_messageHandlers[type](data);
|
||||
}
|
||||
|
||||
function _send(type, data, uuid = "none")
|
||||
{
|
||||
local sendData = {
|
||||
"type": type,
|
||||
"data": data,
|
||||
"uuid": uuid
|
||||
"uuid": uuid,
|
||||
"data": data
|
||||
}
|
||||
|
||||
_connection.send(JSON.dump_ansi(sendData, 2));
|
||||
@@ -147,11 +126,10 @@ class PyG2O
|
||||
function _onMessage(url, message)
|
||||
{
|
||||
local request = JSON.parse_ansi(message);
|
||||
if (!("type" in request) ||
|
||||
!("uuid" in request) ||
|
||||
if (!("uuid" in request) ||
|
||||
!("data" in request))
|
||||
return;
|
||||
|
||||
_callMessage(request["type"], request);
|
||||
_message_call.bindenv(this)(request["data"]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user