Working on running the game even in Telegram
This commit is contained in:
1 parent
5fcb1d1234
commit
e78429b600
9 files changed
+133
-60
No files matched your search
@@ -7,8 +7,8 @@
|
||||
namespace ZL {
|
||||
void WebSocketClientEmscripten::Connect(const std::string& host, uint16_t port) {
|
||||
// Формируем URL. Обратите внимание, что в Web часто лучше использовать ws://localhost
|
||||
std::string url = "ws://" + host + ":" + std::to_string(port);
|
||||
//std::string url = "wss://api.spacegame.fishrungames.com";
|
||||
//std::string url = "ws://" + host + ":" + std::to_string(port);
|
||||
std::string url = "wss://api.spacegame.fishrungames.com";
|
||||
|
||||
EmscriptenWebSocketCreateAttributes attr = {
|
||||
url.c_str(),
|
||||
@@ -36,11 +36,8 @@ namespace ZL {
|
||||
// Локальная очередь для минимизации времени блокировки мьютекса
|
||||
std::queue<std::string> localQueue;
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(queueMutex);
|
||||
if (messageQueue.empty()) return;
|
||||
std::swap(localQueue, messageQueue);
|
||||
}
|
||||
if (messageQueue.empty()) return;
|
||||
std::swap(localQueue, messageQueue);
|
||||
|
||||
while (!localQueue.empty()) {
|
||||
const std::string& msg = localQueue.front();
|
||||
@@ -67,7 +64,6 @@ namespace ZL {
|
||||
auto* self = static_cast<WebSocketClientEmscripten*>(userData);
|
||||
if (e->isText && e->data) {
|
||||
std::string msg(reinterpret_cast<const char*>(e->data), e->numBytes);
|
||||
std::lock_guard<std::mutex> lock(self->queueMutex);
|
||||
self->messageQueue.push(msg);
|
||||
}
|
||||
return EM_TRUE;
|
||||
|
||||
@@ -18,7 +18,6 @@ namespace ZL {
|
||||
|
||||
// Очередь для хранения сырых строк от браузера
|
||||
std::queue<std::string> messageQueue;
|
||||
std::mutex queueMutex;
|
||||
|
||||
public:
|
||||
WebSocketClientEmscripten() = default;
|
||||
|
||||
Reference in new issue
Block a user