2013-05-31 23:13:03 +08:00
|
|
|
//
|
|
|
|
// WebSocketTest.h
|
|
|
|
// TestCpp
|
|
|
|
//
|
|
|
|
// Created by James Chen on 5/31/13.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef __TestCpp__WebSocketTest__
|
|
|
|
#define __TestCpp__WebSocketTest__
|
|
|
|
|
|
|
|
#include "cocos2d.h"
|
2013-10-16 16:48:39 +08:00
|
|
|
#include "extensions/cocos-ext.h"
|
|
|
|
#include "network/WebSocket.h"
|
2013-05-31 23:13:03 +08:00
|
|
|
|
|
|
|
class WebSocketTestLayer
|
2013-06-20 14:17:10 +08:00
|
|
|
: public cocos2d::Layer
|
2013-10-15 18:00:03 +08:00
|
|
|
, public network::WebSocket::Delegate
|
2013-05-31 23:13:03 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
WebSocketTestLayer();
|
|
|
|
virtual ~WebSocketTestLayer();
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
virtual void onOpen(network::WebSocket* ws);
|
|
|
|
virtual void onMessage(network::WebSocket* ws, const network::WebSocket::Data& data);
|
|
|
|
virtual void onClose(network::WebSocket* ws);
|
|
|
|
virtual void onError(network::WebSocket* ws, const network::WebSocket::ErrorCode& error);
|
2013-05-31 23:13:03 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void toExtensionsMainLayer(cocos2d::Object *sender);
|
2013-05-31 23:13:03 +08:00
|
|
|
|
|
|
|
// Menu Callbacks
|
2013-06-20 14:17:10 +08:00
|
|
|
void onMenuSendTextClicked(cocos2d::Object *sender);
|
|
|
|
void onMenuSendBinaryClicked(cocos2d::Object *sender);
|
2013-05-31 23:13:03 +08:00
|
|
|
|
|
|
|
private:
|
2013-10-15 18:00:03 +08:00
|
|
|
network::WebSocket* _wsiSendText;
|
|
|
|
network::WebSocket* _wsiSendBinary;
|
|
|
|
network::WebSocket* _wsiError;
|
2013-05-31 23:13:03 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
cocos2d::LabelTTF* _sendTextStatus;
|
|
|
|
cocos2d::LabelTTF* _sendBinaryStatus;
|
|
|
|
cocos2d::LabelTTF* _errorStatus;
|
2013-05-31 23:13:03 +08:00
|
|
|
|
|
|
|
int _sendTextTimes;
|
|
|
|
int _sendBinaryTimes;
|
|
|
|
};
|
|
|
|
|
|
|
|
void runWebSocketTest();
|
|
|
|
|
|
|
|
#endif /* defined(__TestCpp__WebSocketTest__) */
|