forked from RbxStu/RbxStu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Communication.cpp
30 lines (25 loc) · 893 Bytes
/
Communication.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//
// Created by Dottik on 21/4/2024.
//
#include "Communication.hpp"
#include "Environment/FilesystemLibrary.hpp"
void Communication::handshake() {
char buf[0x9] = "00000000";
buf[0x1] = Communication::OpCodes::GetWorkspace;
const auto sendData = ix::IXWebSocketSendData{buf, 1};
this->m_pWebsocket->sendBinary(sendData);
this->m_pWebsocket->setOnMessageCallback([](const ix::WebSocketMessagePtr &message) {
if (message->type == ix::WebSocketMessageType::Message) {
auto workspace = message->str;
FilesystemLibrary::get_singleton()->set_workspace_path(workspace);
}
});
}
Communication::Communication(const std::string &websocketUrl) {
this->m_pWebsocket = new ix::WebSocket{};
this->m_pWebsocket->setUrl(websocketUrl);
}
void Communication::connect() {
this->m_pWebsocket->connect(5);
this->handshake();
}