26#include "../ExtensionsTest.h"
32#define SEND_TEXT_TIMES 100
35: _wsiSendText(nullptr)
36, _sendTextStatus(nullptr)
37, _progressStatus(nullptr)
40 auto winSize = Director::getInstance()->getWinSize();
42 const int MARGIN = 40;
45 auto menuRequest = Menu::create();
46 menuRequest->setPosition(Vec2::ZERO);
47 addChild(menuRequest);
50 char cmdLabel[60] = { 0 };
52 auto labelSendText = Label::createWithTTF(cmdLabel,
"fonts/arial.ttf", 20);
54 itemSendText->setPosition(Vec2(winSize.width / 2, winSize.height - MARGIN - SPACE));
55 menuRequest->addChild(itemSendText);
58 _sendTextStatus = Label::createWithTTF(
"Waiting connection...",
"fonts/arial.ttf", 16, Size(160, 100), TextHAlignment::CENTER, TextVAlignment::TOP);
65 _progressStatus = Label::createWithTTF(
".",
"fonts/arial.ttf", 16, Size(160, 100), TextHAlignment::CENTER, TextVAlignment::TOP);
70 auto startTestLabel = Label::createWithTTF(
"DO Connect!",
"fonts/arial.ttf", 16);
100 std::vector<std::string> protocols;
101 protocols.push_back(
"myprotocol_1");
102 protocols.push_back(
"myprotocol_2");
103 if (!
_wsiSendText->init(*
this,
"wss://echo.websocket.org", &protocols,
"cacert.pem"))
124 char statueBuffer[80] = { 0 };
128 _wsiSendText->send(
"Hello WebSocket, I'm a text message.");
142 char status[256] = {0};
143 sprintf(status,
"Opened, url: %s, protocol: %s", ws->getUrl().c_str(), ws->getProtocol().c_str());
145 log(
"Websocket (%p) was opened, url: %s, protocol: %s", ws, ws->getUrl().c_str(), ws->getProtocol().c_str());
158 char times[100] = {0};
160 std::string textStr = std::string(
"response text msg: ")+data.bytes+
", "+times;
161 log(
"%s", textStr.c_str());
163 memset(times, 0, 100);
171 log(
"onClose: websocket instance (%p) closed.", ws);
179 log(
"WebSocketDelayTest ref: %u", _referenceCount);
185 log(
"Error was fired, error code: %d",
static_cast<int>(error));
187 sprintf(buf,
"An error was fired, code: %d",
static_cast<int>(error));
205 if (
_wsiSendText->getReadyState() == network::WebSocket::State::OPEN)
214 std::string warningStr =
"send text websocket instance wasn't ready...";
215 log(
"%s", warningStr.c_str());
static cocos2d::Vec2 center()
static cocos2d::Vec2 bottom()
static cocos2d::Vec2 left()
static cocos2d::Vec2 rightBottom()
cocos2d::Menu * _startTestMenu
virtual void onOpen(cocos2d::network::WebSocket *ws) override
virtual void onClose(cocos2d::network::WebSocket *ws) override
virtual ~WebSocketDelayTest()
cocos2d::Label * _progressStatus
virtual void onExit() override
int64_t _sendTimeMircoSec
cocos2d::Label * _sendTextStatus
int64_t getNowMircroSeconds()
int64_t _receiveTimeMircoSec
cocos2d::network::WebSocket * _wsiSendText
int64_t _totalDelayMircoSec
virtual void onMessage(cocos2d::network::WebSocket *ws, const cocos2d::network::WebSocket::Data &data) override
void onMenuSendTextClicked(cocos2d::Ref *sender)
void startTestCallback(cocos2d::Ref *sender)
virtual void onError(cocos2d::network::WebSocket *ws, const cocos2d::network::WebSocket::ErrorCode &error) override