PuzzleSDK
SocketIOTest.h
浏览该文件的文档.
1/****************************************************************************
2 Copyright (c) 2015 Chris Hannon http://www.channon.us
3 Copyright (c) 2013-2016 Chukong Technologies Inc.
4 Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
5
6 http://www.cocos2d-x.org
7
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
14
15 The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 THE SOFTWARE.
25
26 ****************************************************************************/
27
28#ifndef __TestCpp__SocketIOTest__
29#define __TestCpp__SocketIOTest__
30
31#include "cocos2d.h"
32#include "extensions/cocos-ext.h"
33#include "network/SocketIO.h"
34#include "BaseTest.h"
35
36DEFINE_TEST_SUITE(SocketIOTests);
37
39 , public cocos2d::network::SocketIO::SIODelegate
40{
41public:
43
45 virtual ~SocketIOTest();
46
50 virtual void onClose(cocos2d::network::SIOClient* client)override;
54 virtual void onError(cocos2d::network::SIOClient* client, const std::string& data)override;
58 void closedSocketAction(cocos2d::network::SIOClient* client);
59
60 // test action handlers for main Test Client that connects to default namespace "" or "/"
61 void onMenuSIOClientClicked(cocos2d::Ref *sender);
62 void onMenuTestMessageClicked(cocos2d::Ref *sender);
63 void onMenuTestEventClicked(cocos2d::Ref *sender);
64 void onMenuTestClientDisconnectClicked(cocos2d::Ref *sender);
65
66 // test action handlers for Test Endpoint that connects to /testpoint endpoint
67 void onMenuSIOEndpointClicked(cocos2d::Ref *sender);
68 void onMenuTestMessageEndpointClicked(cocos2d::Ref *sender);
69 void onMenuTestEventEndpointClicked(cocos2d::Ref *sender);
70 void onMenuTestEndpointDisconnectClicked(cocos2d::Ref *sender);
71
72 // custom handlers for socket.io related events
73
77 void testevent(cocos2d::network::SIOClient *client, const std::string& data);
81 void echotest(cocos2d::network::SIOClient *client, const std::string& data);
85 void connect(cocos2d::network::SIOClient* client, const std::string& data);
89 void disconnect(cocos2d::network::SIOClient* client, const std::string& data);
93 void message(cocos2d::network::SIOClient* client, const std::string& data);
98 void json(cocos2d::network::SIOClient* client, const std::string& data);
99
100 virtual std::string title() const override{ return "SocketIO Extension Test"; }
101
102protected:
103
104 cocos2d::network::SIOClient *_sioClient, *_sioEndpoint;
105
106 cocos2d::Label *_sioClientStatus;
107};
108
109#endif /* defined(__TestCpp__SocketIOTest__) */
DEFINE_TEST_SUITE(SocketIOTests)
void echotest(cocos2d::network::SIOClient *client, const std::string &data)
Socket.io event handler for custom event "echoevent"
void onMenuSIOEndpointClicked(cocos2d::Ref *sender)
cocos2d::network::SIOClient * _sioClient
Definition: SocketIOTest.h:104
void onMenuTestEndpointDisconnectClicked(cocos2d::Ref *sender)
cocos2d::Label * _sioClientStatus
Definition: SocketIOTest.h:106
void connect(cocos2d::network::SIOClient *client, const std::string &data)
Socket.io event handler for event "connect"
void testevent(cocos2d::network::SIOClient *client, const std::string &data)
Socket.io event handler for custom event "testevent"
void onMenuTestEventClicked(cocos2d::Ref *sender)
void message(cocos2d::network::SIOClient *client, const std::string &data)
Socket.io event handler for event "message"
void closedSocketAction(cocos2d::network::SIOClient *client)
Common function to call on both socket.io disconnect and websocket close
void onMenuTestEventEndpointClicked(cocos2d::Ref *sender)
void onMenuTestClientDisconnectClicked(cocos2d::Ref *sender)
virtual void onError(cocos2d::network::SIOClient *client, const std::string &data) override
Used for network level socket error (not for disconnect from the socket.io server)
virtual std::string title() const override
Definition: SocketIOTest.h:100
void onMenuTestMessageEndpointClicked(cocos2d::Ref *sender)
void json(cocos2d::network::SIOClient *client, const std::string &data)
Socket.io event handler for event "json" This is only used in v 0.9.x, in 1.x this is handled as a "m...
void onMenuSIOClientClicked(cocos2d::Ref *sender)
cocos2d::network::SIOClient * _sioEndpoint
Definition: SocketIOTest.h:104
virtual void onClose(cocos2d::network::SIOClient *client) override
Used for network level socket close (not for disconnect from the socket.io server)
virtual ~SocketIOTest()
CREATE_FUNC(SocketIOTest)
void onMenuTestMessageClicked(cocos2d::Ref *sender)
void disconnect(cocos2d::network::SIOClient *client, const std::string &data)
Socket.io event handler for event "disconnect"