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
|
2014-01-02 16:25:35 +08:00
|
|
|
, public cocos2d::network::WebSocket::Delegate
|
2013-05-31 23:13:03 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
WebSocketTestLayer();
|
|
|
|
virtual ~WebSocketTestLayer();
|
|
|
|
|
2014-01-02 16:25:35 +08:00
|
|
|
virtual void onOpen(cocos2d::network::WebSocket* ws);
|
|
|
|
virtual void onMessage(cocos2d::network::WebSocket* ws, const cocos2d::network::WebSocket::Data& data);
|
|
|
|
virtual void onClose(cocos2d::network::WebSocket* ws);
|
|
|
|
virtual void onError(cocos2d::network::WebSocket* ws, const cocos2d::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:
|
2014-01-02 16:25:35 +08:00
|
|
|
cocos2d::network::WebSocket* _wsiSendText;
|
|
|
|
cocos2d::network::WebSocket* _wsiSendBinary;
|
|
|
|
cocos2d::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__) */
|