Implements a socket.io client extension, adds a test case and updates the android makefiles.
Contains the following tasks:
-initial socket.io extension commit
-sioclientimpl subclasses websocket:delegate to respond to websocket events
-implement static connect methods and basic client creation
-move SocketIO class files into correct extension folder (network)
-create SocketIO test in TestCpp
-update project references
-add missing static modifier to connect method
-implement basic test methods
-update extensions tests with SocketIO test entry
-implement basic handshake and opensocket methods for SocketIO
-add Delegate class to handle callbacks, implement virtual Delegate methods in test
-implement socket and client registries for lookup when connecting to hosts and endpoints
-connect delegate onOpen method by separating impl creation from connection
-update test to demonstrate onOpen callback
-create send and emit methods, move SIOClient into header file, add send and emit methods to test
-implement basic socket.io message parsing
-improve logging for events and messages
-add logic to pull event name from payload
-schedule heartbeat to keep connection alive, scheduled for 90% of the heartbeat interval from the server for safety
-add onConnect handler to to catch socket.io onconnect vs websocket onopen
-add disconnect and disconnectFromEndpoint methods to properly disconnect and destroy objects
-modify SIOClientImpl to track _uri for easier lookup in registries
-connect handler for onMessage to message event from socket.io, modify onError handler to take a string instead of WebSocket error code
-create SIOEvent callback type, implement event registry in clients, add test for event registration and callback
-update SIOEvent to use std::function and c++11, utilize cocos2d CC_CALLBACK method to bind selectors, this ensures that the *this reference is properly passed
-check for connect before sending or emitting in the client, cleanup some codes
-change connect logic to reuse existing socket connections instead of opening a new one
-implements get and set Tag methods for clients for easy reference
-improve endpoint handling, add endpoint tests to test layer
-additional error handling within socket disconnect error and failure to open connection
-fixes extracting endpoint from socket.io messages (in cases of the connect message, where there is 1 less colon for the connect message to the default namespace). Also fixes connecting to the default namespace "/" in the connectToEndpoint method
-add disconnect and onClose handlers to client so that onClose is called in the delegate
-add disconnect test methods to test layers
-change c-style casts to static_casts when using a CCDICT_FOREACH
-remove some unneeded namespace completion
-add usage documentation
-add handling for disconnect from server, cleanup some codes
-update comments and documentation in the socketiotest
-update includes so the NDK doesn't complain when compiling with c++11
-add socketio.cpp and test.cpp to the android makefiles
-update test URL to my public server, test script can also be found in my repo at https://github.com/hannon235/socket.io-testserver.git
Signed-off-by: Chris Hannon <himynameschris@gmail.com>
2013-06-26 10:40:01 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010-2013 cocos2d-x.org
|
|
|
|
Copyright (c) 2013 Chris Hannon
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
|
|
|
|
*based on the SocketIO library created by LearnBoost at http://socket.io
|
|
|
|
*using spec version 1 found at https://github.com/LearnBoost/socket.io-spec
|
|
|
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "SocketIO.h"
|
|
|
|
#include "cocos-ext.h"
|
|
|
|
#include "network/WebSocket.h"
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
NS_CC_EXT_BEGIN
|
|
|
|
|
|
|
|
//class declarations
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief The implementation of the socket.io connection
|
|
|
|
* Clients/endpoints may share the same impl to accomplish multiplexing on the same websocket
|
|
|
|
*/
|
|
|
|
class SIOClientImpl :
|
|
|
|
public Object,
|
|
|
|
public WebSocket::Delegate
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
int _port, _heartbeat, _timeout;
|
|
|
|
std::string _host, _sid, _uri;
|
|
|
|
bool _connected;
|
|
|
|
|
|
|
|
WebSocket *_ws;
|
|
|
|
|
|
|
|
Dictionary* _clients;
|
|
|
|
|
|
|
|
public:
|
|
|
|
SIOClientImpl(const std::string& host, int port);
|
|
|
|
virtual ~SIOClientImpl(void);
|
|
|
|
|
|
|
|
static SIOClientImpl* create(const std::string& host, int port);
|
|
|
|
|
|
|
|
virtual void onOpen(cocos2d::extension::WebSocket* ws);
|
|
|
|
virtual void onMessage(cocos2d::extension::WebSocket* ws, const cocos2d::extension::WebSocket::Data& data);
|
|
|
|
virtual void onClose(cocos2d::extension::WebSocket* ws);
|
|
|
|
virtual void onError(cocos2d::extension::WebSocket* ws, const cocos2d::extension::WebSocket::ErrorCode& error);
|
|
|
|
|
|
|
|
void connect();
|
|
|
|
void disconnect();
|
|
|
|
bool init();
|
|
|
|
void handshake();
|
|
|
|
void handshakeResponse(HttpClient *sender, HttpResponse *response);
|
|
|
|
void openSocket();
|
|
|
|
void heartbeat(float dt);
|
|
|
|
|
|
|
|
SIOClient* getClient(const std::string& endpoint);
|
|
|
|
void addClient(const std::string& endpoint, SIOClient* client);
|
|
|
|
|
|
|
|
void connectToEndpoint(const std::string& endpoint);
|
|
|
|
void disconnectFromEndpoint(const std::string& endpoint);
|
|
|
|
|
|
|
|
void send(std::string endpoint, std::string s);
|
|
|
|
void emit(std::string endpoint, std::string eventname, std::string args);
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//method implementations
|
|
|
|
|
|
|
|
//begin SIOClientImpl methods
|
|
|
|
SIOClientImpl::SIOClientImpl(const std::string& host, int port) :
|
|
|
|
_port(port),
|
|
|
|
_host(host),
|
|
|
|
_connected(false)
|
|
|
|
{
|
|
|
|
_clients = Dictionary::create();
|
|
|
|
_clients->retain();
|
|
|
|
|
|
|
|
std::stringstream s;
|
|
|
|
s << host << ":" << port;
|
|
|
|
_uri = s.str();
|
|
|
|
|
|
|
|
_ws = NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SIOClientImpl::~SIOClientImpl() {
|
|
|
|
|
|
|
|
if(_connected) disconnect();
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(_clients);
|
|
|
|
CC_SAFE_DELETE(_ws);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SIOClientImpl::handshake() {
|
2013-07-24 06:20:22 +08:00
|
|
|
log("SIOClientImpl::handshake() called");
|
Implements a socket.io client extension, adds a test case and updates the android makefiles.
Contains the following tasks:
-initial socket.io extension commit
-sioclientimpl subclasses websocket:delegate to respond to websocket events
-implement static connect methods and basic client creation
-move SocketIO class files into correct extension folder (network)
-create SocketIO test in TestCpp
-update project references
-add missing static modifier to connect method
-implement basic test methods
-update extensions tests with SocketIO test entry
-implement basic handshake and opensocket methods for SocketIO
-add Delegate class to handle callbacks, implement virtual Delegate methods in test
-implement socket and client registries for lookup when connecting to hosts and endpoints
-connect delegate onOpen method by separating impl creation from connection
-update test to demonstrate onOpen callback
-create send and emit methods, move SIOClient into header file, add send and emit methods to test
-implement basic socket.io message parsing
-improve logging for events and messages
-add logic to pull event name from payload
-schedule heartbeat to keep connection alive, scheduled for 90% of the heartbeat interval from the server for safety
-add onConnect handler to to catch socket.io onconnect vs websocket onopen
-add disconnect and disconnectFromEndpoint methods to properly disconnect and destroy objects
-modify SIOClientImpl to track _uri for easier lookup in registries
-connect handler for onMessage to message event from socket.io, modify onError handler to take a string instead of WebSocket error code
-create SIOEvent callback type, implement event registry in clients, add test for event registration and callback
-update SIOEvent to use std::function and c++11, utilize cocos2d CC_CALLBACK method to bind selectors, this ensures that the *this reference is properly passed
-check for connect before sending or emitting in the client, cleanup some codes
-change connect logic to reuse existing socket connections instead of opening a new one
-implements get and set Tag methods for clients for easy reference
-improve endpoint handling, add endpoint tests to test layer
-additional error handling within socket disconnect error and failure to open connection
-fixes extracting endpoint from socket.io messages (in cases of the connect message, where there is 1 less colon for the connect message to the default namespace). Also fixes connecting to the default namespace "/" in the connectToEndpoint method
-add disconnect and onClose handlers to client so that onClose is called in the delegate
-add disconnect test methods to test layers
-change c-style casts to static_casts when using a CCDICT_FOREACH
-remove some unneeded namespace completion
-add usage documentation
-add handling for disconnect from server, cleanup some codes
-update comments and documentation in the socketiotest
-update includes so the NDK doesn't complain when compiling with c++11
-add socketio.cpp and test.cpp to the android makefiles
-update test URL to my public server, test script can also be found in my repo at https://github.com/hannon235/socket.io-testserver.git
Signed-off-by: Chris Hannon <himynameschris@gmail.com>
2013-06-26 10:40:01 +08:00
|
|
|
|
|
|
|
std::stringstream pre;
|
|
|
|
pre << "http://" << _uri << "/socket.io/1";
|
|
|
|
|
|
|
|
HttpRequest* request = new HttpRequest();
|
|
|
|
request->setUrl(pre.str().c_str());
|
|
|
|
request->setRequestType(HttpRequest::kHttpGet);
|
|
|
|
|
|
|
|
request->setResponseCallback(this, httpresponse_selector(SIOClientImpl::handshakeResponse));
|
|
|
|
request->setTag("handshake");
|
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
log("SIOClientImpl::handshake() waiting");
|
Implements a socket.io client extension, adds a test case and updates the android makefiles.
Contains the following tasks:
-initial socket.io extension commit
-sioclientimpl subclasses websocket:delegate to respond to websocket events
-implement static connect methods and basic client creation
-move SocketIO class files into correct extension folder (network)
-create SocketIO test in TestCpp
-update project references
-add missing static modifier to connect method
-implement basic test methods
-update extensions tests with SocketIO test entry
-implement basic handshake and opensocket methods for SocketIO
-add Delegate class to handle callbacks, implement virtual Delegate methods in test
-implement socket and client registries for lookup when connecting to hosts and endpoints
-connect delegate onOpen method by separating impl creation from connection
-update test to demonstrate onOpen callback
-create send and emit methods, move SIOClient into header file, add send and emit methods to test
-implement basic socket.io message parsing
-improve logging for events and messages
-add logic to pull event name from payload
-schedule heartbeat to keep connection alive, scheduled for 90% of the heartbeat interval from the server for safety
-add onConnect handler to to catch socket.io onconnect vs websocket onopen
-add disconnect and disconnectFromEndpoint methods to properly disconnect and destroy objects
-modify SIOClientImpl to track _uri for easier lookup in registries
-connect handler for onMessage to message event from socket.io, modify onError handler to take a string instead of WebSocket error code
-create SIOEvent callback type, implement event registry in clients, add test for event registration and callback
-update SIOEvent to use std::function and c++11, utilize cocos2d CC_CALLBACK method to bind selectors, this ensures that the *this reference is properly passed
-check for connect before sending or emitting in the client, cleanup some codes
-change connect logic to reuse existing socket connections instead of opening a new one
-implements get and set Tag methods for clients for easy reference
-improve endpoint handling, add endpoint tests to test layer
-additional error handling within socket disconnect error and failure to open connection
-fixes extracting endpoint from socket.io messages (in cases of the connect message, where there is 1 less colon for the connect message to the default namespace). Also fixes connecting to the default namespace "/" in the connectToEndpoint method
-add disconnect and onClose handlers to client so that onClose is called in the delegate
-add disconnect test methods to test layers
-change c-style casts to static_casts when using a CCDICT_FOREACH
-remove some unneeded namespace completion
-add usage documentation
-add handling for disconnect from server, cleanup some codes
-update comments and documentation in the socketiotest
-update includes so the NDK doesn't complain when compiling with c++11
-add socketio.cpp and test.cpp to the android makefiles
-update test URL to my public server, test script can also be found in my repo at https://github.com/hannon235/socket.io-testserver.git
Signed-off-by: Chris Hannon <himynameschris@gmail.com>
2013-06-26 10:40:01 +08:00
|
|
|
|
|
|
|
HttpClient::getInstance()->send(request);
|
|
|
|
|
|
|
|
request->release();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SIOClientImpl::handshakeResponse(HttpClient *sender, HttpResponse *response) {
|
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
log("SIOClientImpl::handshakeResponse() called");
|
Implements a socket.io client extension, adds a test case and updates the android makefiles.
Contains the following tasks:
-initial socket.io extension commit
-sioclientimpl subclasses websocket:delegate to respond to websocket events
-implement static connect methods and basic client creation
-move SocketIO class files into correct extension folder (network)
-create SocketIO test in TestCpp
-update project references
-add missing static modifier to connect method
-implement basic test methods
-update extensions tests with SocketIO test entry
-implement basic handshake and opensocket methods for SocketIO
-add Delegate class to handle callbacks, implement virtual Delegate methods in test
-implement socket and client registries for lookup when connecting to hosts and endpoints
-connect delegate onOpen method by separating impl creation from connection
-update test to demonstrate onOpen callback
-create send and emit methods, move SIOClient into header file, add send and emit methods to test
-implement basic socket.io message parsing
-improve logging for events and messages
-add logic to pull event name from payload
-schedule heartbeat to keep connection alive, scheduled for 90% of the heartbeat interval from the server for safety
-add onConnect handler to to catch socket.io onconnect vs websocket onopen
-add disconnect and disconnectFromEndpoint methods to properly disconnect and destroy objects
-modify SIOClientImpl to track _uri for easier lookup in registries
-connect handler for onMessage to message event from socket.io, modify onError handler to take a string instead of WebSocket error code
-create SIOEvent callback type, implement event registry in clients, add test for event registration and callback
-update SIOEvent to use std::function and c++11, utilize cocos2d CC_CALLBACK method to bind selectors, this ensures that the *this reference is properly passed
-check for connect before sending or emitting in the client, cleanup some codes
-change connect logic to reuse existing socket connections instead of opening a new one
-implements get and set Tag methods for clients for easy reference
-improve endpoint handling, add endpoint tests to test layer
-additional error handling within socket disconnect error and failure to open connection
-fixes extracting endpoint from socket.io messages (in cases of the connect message, where there is 1 less colon for the connect message to the default namespace). Also fixes connecting to the default namespace "/" in the connectToEndpoint method
-add disconnect and onClose handlers to client so that onClose is called in the delegate
-add disconnect test methods to test layers
-change c-style casts to static_casts when using a CCDICT_FOREACH
-remove some unneeded namespace completion
-add usage documentation
-add handling for disconnect from server, cleanup some codes
-update comments and documentation in the socketiotest
-update includes so the NDK doesn't complain when compiling with c++11
-add socketio.cpp and test.cpp to the android makefiles
-update test URL to my public server, test script can also be found in my repo at https://github.com/hannon235/socket.io-testserver.git
Signed-off-by: Chris Hannon <himynameschris@gmail.com>
2013-06-26 10:40:01 +08:00
|
|
|
|
|
|
|
if (0 != strlen(response->getHttpRequest()->getTag()))
|
|
|
|
{
|
2013-07-24 06:20:22 +08:00
|
|
|
log("%s completed", response->getHttpRequest()->getTag());
|
Implements a socket.io client extension, adds a test case and updates the android makefiles.
Contains the following tasks:
-initial socket.io extension commit
-sioclientimpl subclasses websocket:delegate to respond to websocket events
-implement static connect methods and basic client creation
-move SocketIO class files into correct extension folder (network)
-create SocketIO test in TestCpp
-update project references
-add missing static modifier to connect method
-implement basic test methods
-update extensions tests with SocketIO test entry
-implement basic handshake and opensocket methods for SocketIO
-add Delegate class to handle callbacks, implement virtual Delegate methods in test
-implement socket and client registries for lookup when connecting to hosts and endpoints
-connect delegate onOpen method by separating impl creation from connection
-update test to demonstrate onOpen callback
-create send and emit methods, move SIOClient into header file, add send and emit methods to test
-implement basic socket.io message parsing
-improve logging for events and messages
-add logic to pull event name from payload
-schedule heartbeat to keep connection alive, scheduled for 90% of the heartbeat interval from the server for safety
-add onConnect handler to to catch socket.io onconnect vs websocket onopen
-add disconnect and disconnectFromEndpoint methods to properly disconnect and destroy objects
-modify SIOClientImpl to track _uri for easier lookup in registries
-connect handler for onMessage to message event from socket.io, modify onError handler to take a string instead of WebSocket error code
-create SIOEvent callback type, implement event registry in clients, add test for event registration and callback
-update SIOEvent to use std::function and c++11, utilize cocos2d CC_CALLBACK method to bind selectors, this ensures that the *this reference is properly passed
-check for connect before sending or emitting in the client, cleanup some codes
-change connect logic to reuse existing socket connections instead of opening a new one
-implements get and set Tag methods for clients for easy reference
-improve endpoint handling, add endpoint tests to test layer
-additional error handling within socket disconnect error and failure to open connection
-fixes extracting endpoint from socket.io messages (in cases of the connect message, where there is 1 less colon for the connect message to the default namespace). Also fixes connecting to the default namespace "/" in the connectToEndpoint method
-add disconnect and onClose handlers to client so that onClose is called in the delegate
-add disconnect test methods to test layers
-change c-style casts to static_casts when using a CCDICT_FOREACH
-remove some unneeded namespace completion
-add usage documentation
-add handling for disconnect from server, cleanup some codes
-update comments and documentation in the socketiotest
-update includes so the NDK doesn't complain when compiling with c++11
-add socketio.cpp and test.cpp to the android makefiles
-update test URL to my public server, test script can also be found in my repo at https://github.com/hannon235/socket.io-testserver.git
Signed-off-by: Chris Hannon <himynameschris@gmail.com>
2013-06-26 10:40:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int statusCode = response->getResponseCode();
|
|
|
|
char statusString[64] = {};
|
|
|
|
sprintf(statusString, "HTTP Status Code: %d, tag = %s", statusCode, response->getHttpRequest()->getTag());
|
2013-07-24 06:20:22 +08:00
|
|
|
log("response code: %d", statusCode);
|
Implements a socket.io client extension, adds a test case and updates the android makefiles.
Contains the following tasks:
-initial socket.io extension commit
-sioclientimpl subclasses websocket:delegate to respond to websocket events
-implement static connect methods and basic client creation
-move SocketIO class files into correct extension folder (network)
-create SocketIO test in TestCpp
-update project references
-add missing static modifier to connect method
-implement basic test methods
-update extensions tests with SocketIO test entry
-implement basic handshake and opensocket methods for SocketIO
-add Delegate class to handle callbacks, implement virtual Delegate methods in test
-implement socket and client registries for lookup when connecting to hosts and endpoints
-connect delegate onOpen method by separating impl creation from connection
-update test to demonstrate onOpen callback
-create send and emit methods, move SIOClient into header file, add send and emit methods to test
-implement basic socket.io message parsing
-improve logging for events and messages
-add logic to pull event name from payload
-schedule heartbeat to keep connection alive, scheduled for 90% of the heartbeat interval from the server for safety
-add onConnect handler to to catch socket.io onconnect vs websocket onopen
-add disconnect and disconnectFromEndpoint methods to properly disconnect and destroy objects
-modify SIOClientImpl to track _uri for easier lookup in registries
-connect handler for onMessage to message event from socket.io, modify onError handler to take a string instead of WebSocket error code
-create SIOEvent callback type, implement event registry in clients, add test for event registration and callback
-update SIOEvent to use std::function and c++11, utilize cocos2d CC_CALLBACK method to bind selectors, this ensures that the *this reference is properly passed
-check for connect before sending or emitting in the client, cleanup some codes
-change connect logic to reuse existing socket connections instead of opening a new one
-implements get and set Tag methods for clients for easy reference
-improve endpoint handling, add endpoint tests to test layer
-additional error handling within socket disconnect error and failure to open connection
-fixes extracting endpoint from socket.io messages (in cases of the connect message, where there is 1 less colon for the connect message to the default namespace). Also fixes connecting to the default namespace "/" in the connectToEndpoint method
-add disconnect and onClose handlers to client so that onClose is called in the delegate
-add disconnect test methods to test layers
-change c-style casts to static_casts when using a CCDICT_FOREACH
-remove some unneeded namespace completion
-add usage documentation
-add handling for disconnect from server, cleanup some codes
-update comments and documentation in the socketiotest
-update includes so the NDK doesn't complain when compiling with c++11
-add socketio.cpp and test.cpp to the android makefiles
-update test URL to my public server, test script can also be found in my repo at https://github.com/hannon235/socket.io-testserver.git
Signed-off-by: Chris Hannon <himynameschris@gmail.com>
2013-06-26 10:40:01 +08:00
|
|
|
|
|
|
|
if (!response->isSucceed())
|
|
|
|
{
|
2013-07-24 06:20:22 +08:00
|
|
|
log("SIOClientImpl::handshake() failed");
|
|
|
|
log("error buffer: %s", response->getErrorBuffer());
|
Implements a socket.io client extension, adds a test case and updates the android makefiles.
Contains the following tasks:
-initial socket.io extension commit
-sioclientimpl subclasses websocket:delegate to respond to websocket events
-implement static connect methods and basic client creation
-move SocketIO class files into correct extension folder (network)
-create SocketIO test in TestCpp
-update project references
-add missing static modifier to connect method
-implement basic test methods
-update extensions tests with SocketIO test entry
-implement basic handshake and opensocket methods for SocketIO
-add Delegate class to handle callbacks, implement virtual Delegate methods in test
-implement socket and client registries for lookup when connecting to hosts and endpoints
-connect delegate onOpen method by separating impl creation from connection
-update test to demonstrate onOpen callback
-create send and emit methods, move SIOClient into header file, add send and emit methods to test
-implement basic socket.io message parsing
-improve logging for events and messages
-add logic to pull event name from payload
-schedule heartbeat to keep connection alive, scheduled for 90% of the heartbeat interval from the server for safety
-add onConnect handler to to catch socket.io onconnect vs websocket onopen
-add disconnect and disconnectFromEndpoint methods to properly disconnect and destroy objects
-modify SIOClientImpl to track _uri for easier lookup in registries
-connect handler for onMessage to message event from socket.io, modify onError handler to take a string instead of WebSocket error code
-create SIOEvent callback type, implement event registry in clients, add test for event registration and callback
-update SIOEvent to use std::function and c++11, utilize cocos2d CC_CALLBACK method to bind selectors, this ensures that the *this reference is properly passed
-check for connect before sending or emitting in the client, cleanup some codes
-change connect logic to reuse existing socket connections instead of opening a new one
-implements get and set Tag methods for clients for easy reference
-improve endpoint handling, add endpoint tests to test layer
-additional error handling within socket disconnect error and failure to open connection
-fixes extracting endpoint from socket.io messages (in cases of the connect message, where there is 1 less colon for the connect message to the default namespace). Also fixes connecting to the default namespace "/" in the connectToEndpoint method
-add disconnect and onClose handlers to client so that onClose is called in the delegate
-add disconnect test methods to test layers
-change c-style casts to static_casts when using a CCDICT_FOREACH
-remove some unneeded namespace completion
-add usage documentation
-add handling for disconnect from server, cleanup some codes
-update comments and documentation in the socketiotest
-update includes so the NDK doesn't complain when compiling with c++11
-add socketio.cpp and test.cpp to the android makefiles
-update test URL to my public server, test script can also be found in my repo at https://github.com/hannon235/socket.io-testserver.git
Signed-off-by: Chris Hannon <himynameschris@gmail.com>
2013-06-26 10:40:01 +08:00
|
|
|
|
|
|
|
DictElement* el = NULL;
|
|
|
|
|
|
|
|
CCDICT_FOREACH(_clients, el) {
|
|
|
|
|
|
|
|
SIOClient* c = static_cast<SIOClient*>(el->getObject());
|
|
|
|
|
|
|
|
c->getDelegate()->onError(c, response->getErrorBuffer());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
log("SIOClientImpl::handshake() succeeded");
|
Implements a socket.io client extension, adds a test case and updates the android makefiles.
Contains the following tasks:
-initial socket.io extension commit
-sioclientimpl subclasses websocket:delegate to respond to websocket events
-implement static connect methods and basic client creation
-move SocketIO class files into correct extension folder (network)
-create SocketIO test in TestCpp
-update project references
-add missing static modifier to connect method
-implement basic test methods
-update extensions tests with SocketIO test entry
-implement basic handshake and opensocket methods for SocketIO
-add Delegate class to handle callbacks, implement virtual Delegate methods in test
-implement socket and client registries for lookup when connecting to hosts and endpoints
-connect delegate onOpen method by separating impl creation from connection
-update test to demonstrate onOpen callback
-create send and emit methods, move SIOClient into header file, add send and emit methods to test
-implement basic socket.io message parsing
-improve logging for events and messages
-add logic to pull event name from payload
-schedule heartbeat to keep connection alive, scheduled for 90% of the heartbeat interval from the server for safety
-add onConnect handler to to catch socket.io onconnect vs websocket onopen
-add disconnect and disconnectFromEndpoint methods to properly disconnect and destroy objects
-modify SIOClientImpl to track _uri for easier lookup in registries
-connect handler for onMessage to message event from socket.io, modify onError handler to take a string instead of WebSocket error code
-create SIOEvent callback type, implement event registry in clients, add test for event registration and callback
-update SIOEvent to use std::function and c++11, utilize cocos2d CC_CALLBACK method to bind selectors, this ensures that the *this reference is properly passed
-check for connect before sending or emitting in the client, cleanup some codes
-change connect logic to reuse existing socket connections instead of opening a new one
-implements get and set Tag methods for clients for easy reference
-improve endpoint handling, add endpoint tests to test layer
-additional error handling within socket disconnect error and failure to open connection
-fixes extracting endpoint from socket.io messages (in cases of the connect message, where there is 1 less colon for the connect message to the default namespace). Also fixes connecting to the default namespace "/" in the connectToEndpoint method
-add disconnect and onClose handlers to client so that onClose is called in the delegate
-add disconnect test methods to test layers
-change c-style casts to static_casts when using a CCDICT_FOREACH
-remove some unneeded namespace completion
-add usage documentation
-add handling for disconnect from server, cleanup some codes
-update comments and documentation in the socketiotest
-update includes so the NDK doesn't complain when compiling with c++11
-add socketio.cpp and test.cpp to the android makefiles
-update test URL to my public server, test script can also be found in my repo at https://github.com/hannon235/socket.io-testserver.git
Signed-off-by: Chris Hannon <himynameschris@gmail.com>
2013-06-26 10:40:01 +08:00
|
|
|
|
|
|
|
std::vector<char> *buffer = response->getResponseData();
|
|
|
|
std::stringstream s;
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < buffer->size(); i++)
|
|
|
|
{
|
|
|
|
s << (*buffer)[i];
|
|
|
|
}
|
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
log("SIOClientImpl::handshake() dump data: %s", s.str().c_str());
|
Implements a socket.io client extension, adds a test case and updates the android makefiles.
Contains the following tasks:
-initial socket.io extension commit
-sioclientimpl subclasses websocket:delegate to respond to websocket events
-implement static connect methods and basic client creation
-move SocketIO class files into correct extension folder (network)
-create SocketIO test in TestCpp
-update project references
-add missing static modifier to connect method
-implement basic test methods
-update extensions tests with SocketIO test entry
-implement basic handshake and opensocket methods for SocketIO
-add Delegate class to handle callbacks, implement virtual Delegate methods in test
-implement socket and client registries for lookup when connecting to hosts and endpoints
-connect delegate onOpen method by separating impl creation from connection
-update test to demonstrate onOpen callback
-create send and emit methods, move SIOClient into header file, add send and emit methods to test
-implement basic socket.io message parsing
-improve logging for events and messages
-add logic to pull event name from payload
-schedule heartbeat to keep connection alive, scheduled for 90% of the heartbeat interval from the server for safety
-add onConnect handler to to catch socket.io onconnect vs websocket onopen
-add disconnect and disconnectFromEndpoint methods to properly disconnect and destroy objects
-modify SIOClientImpl to track _uri for easier lookup in registries
-connect handler for onMessage to message event from socket.io, modify onError handler to take a string instead of WebSocket error code
-create SIOEvent callback type, implement event registry in clients, add test for event registration and callback
-update SIOEvent to use std::function and c++11, utilize cocos2d CC_CALLBACK method to bind selectors, this ensures that the *this reference is properly passed
-check for connect before sending or emitting in the client, cleanup some codes
-change connect logic to reuse existing socket connections instead of opening a new one
-implements get and set Tag methods for clients for easy reference
-improve endpoint handling, add endpoint tests to test layer
-additional error handling within socket disconnect error and failure to open connection
-fixes extracting endpoint from socket.io messages (in cases of the connect message, where there is 1 less colon for the connect message to the default namespace). Also fixes connecting to the default namespace "/" in the connectToEndpoint method
-add disconnect and onClose handlers to client so that onClose is called in the delegate
-add disconnect test methods to test layers
-change c-style casts to static_casts when using a CCDICT_FOREACH
-remove some unneeded namespace completion
-add usage documentation
-add handling for disconnect from server, cleanup some codes
-update comments and documentation in the socketiotest
-update includes so the NDK doesn't complain when compiling with c++11
-add socketio.cpp and test.cpp to the android makefiles
-update test URL to my public server, test script can also be found in my repo at https://github.com/hannon235/socket.io-testserver.git
Signed-off-by: Chris Hannon <himynameschris@gmail.com>
2013-06-26 10:40:01 +08:00
|
|
|
|
|
|
|
std::string res = s.str();
|
|
|
|
std::string sid;
|
2013-07-13 19:20:11 +08:00
|
|
|
int pos = 0;
|
|
|
|
int heartbeat = 0, timeout = 0;
|
Implements a socket.io client extension, adds a test case and updates the android makefiles.
Contains the following tasks:
-initial socket.io extension commit
-sioclientimpl subclasses websocket:delegate to respond to websocket events
-implement static connect methods and basic client creation
-move SocketIO class files into correct extension folder (network)
-create SocketIO test in TestCpp
-update project references
-add missing static modifier to connect method
-implement basic test methods
-update extensions tests with SocketIO test entry
-implement basic handshake and opensocket methods for SocketIO
-add Delegate class to handle callbacks, implement virtual Delegate methods in test
-implement socket and client registries for lookup when connecting to hosts and endpoints
-connect delegate onOpen method by separating impl creation from connection
-update test to demonstrate onOpen callback
-create send and emit methods, move SIOClient into header file, add send and emit methods to test
-implement basic socket.io message parsing
-improve logging for events and messages
-add logic to pull event name from payload
-schedule heartbeat to keep connection alive, scheduled for 90% of the heartbeat interval from the server for safety
-add onConnect handler to to catch socket.io onconnect vs websocket onopen
-add disconnect and disconnectFromEndpoint methods to properly disconnect and destroy objects
-modify SIOClientImpl to track _uri for easier lookup in registries
-connect handler for onMessage to message event from socket.io, modify onError handler to take a string instead of WebSocket error code
-create SIOEvent callback type, implement event registry in clients, add test for event registration and callback
-update SIOEvent to use std::function and c++11, utilize cocos2d CC_CALLBACK method to bind selectors, this ensures that the *this reference is properly passed
-check for connect before sending or emitting in the client, cleanup some codes
-change connect logic to reuse existing socket connections instead of opening a new one
-implements get and set Tag methods for clients for easy reference
-improve endpoint handling, add endpoint tests to test layer
-additional error handling within socket disconnect error and failure to open connection
-fixes extracting endpoint from socket.io messages (in cases of the connect message, where there is 1 less colon for the connect message to the default namespace). Also fixes connecting to the default namespace "/" in the connectToEndpoint method
-add disconnect and onClose handlers to client so that onClose is called in the delegate
-add disconnect test methods to test layers
-change c-style casts to static_casts when using a CCDICT_FOREACH
-remove some unneeded namespace completion
-add usage documentation
-add handling for disconnect from server, cleanup some codes
-update comments and documentation in the socketiotest
-update includes so the NDK doesn't complain when compiling with c++11
-add socketio.cpp and test.cpp to the android makefiles
-update test URL to my public server, test script can also be found in my repo at https://github.com/hannon235/socket.io-testserver.git
Signed-off-by: Chris Hannon <himynameschris@gmail.com>
2013-06-26 10:40:01 +08:00
|
|
|
|
|
|
|
pos = res.find(":");
|
|
|
|
if(pos >= 0) {
|
|
|
|
sid = res.substr(0, pos);
|
|
|
|
res.erase(0, pos+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
pos = res.find(":");
|
|
|
|
if(pos >= 0){
|
|
|
|
heartbeat = atoi(res.substr(pos+1, res.size()).c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
pos = res.find(":");
|
|
|
|
if(pos >= 0){
|
|
|
|
timeout = atoi(res.substr(pos+1, res.size()).c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
_sid = sid;
|
|
|
|
_heartbeat = heartbeat;
|
|
|
|
_timeout = timeout;
|
|
|
|
|
|
|
|
openSocket();
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SIOClientImpl::openSocket() {
|
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
log("SIOClientImpl::openSocket() called");
|
Implements a socket.io client extension, adds a test case and updates the android makefiles.
Contains the following tasks:
-initial socket.io extension commit
-sioclientimpl subclasses websocket:delegate to respond to websocket events
-implement static connect methods and basic client creation
-move SocketIO class files into correct extension folder (network)
-create SocketIO test in TestCpp
-update project references
-add missing static modifier to connect method
-implement basic test methods
-update extensions tests with SocketIO test entry
-implement basic handshake and opensocket methods for SocketIO
-add Delegate class to handle callbacks, implement virtual Delegate methods in test
-implement socket and client registries for lookup when connecting to hosts and endpoints
-connect delegate onOpen method by separating impl creation from connection
-update test to demonstrate onOpen callback
-create send and emit methods, move SIOClient into header file, add send and emit methods to test
-implement basic socket.io message parsing
-improve logging for events and messages
-add logic to pull event name from payload
-schedule heartbeat to keep connection alive, scheduled for 90% of the heartbeat interval from the server for safety
-add onConnect handler to to catch socket.io onconnect vs websocket onopen
-add disconnect and disconnectFromEndpoint methods to properly disconnect and destroy objects
-modify SIOClientImpl to track _uri for easier lookup in registries
-connect handler for onMessage to message event from socket.io, modify onError handler to take a string instead of WebSocket error code
-create SIOEvent callback type, implement event registry in clients, add test for event registration and callback
-update SIOEvent to use std::function and c++11, utilize cocos2d CC_CALLBACK method to bind selectors, this ensures that the *this reference is properly passed
-check for connect before sending or emitting in the client, cleanup some codes
-change connect logic to reuse existing socket connections instead of opening a new one
-implements get and set Tag methods for clients for easy reference
-improve endpoint handling, add endpoint tests to test layer
-additional error handling within socket disconnect error and failure to open connection
-fixes extracting endpoint from socket.io messages (in cases of the connect message, where there is 1 less colon for the connect message to the default namespace). Also fixes connecting to the default namespace "/" in the connectToEndpoint method
-add disconnect and onClose handlers to client so that onClose is called in the delegate
-add disconnect test methods to test layers
-change c-style casts to static_casts when using a CCDICT_FOREACH
-remove some unneeded namespace completion
-add usage documentation
-add handling for disconnect from server, cleanup some codes
-update comments and documentation in the socketiotest
-update includes so the NDK doesn't complain when compiling with c++11
-add socketio.cpp and test.cpp to the android makefiles
-update test URL to my public server, test script can also be found in my repo at https://github.com/hannon235/socket.io-testserver.git
Signed-off-by: Chris Hannon <himynameschris@gmail.com>
2013-06-26 10:40:01 +08:00
|
|
|
|
|
|
|
std::stringstream s;
|
|
|
|
s << _uri << "/socket.io/1/websocket/" << _sid;
|
|
|
|
|
|
|
|
_ws = new WebSocket();
|
|
|
|
if(!_ws->init(*this, s.str()))
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(_ws);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SIOClientImpl::init() {
|
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
log("SIOClientImpl::init() successful");
|
Implements a socket.io client extension, adds a test case and updates the android makefiles.
Contains the following tasks:
-initial socket.io extension commit
-sioclientimpl subclasses websocket:delegate to respond to websocket events
-implement static connect methods and basic client creation
-move SocketIO class files into correct extension folder (network)
-create SocketIO test in TestCpp
-update project references
-add missing static modifier to connect method
-implement basic test methods
-update extensions tests with SocketIO test entry
-implement basic handshake and opensocket methods for SocketIO
-add Delegate class to handle callbacks, implement virtual Delegate methods in test
-implement socket and client registries for lookup when connecting to hosts and endpoints
-connect delegate onOpen method by separating impl creation from connection
-update test to demonstrate onOpen callback
-create send and emit methods, move SIOClient into header file, add send and emit methods to test
-implement basic socket.io message parsing
-improve logging for events and messages
-add logic to pull event name from payload
-schedule heartbeat to keep connection alive, scheduled for 90% of the heartbeat interval from the server for safety
-add onConnect handler to to catch socket.io onconnect vs websocket onopen
-add disconnect and disconnectFromEndpoint methods to properly disconnect and destroy objects
-modify SIOClientImpl to track _uri for easier lookup in registries
-connect handler for onMessage to message event from socket.io, modify onError handler to take a string instead of WebSocket error code
-create SIOEvent callback type, implement event registry in clients, add test for event registration and callback
-update SIOEvent to use std::function and c++11, utilize cocos2d CC_CALLBACK method to bind selectors, this ensures that the *this reference is properly passed
-check for connect before sending or emitting in the client, cleanup some codes
-change connect logic to reuse existing socket connections instead of opening a new one
-implements get and set Tag methods for clients for easy reference
-improve endpoint handling, add endpoint tests to test layer
-additional error handling within socket disconnect error and failure to open connection
-fixes extracting endpoint from socket.io messages (in cases of the connect message, where there is 1 less colon for the connect message to the default namespace). Also fixes connecting to the default namespace "/" in the connectToEndpoint method
-add disconnect and onClose handlers to client so that onClose is called in the delegate
-add disconnect test methods to test layers
-change c-style casts to static_casts when using a CCDICT_FOREACH
-remove some unneeded namespace completion
-add usage documentation
-add handling for disconnect from server, cleanup some codes
-update comments and documentation in the socketiotest
-update includes so the NDK doesn't complain when compiling with c++11
-add socketio.cpp and test.cpp to the android makefiles
-update test URL to my public server, test script can also be found in my repo at https://github.com/hannon235/socket.io-testserver.git
Signed-off-by: Chris Hannon <himynameschris@gmail.com>
2013-06-26 10:40:01 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SIOClientImpl::connect() {
|
|
|
|
|
|
|
|
this->handshake();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SIOClientImpl::disconnect() {
|
|
|
|
|
|
|
|
if(_ws->getReadyState() == WebSocket::kStateOpen) {
|
|
|
|
|
|
|
|
std::string s = "0::";
|
|
|
|
|
|
|
|
_ws->send(s);
|
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
log("Disconnect sent");
|
Implements a socket.io client extension, adds a test case and updates the android makefiles.
Contains the following tasks:
-initial socket.io extension commit
-sioclientimpl subclasses websocket:delegate to respond to websocket events
-implement static connect methods and basic client creation
-move SocketIO class files into correct extension folder (network)
-create SocketIO test in TestCpp
-update project references
-add missing static modifier to connect method
-implement basic test methods
-update extensions tests with SocketIO test entry
-implement basic handshake and opensocket methods for SocketIO
-add Delegate class to handle callbacks, implement virtual Delegate methods in test
-implement socket and client registries for lookup when connecting to hosts and endpoints
-connect delegate onOpen method by separating impl creation from connection
-update test to demonstrate onOpen callback
-create send and emit methods, move SIOClient into header file, add send and emit methods to test
-implement basic socket.io message parsing
-improve logging for events and messages
-add logic to pull event name from payload
-schedule heartbeat to keep connection alive, scheduled for 90% of the heartbeat interval from the server for safety
-add onConnect handler to to catch socket.io onconnect vs websocket onopen
-add disconnect and disconnectFromEndpoint methods to properly disconnect and destroy objects
-modify SIOClientImpl to track _uri for easier lookup in registries
-connect handler for onMessage to message event from socket.io, modify onError handler to take a string instead of WebSocket error code
-create SIOEvent callback type, implement event registry in clients, add test for event registration and callback
-update SIOEvent to use std::function and c++11, utilize cocos2d CC_CALLBACK method to bind selectors, this ensures that the *this reference is properly passed
-check for connect before sending or emitting in the client, cleanup some codes
-change connect logic to reuse existing socket connections instead of opening a new one
-implements get and set Tag methods for clients for easy reference
-improve endpoint handling, add endpoint tests to test layer
-additional error handling within socket disconnect error and failure to open connection
-fixes extracting endpoint from socket.io messages (in cases of the connect message, where there is 1 less colon for the connect message to the default namespace). Also fixes connecting to the default namespace "/" in the connectToEndpoint method
-add disconnect and onClose handlers to client so that onClose is called in the delegate
-add disconnect test methods to test layers
-change c-style casts to static_casts when using a CCDICT_FOREACH
-remove some unneeded namespace completion
-add usage documentation
-add handling for disconnect from server, cleanup some codes
-update comments and documentation in the socketiotest
-update includes so the NDK doesn't complain when compiling with c++11
-add socketio.cpp and test.cpp to the android makefiles
-update test URL to my public server, test script can also be found in my repo at https://github.com/hannon235/socket.io-testserver.git
Signed-off-by: Chris Hannon <himynameschris@gmail.com>
2013-06-26 10:40:01 +08:00
|
|
|
|
|
|
|
_ws->close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-07-13 19:20:11 +08:00
|
|
|
Director::getInstance()->getScheduler()->unscheduleAllForTarget(this);
|
Implements a socket.io client extension, adds a test case and updates the android makefiles.
Contains the following tasks:
-initial socket.io extension commit
-sioclientimpl subclasses websocket:delegate to respond to websocket events
-implement static connect methods and basic client creation
-move SocketIO class files into correct extension folder (network)
-create SocketIO test in TestCpp
-update project references
-add missing static modifier to connect method
-implement basic test methods
-update extensions tests with SocketIO test entry
-implement basic handshake and opensocket methods for SocketIO
-add Delegate class to handle callbacks, implement virtual Delegate methods in test
-implement socket and client registries for lookup when connecting to hosts and endpoints
-connect delegate onOpen method by separating impl creation from connection
-update test to demonstrate onOpen callback
-create send and emit methods, move SIOClient into header file, add send and emit methods to test
-implement basic socket.io message parsing
-improve logging for events and messages
-add logic to pull event name from payload
-schedule heartbeat to keep connection alive, scheduled for 90% of the heartbeat interval from the server for safety
-add onConnect handler to to catch socket.io onconnect vs websocket onopen
-add disconnect and disconnectFromEndpoint methods to properly disconnect and destroy objects
-modify SIOClientImpl to track _uri for easier lookup in registries
-connect handler for onMessage to message event from socket.io, modify onError handler to take a string instead of WebSocket error code
-create SIOEvent callback type, implement event registry in clients, add test for event registration and callback
-update SIOEvent to use std::function and c++11, utilize cocos2d CC_CALLBACK method to bind selectors, this ensures that the *this reference is properly passed
-check for connect before sending or emitting in the client, cleanup some codes
-change connect logic to reuse existing socket connections instead of opening a new one
-implements get and set Tag methods for clients for easy reference
-improve endpoint handling, add endpoint tests to test layer
-additional error handling within socket disconnect error and failure to open connection
-fixes extracting endpoint from socket.io messages (in cases of the connect message, where there is 1 less colon for the connect message to the default namespace). Also fixes connecting to the default namespace "/" in the connectToEndpoint method
-add disconnect and onClose handlers to client so that onClose is called in the delegate
-add disconnect test methods to test layers
-change c-style casts to static_casts when using a CCDICT_FOREACH
-remove some unneeded namespace completion
-add usage documentation
-add handling for disconnect from server, cleanup some codes
-update comments and documentation in the socketiotest
-update includes so the NDK doesn't complain when compiling with c++11
-add socketio.cpp and test.cpp to the android makefiles
-update test URL to my public server, test script can also be found in my repo at https://github.com/hannon235/socket.io-testserver.git
Signed-off-by: Chris Hannon <himynameschris@gmail.com>
2013-06-26 10:40:01 +08:00
|
|
|
|
|
|
|
_connected = false;
|
|
|
|
|
|
|
|
SocketIO::instance()->removeSocket(_uri);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SIOClientImpl* SIOClientImpl::create(const std::string& host, int port) {
|
|
|
|
|
|
|
|
SIOClientImpl *s = new SIOClientImpl(host, port);
|
|
|
|
|
|
|
|
if(s && s->init()) {
|
|
|
|
|
|
|
|
return s;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SIOClient* SIOClientImpl::getClient(const std::string& endpoint) {
|
|
|
|
|
|
|
|
return static_cast<SIOClient*>(_clients->objectForKey(endpoint));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SIOClientImpl::addClient(const std::string& endpoint, SIOClient* client) {
|
|
|
|
|
|
|
|
_clients->setObject(client, endpoint);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SIOClientImpl::connectToEndpoint(const std::string& endpoint) {
|
|
|
|
|
|
|
|
std::string path = endpoint == "/" ? "" : endpoint;
|
|
|
|
|
|
|
|
std::string s = "1::" + path;
|
|
|
|
|
|
|
|
_ws->send(s);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SIOClientImpl::disconnectFromEndpoint(const std::string& endpoint) {
|
|
|
|
|
|
|
|
_clients->removeObjectForKey(endpoint);
|
|
|
|
|
|
|
|
if(_clients->count() == 0 || endpoint == "/") {
|
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
log("SIOClientImpl::disconnectFromEndpoint out of endpoints, checking for disconnect");
|
Implements a socket.io client extension, adds a test case and updates the android makefiles.
Contains the following tasks:
-initial socket.io extension commit
-sioclientimpl subclasses websocket:delegate to respond to websocket events
-implement static connect methods and basic client creation
-move SocketIO class files into correct extension folder (network)
-create SocketIO test in TestCpp
-update project references
-add missing static modifier to connect method
-implement basic test methods
-update extensions tests with SocketIO test entry
-implement basic handshake and opensocket methods for SocketIO
-add Delegate class to handle callbacks, implement virtual Delegate methods in test
-implement socket and client registries for lookup when connecting to hosts and endpoints
-connect delegate onOpen method by separating impl creation from connection
-update test to demonstrate onOpen callback
-create send and emit methods, move SIOClient into header file, add send and emit methods to test
-implement basic socket.io message parsing
-improve logging for events and messages
-add logic to pull event name from payload
-schedule heartbeat to keep connection alive, scheduled for 90% of the heartbeat interval from the server for safety
-add onConnect handler to to catch socket.io onconnect vs websocket onopen
-add disconnect and disconnectFromEndpoint methods to properly disconnect and destroy objects
-modify SIOClientImpl to track _uri for easier lookup in registries
-connect handler for onMessage to message event from socket.io, modify onError handler to take a string instead of WebSocket error code
-create SIOEvent callback type, implement event registry in clients, add test for event registration and callback
-update SIOEvent to use std::function and c++11, utilize cocos2d CC_CALLBACK method to bind selectors, this ensures that the *this reference is properly passed
-check for connect before sending or emitting in the client, cleanup some codes
-change connect logic to reuse existing socket connections instead of opening a new one
-implements get and set Tag methods for clients for easy reference
-improve endpoint handling, add endpoint tests to test layer
-additional error handling within socket disconnect error and failure to open connection
-fixes extracting endpoint from socket.io messages (in cases of the connect message, where there is 1 less colon for the connect message to the default namespace). Also fixes connecting to the default namespace "/" in the connectToEndpoint method
-add disconnect and onClose handlers to client so that onClose is called in the delegate
-add disconnect test methods to test layers
-change c-style casts to static_casts when using a CCDICT_FOREACH
-remove some unneeded namespace completion
-add usage documentation
-add handling for disconnect from server, cleanup some codes
-update comments and documentation in the socketiotest
-update includes so the NDK doesn't complain when compiling with c++11
-add socketio.cpp and test.cpp to the android makefiles
-update test URL to my public server, test script can also be found in my repo at https://github.com/hannon235/socket.io-testserver.git
Signed-off-by: Chris Hannon <himynameschris@gmail.com>
2013-06-26 10:40:01 +08:00
|
|
|
|
|
|
|
if(_connected) this->disconnect();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
std::string path = endpoint == "/" ? "" : endpoint;
|
|
|
|
|
|
|
|
std::string s = "0::" + path;
|
|
|
|
|
|
|
|
_ws->send(s);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SIOClientImpl::heartbeat(float dt) {
|
|
|
|
|
|
|
|
std::string s = "2::";
|
|
|
|
|
|
|
|
_ws->send(s);
|
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
log("Heartbeat sent");
|
Implements a socket.io client extension, adds a test case and updates the android makefiles.
Contains the following tasks:
-initial socket.io extension commit
-sioclientimpl subclasses websocket:delegate to respond to websocket events
-implement static connect methods and basic client creation
-move SocketIO class files into correct extension folder (network)
-create SocketIO test in TestCpp
-update project references
-add missing static modifier to connect method
-implement basic test methods
-update extensions tests with SocketIO test entry
-implement basic handshake and opensocket methods for SocketIO
-add Delegate class to handle callbacks, implement virtual Delegate methods in test
-implement socket and client registries for lookup when connecting to hosts and endpoints
-connect delegate onOpen method by separating impl creation from connection
-update test to demonstrate onOpen callback
-create send and emit methods, move SIOClient into header file, add send and emit methods to test
-implement basic socket.io message parsing
-improve logging for events and messages
-add logic to pull event name from payload
-schedule heartbeat to keep connection alive, scheduled for 90% of the heartbeat interval from the server for safety
-add onConnect handler to to catch socket.io onconnect vs websocket onopen
-add disconnect and disconnectFromEndpoint methods to properly disconnect and destroy objects
-modify SIOClientImpl to track _uri for easier lookup in registries
-connect handler for onMessage to message event from socket.io, modify onError handler to take a string instead of WebSocket error code
-create SIOEvent callback type, implement event registry in clients, add test for event registration and callback
-update SIOEvent to use std::function and c++11, utilize cocos2d CC_CALLBACK method to bind selectors, this ensures that the *this reference is properly passed
-check for connect before sending or emitting in the client, cleanup some codes
-change connect logic to reuse existing socket connections instead of opening a new one
-implements get and set Tag methods for clients for easy reference
-improve endpoint handling, add endpoint tests to test layer
-additional error handling within socket disconnect error and failure to open connection
-fixes extracting endpoint from socket.io messages (in cases of the connect message, where there is 1 less colon for the connect message to the default namespace). Also fixes connecting to the default namespace "/" in the connectToEndpoint method
-add disconnect and onClose handlers to client so that onClose is called in the delegate
-add disconnect test methods to test layers
-change c-style casts to static_casts when using a CCDICT_FOREACH
-remove some unneeded namespace completion
-add usage documentation
-add handling for disconnect from server, cleanup some codes
-update comments and documentation in the socketiotest
-update includes so the NDK doesn't complain when compiling with c++11
-add socketio.cpp and test.cpp to the android makefiles
-update test URL to my public server, test script can also be found in my repo at https://github.com/hannon235/socket.io-testserver.git
Signed-off-by: Chris Hannon <himynameschris@gmail.com>
2013-06-26 10:40:01 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIOClientImpl::send(std::string endpoint, std::string s) {
|
|
|
|
std::stringstream pre;
|
|
|
|
|
|
|
|
std::string path = endpoint == "/" ? "" : endpoint;
|
|
|
|
|
|
|
|
pre << "3::" << path << ":" << s;
|
|
|
|
|
|
|
|
std::string msg = pre.str();
|
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
log("sending message: %s", msg.c_str());
|
Implements a socket.io client extension, adds a test case and updates the android makefiles.
Contains the following tasks:
-initial socket.io extension commit
-sioclientimpl subclasses websocket:delegate to respond to websocket events
-implement static connect methods and basic client creation
-move SocketIO class files into correct extension folder (network)
-create SocketIO test in TestCpp
-update project references
-add missing static modifier to connect method
-implement basic test methods
-update extensions tests with SocketIO test entry
-implement basic handshake and opensocket methods for SocketIO
-add Delegate class to handle callbacks, implement virtual Delegate methods in test
-implement socket and client registries for lookup when connecting to hosts and endpoints
-connect delegate onOpen method by separating impl creation from connection
-update test to demonstrate onOpen callback
-create send and emit methods, move SIOClient into header file, add send and emit methods to test
-implement basic socket.io message parsing
-improve logging for events and messages
-add logic to pull event name from payload
-schedule heartbeat to keep connection alive, scheduled for 90% of the heartbeat interval from the server for safety
-add onConnect handler to to catch socket.io onconnect vs websocket onopen
-add disconnect and disconnectFromEndpoint methods to properly disconnect and destroy objects
-modify SIOClientImpl to track _uri for easier lookup in registries
-connect handler for onMessage to message event from socket.io, modify onError handler to take a string instead of WebSocket error code
-create SIOEvent callback type, implement event registry in clients, add test for event registration and callback
-update SIOEvent to use std::function and c++11, utilize cocos2d CC_CALLBACK method to bind selectors, this ensures that the *this reference is properly passed
-check for connect before sending or emitting in the client, cleanup some codes
-change connect logic to reuse existing socket connections instead of opening a new one
-implements get and set Tag methods for clients for easy reference
-improve endpoint handling, add endpoint tests to test layer
-additional error handling within socket disconnect error and failure to open connection
-fixes extracting endpoint from socket.io messages (in cases of the connect message, where there is 1 less colon for the connect message to the default namespace). Also fixes connecting to the default namespace "/" in the connectToEndpoint method
-add disconnect and onClose handlers to client so that onClose is called in the delegate
-add disconnect test methods to test layers
-change c-style casts to static_casts when using a CCDICT_FOREACH
-remove some unneeded namespace completion
-add usage documentation
-add handling for disconnect from server, cleanup some codes
-update comments and documentation in the socketiotest
-update includes so the NDK doesn't complain when compiling with c++11
-add socketio.cpp and test.cpp to the android makefiles
-update test URL to my public server, test script can also be found in my repo at https://github.com/hannon235/socket.io-testserver.git
Signed-off-by: Chris Hannon <himynameschris@gmail.com>
2013-06-26 10:40:01 +08:00
|
|
|
|
|
|
|
_ws->send(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SIOClientImpl::emit(std::string endpoint, std::string eventname, std::string args) {
|
|
|
|
|
|
|
|
std::stringstream pre;
|
|
|
|
|
|
|
|
std::string path = endpoint == "/" ? "" : endpoint;
|
|
|
|
|
|
|
|
pre << "5::" << path << ":{\"name\":\"" << eventname << "\",\"args\":" << args << "}";
|
|
|
|
|
|
|
|
std::string msg = pre.str();
|
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
log("emitting event with data: %s", msg.c_str());
|
Implements a socket.io client extension, adds a test case and updates the android makefiles.
Contains the following tasks:
-initial socket.io extension commit
-sioclientimpl subclasses websocket:delegate to respond to websocket events
-implement static connect methods and basic client creation
-move SocketIO class files into correct extension folder (network)
-create SocketIO test in TestCpp
-update project references
-add missing static modifier to connect method
-implement basic test methods
-update extensions tests with SocketIO test entry
-implement basic handshake and opensocket methods for SocketIO
-add Delegate class to handle callbacks, implement virtual Delegate methods in test
-implement socket and client registries for lookup when connecting to hosts and endpoints
-connect delegate onOpen method by separating impl creation from connection
-update test to demonstrate onOpen callback
-create send and emit methods, move SIOClient into header file, add send and emit methods to test
-implement basic socket.io message parsing
-improve logging for events and messages
-add logic to pull event name from payload
-schedule heartbeat to keep connection alive, scheduled for 90% of the heartbeat interval from the server for safety
-add onConnect handler to to catch socket.io onconnect vs websocket onopen
-add disconnect and disconnectFromEndpoint methods to properly disconnect and destroy objects
-modify SIOClientImpl to track _uri for easier lookup in registries
-connect handler for onMessage to message event from socket.io, modify onError handler to take a string instead of WebSocket error code
-create SIOEvent callback type, implement event registry in clients, add test for event registration and callback
-update SIOEvent to use std::function and c++11, utilize cocos2d CC_CALLBACK method to bind selectors, this ensures that the *this reference is properly passed
-check for connect before sending or emitting in the client, cleanup some codes
-change connect logic to reuse existing socket connections instead of opening a new one
-implements get and set Tag methods for clients for easy reference
-improve endpoint handling, add endpoint tests to test layer
-additional error handling within socket disconnect error and failure to open connection
-fixes extracting endpoint from socket.io messages (in cases of the connect message, where there is 1 less colon for the connect message to the default namespace). Also fixes connecting to the default namespace "/" in the connectToEndpoint method
-add disconnect and onClose handlers to client so that onClose is called in the delegate
-add disconnect test methods to test layers
-change c-style casts to static_casts when using a CCDICT_FOREACH
-remove some unneeded namespace completion
-add usage documentation
-add handling for disconnect from server, cleanup some codes
-update comments and documentation in the socketiotest
-update includes so the NDK doesn't complain when compiling with c++11
-add socketio.cpp and test.cpp to the android makefiles
-update test URL to my public server, test script can also be found in my repo at https://github.com/hannon235/socket.io-testserver.git
Signed-off-by: Chris Hannon <himynameschris@gmail.com>
2013-06-26 10:40:01 +08:00
|
|
|
|
|
|
|
_ws->send(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SIOClientImpl::onOpen(cocos2d::extension::WebSocket* ws) {
|
|
|
|
|
|
|
|
_connected = true;
|
|
|
|
|
|
|
|
SocketIO::instance()->addSocket(_uri, this);
|
|
|
|
|
|
|
|
DictElement* e = NULL;
|
|
|
|
|
|
|
|
CCDICT_FOREACH(_clients, e) {
|
|
|
|
|
|
|
|
SIOClient *c = static_cast<SIOClient*>(e->getObject());
|
|
|
|
|
|
|
|
c->onOpen();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-07-15 16:14:26 +08:00
|
|
|
Director::getInstance()->getScheduler()->scheduleSelector(schedule_selector(SIOClientImpl::heartbeat), this, (_heartbeat * .9), false);
|
Implements a socket.io client extension, adds a test case and updates the android makefiles.
Contains the following tasks:
-initial socket.io extension commit
-sioclientimpl subclasses websocket:delegate to respond to websocket events
-implement static connect methods and basic client creation
-move SocketIO class files into correct extension folder (network)
-create SocketIO test in TestCpp
-update project references
-add missing static modifier to connect method
-implement basic test methods
-update extensions tests with SocketIO test entry
-implement basic handshake and opensocket methods for SocketIO
-add Delegate class to handle callbacks, implement virtual Delegate methods in test
-implement socket and client registries for lookup when connecting to hosts and endpoints
-connect delegate onOpen method by separating impl creation from connection
-update test to demonstrate onOpen callback
-create send and emit methods, move SIOClient into header file, add send and emit methods to test
-implement basic socket.io message parsing
-improve logging for events and messages
-add logic to pull event name from payload
-schedule heartbeat to keep connection alive, scheduled for 90% of the heartbeat interval from the server for safety
-add onConnect handler to to catch socket.io onconnect vs websocket onopen
-add disconnect and disconnectFromEndpoint methods to properly disconnect and destroy objects
-modify SIOClientImpl to track _uri for easier lookup in registries
-connect handler for onMessage to message event from socket.io, modify onError handler to take a string instead of WebSocket error code
-create SIOEvent callback type, implement event registry in clients, add test for event registration and callback
-update SIOEvent to use std::function and c++11, utilize cocos2d CC_CALLBACK method to bind selectors, this ensures that the *this reference is properly passed
-check for connect before sending or emitting in the client, cleanup some codes
-change connect logic to reuse existing socket connections instead of opening a new one
-implements get and set Tag methods for clients for easy reference
-improve endpoint handling, add endpoint tests to test layer
-additional error handling within socket disconnect error and failure to open connection
-fixes extracting endpoint from socket.io messages (in cases of the connect message, where there is 1 less colon for the connect message to the default namespace). Also fixes connecting to the default namespace "/" in the connectToEndpoint method
-add disconnect and onClose handlers to client so that onClose is called in the delegate
-add disconnect test methods to test layers
-change c-style casts to static_casts when using a CCDICT_FOREACH
-remove some unneeded namespace completion
-add usage documentation
-add handling for disconnect from server, cleanup some codes
-update comments and documentation in the socketiotest
-update includes so the NDK doesn't complain when compiling with c++11
-add socketio.cpp and test.cpp to the android makefiles
-update test URL to my public server, test script can also be found in my repo at https://github.com/hannon235/socket.io-testserver.git
Signed-off-by: Chris Hannon <himynameschris@gmail.com>
2013-06-26 10:40:01 +08:00
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
log("SIOClientImpl::onOpen socket connected!");
|
Implements a socket.io client extension, adds a test case and updates the android makefiles.
Contains the following tasks:
-initial socket.io extension commit
-sioclientimpl subclasses websocket:delegate to respond to websocket events
-implement static connect methods and basic client creation
-move SocketIO class files into correct extension folder (network)
-create SocketIO test in TestCpp
-update project references
-add missing static modifier to connect method
-implement basic test methods
-update extensions tests with SocketIO test entry
-implement basic handshake and opensocket methods for SocketIO
-add Delegate class to handle callbacks, implement virtual Delegate methods in test
-implement socket and client registries for lookup when connecting to hosts and endpoints
-connect delegate onOpen method by separating impl creation from connection
-update test to demonstrate onOpen callback
-create send and emit methods, move SIOClient into header file, add send and emit methods to test
-implement basic socket.io message parsing
-improve logging for events and messages
-add logic to pull event name from payload
-schedule heartbeat to keep connection alive, scheduled for 90% of the heartbeat interval from the server for safety
-add onConnect handler to to catch socket.io onconnect vs websocket onopen
-add disconnect and disconnectFromEndpoint methods to properly disconnect and destroy objects
-modify SIOClientImpl to track _uri for easier lookup in registries
-connect handler for onMessage to message event from socket.io, modify onError handler to take a string instead of WebSocket error code
-create SIOEvent callback type, implement event registry in clients, add test for event registration and callback
-update SIOEvent to use std::function and c++11, utilize cocos2d CC_CALLBACK method to bind selectors, this ensures that the *this reference is properly passed
-check for connect before sending or emitting in the client, cleanup some codes
-change connect logic to reuse existing socket connections instead of opening a new one
-implements get and set Tag methods for clients for easy reference
-improve endpoint handling, add endpoint tests to test layer
-additional error handling within socket disconnect error and failure to open connection
-fixes extracting endpoint from socket.io messages (in cases of the connect message, where there is 1 less colon for the connect message to the default namespace). Also fixes connecting to the default namespace "/" in the connectToEndpoint method
-add disconnect and onClose handlers to client so that onClose is called in the delegate
-add disconnect test methods to test layers
-change c-style casts to static_casts when using a CCDICT_FOREACH
-remove some unneeded namespace completion
-add usage documentation
-add handling for disconnect from server, cleanup some codes
-update comments and documentation in the socketiotest
-update includes so the NDK doesn't complain when compiling with c++11
-add socketio.cpp and test.cpp to the android makefiles
-update test URL to my public server, test script can also be found in my repo at https://github.com/hannon235/socket.io-testserver.git
Signed-off-by: Chris Hannon <himynameschris@gmail.com>
2013-06-26 10:40:01 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SIOClientImpl::onMessage(cocos2d::extension::WebSocket* ws, const cocos2d::extension::WebSocket::Data& data) {
|
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
log("SIOClientImpl::onMessage received: %s", data.bytes);
|
Implements a socket.io client extension, adds a test case and updates the android makefiles.
Contains the following tasks:
-initial socket.io extension commit
-sioclientimpl subclasses websocket:delegate to respond to websocket events
-implement static connect methods and basic client creation
-move SocketIO class files into correct extension folder (network)
-create SocketIO test in TestCpp
-update project references
-add missing static modifier to connect method
-implement basic test methods
-update extensions tests with SocketIO test entry
-implement basic handshake and opensocket methods for SocketIO
-add Delegate class to handle callbacks, implement virtual Delegate methods in test
-implement socket and client registries for lookup when connecting to hosts and endpoints
-connect delegate onOpen method by separating impl creation from connection
-update test to demonstrate onOpen callback
-create send and emit methods, move SIOClient into header file, add send and emit methods to test
-implement basic socket.io message parsing
-improve logging for events and messages
-add logic to pull event name from payload
-schedule heartbeat to keep connection alive, scheduled for 90% of the heartbeat interval from the server for safety
-add onConnect handler to to catch socket.io onconnect vs websocket onopen
-add disconnect and disconnectFromEndpoint methods to properly disconnect and destroy objects
-modify SIOClientImpl to track _uri for easier lookup in registries
-connect handler for onMessage to message event from socket.io, modify onError handler to take a string instead of WebSocket error code
-create SIOEvent callback type, implement event registry in clients, add test for event registration and callback
-update SIOEvent to use std::function and c++11, utilize cocos2d CC_CALLBACK method to bind selectors, this ensures that the *this reference is properly passed
-check for connect before sending or emitting in the client, cleanup some codes
-change connect logic to reuse existing socket connections instead of opening a new one
-implements get and set Tag methods for clients for easy reference
-improve endpoint handling, add endpoint tests to test layer
-additional error handling within socket disconnect error and failure to open connection
-fixes extracting endpoint from socket.io messages (in cases of the connect message, where there is 1 less colon for the connect message to the default namespace). Also fixes connecting to the default namespace "/" in the connectToEndpoint method
-add disconnect and onClose handlers to client so that onClose is called in the delegate
-add disconnect test methods to test layers
-change c-style casts to static_casts when using a CCDICT_FOREACH
-remove some unneeded namespace completion
-add usage documentation
-add handling for disconnect from server, cleanup some codes
-update comments and documentation in the socketiotest
-update includes so the NDK doesn't complain when compiling with c++11
-add socketio.cpp and test.cpp to the android makefiles
-update test URL to my public server, test script can also be found in my repo at https://github.com/hannon235/socket.io-testserver.git
Signed-off-by: Chris Hannon <himynameschris@gmail.com>
2013-06-26 10:40:01 +08:00
|
|
|
|
|
|
|
int control = atoi(&data.bytes[0]);
|
|
|
|
|
|
|
|
std::string payload, msgid, endpoint, s_data, eventname;
|
|
|
|
payload = data.bytes;
|
|
|
|
|
|
|
|
int pos, pos2;
|
|
|
|
|
|
|
|
pos = payload.find(":");
|
|
|
|
if(pos >=0 ) {
|
|
|
|
payload.erase(0, pos+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
pos = payload.find(":");
|
|
|
|
if(pos > 0 ) {
|
|
|
|
msgid = atoi(payload.substr(0, pos+1).c_str());
|
|
|
|
}
|
|
|
|
payload.erase(0, pos+1);
|
|
|
|
|
|
|
|
pos = payload.find(":");
|
|
|
|
if(pos >= 0) {
|
|
|
|
|
|
|
|
endpoint = payload.substr(0, pos);
|
|
|
|
payload.erase(0, pos+1);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
endpoint = payload;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(endpoint == "") endpoint = "/";
|
|
|
|
|
|
|
|
|
|
|
|
s_data = payload;
|
|
|
|
SIOClient *c = NULL;
|
|
|
|
c = getClient(endpoint);
|
2013-07-24 06:20:22 +08:00
|
|
|
if(c == NULL) log("SIOClientImpl::onMessage client lookup returned NULL");
|
Implements a socket.io client extension, adds a test case and updates the android makefiles.
Contains the following tasks:
-initial socket.io extension commit
-sioclientimpl subclasses websocket:delegate to respond to websocket events
-implement static connect methods and basic client creation
-move SocketIO class files into correct extension folder (network)
-create SocketIO test in TestCpp
-update project references
-add missing static modifier to connect method
-implement basic test methods
-update extensions tests with SocketIO test entry
-implement basic handshake and opensocket methods for SocketIO
-add Delegate class to handle callbacks, implement virtual Delegate methods in test
-implement socket and client registries for lookup when connecting to hosts and endpoints
-connect delegate onOpen method by separating impl creation from connection
-update test to demonstrate onOpen callback
-create send and emit methods, move SIOClient into header file, add send and emit methods to test
-implement basic socket.io message parsing
-improve logging for events and messages
-add logic to pull event name from payload
-schedule heartbeat to keep connection alive, scheduled for 90% of the heartbeat interval from the server for safety
-add onConnect handler to to catch socket.io onconnect vs websocket onopen
-add disconnect and disconnectFromEndpoint methods to properly disconnect and destroy objects
-modify SIOClientImpl to track _uri for easier lookup in registries
-connect handler for onMessage to message event from socket.io, modify onError handler to take a string instead of WebSocket error code
-create SIOEvent callback type, implement event registry in clients, add test for event registration and callback
-update SIOEvent to use std::function and c++11, utilize cocos2d CC_CALLBACK method to bind selectors, this ensures that the *this reference is properly passed
-check for connect before sending or emitting in the client, cleanup some codes
-change connect logic to reuse existing socket connections instead of opening a new one
-implements get and set Tag methods for clients for easy reference
-improve endpoint handling, add endpoint tests to test layer
-additional error handling within socket disconnect error and failure to open connection
-fixes extracting endpoint from socket.io messages (in cases of the connect message, where there is 1 less colon for the connect message to the default namespace). Also fixes connecting to the default namespace "/" in the connectToEndpoint method
-add disconnect and onClose handlers to client so that onClose is called in the delegate
-add disconnect test methods to test layers
-change c-style casts to static_casts when using a CCDICT_FOREACH
-remove some unneeded namespace completion
-add usage documentation
-add handling for disconnect from server, cleanup some codes
-update comments and documentation in the socketiotest
-update includes so the NDK doesn't complain when compiling with c++11
-add socketio.cpp and test.cpp to the android makefiles
-update test URL to my public server, test script can also be found in my repo at https://github.com/hannon235/socket.io-testserver.git
Signed-off-by: Chris Hannon <himynameschris@gmail.com>
2013-06-26 10:40:01 +08:00
|
|
|
|
|
|
|
switch(control) {
|
|
|
|
case 0:
|
2013-07-24 06:20:22 +08:00
|
|
|
log("Received Disconnect Signal for Endpoint: %s\n", endpoint.c_str());
|
Implements a socket.io client extension, adds a test case and updates the android makefiles.
Contains the following tasks:
-initial socket.io extension commit
-sioclientimpl subclasses websocket:delegate to respond to websocket events
-implement static connect methods and basic client creation
-move SocketIO class files into correct extension folder (network)
-create SocketIO test in TestCpp
-update project references
-add missing static modifier to connect method
-implement basic test methods
-update extensions tests with SocketIO test entry
-implement basic handshake and opensocket methods for SocketIO
-add Delegate class to handle callbacks, implement virtual Delegate methods in test
-implement socket and client registries for lookup when connecting to hosts and endpoints
-connect delegate onOpen method by separating impl creation from connection
-update test to demonstrate onOpen callback
-create send and emit methods, move SIOClient into header file, add send and emit methods to test
-implement basic socket.io message parsing
-improve logging for events and messages
-add logic to pull event name from payload
-schedule heartbeat to keep connection alive, scheduled for 90% of the heartbeat interval from the server for safety
-add onConnect handler to to catch socket.io onconnect vs websocket onopen
-add disconnect and disconnectFromEndpoint methods to properly disconnect and destroy objects
-modify SIOClientImpl to track _uri for easier lookup in registries
-connect handler for onMessage to message event from socket.io, modify onError handler to take a string instead of WebSocket error code
-create SIOEvent callback type, implement event registry in clients, add test for event registration and callback
-update SIOEvent to use std::function and c++11, utilize cocos2d CC_CALLBACK method to bind selectors, this ensures that the *this reference is properly passed
-check for connect before sending or emitting in the client, cleanup some codes
-change connect logic to reuse existing socket connections instead of opening a new one
-implements get and set Tag methods for clients for easy reference
-improve endpoint handling, add endpoint tests to test layer
-additional error handling within socket disconnect error and failure to open connection
-fixes extracting endpoint from socket.io messages (in cases of the connect message, where there is 1 less colon for the connect message to the default namespace). Also fixes connecting to the default namespace "/" in the connectToEndpoint method
-add disconnect and onClose handlers to client so that onClose is called in the delegate
-add disconnect test methods to test layers
-change c-style casts to static_casts when using a CCDICT_FOREACH
-remove some unneeded namespace completion
-add usage documentation
-add handling for disconnect from server, cleanup some codes
-update comments and documentation in the socketiotest
-update includes so the NDK doesn't complain when compiling with c++11
-add socketio.cpp and test.cpp to the android makefiles
-update test URL to my public server, test script can also be found in my repo at https://github.com/hannon235/socket.io-testserver.git
Signed-off-by: Chris Hannon <himynameschris@gmail.com>
2013-06-26 10:40:01 +08:00
|
|
|
if(c) c->receivedDisconnect();
|
|
|
|
disconnectFromEndpoint(endpoint);
|
|
|
|
break;
|
|
|
|
case 1:
|
2013-07-24 06:20:22 +08:00
|
|
|
log("Connected to endpoint: %s \n",endpoint.c_str());
|
Implements a socket.io client extension, adds a test case and updates the android makefiles.
Contains the following tasks:
-initial socket.io extension commit
-sioclientimpl subclasses websocket:delegate to respond to websocket events
-implement static connect methods and basic client creation
-move SocketIO class files into correct extension folder (network)
-create SocketIO test in TestCpp
-update project references
-add missing static modifier to connect method
-implement basic test methods
-update extensions tests with SocketIO test entry
-implement basic handshake and opensocket methods for SocketIO
-add Delegate class to handle callbacks, implement virtual Delegate methods in test
-implement socket and client registries for lookup when connecting to hosts and endpoints
-connect delegate onOpen method by separating impl creation from connection
-update test to demonstrate onOpen callback
-create send and emit methods, move SIOClient into header file, add send and emit methods to test
-implement basic socket.io message parsing
-improve logging for events and messages
-add logic to pull event name from payload
-schedule heartbeat to keep connection alive, scheduled for 90% of the heartbeat interval from the server for safety
-add onConnect handler to to catch socket.io onconnect vs websocket onopen
-add disconnect and disconnectFromEndpoint methods to properly disconnect and destroy objects
-modify SIOClientImpl to track _uri for easier lookup in registries
-connect handler for onMessage to message event from socket.io, modify onError handler to take a string instead of WebSocket error code
-create SIOEvent callback type, implement event registry in clients, add test for event registration and callback
-update SIOEvent to use std::function and c++11, utilize cocos2d CC_CALLBACK method to bind selectors, this ensures that the *this reference is properly passed
-check for connect before sending or emitting in the client, cleanup some codes
-change connect logic to reuse existing socket connections instead of opening a new one
-implements get and set Tag methods for clients for easy reference
-improve endpoint handling, add endpoint tests to test layer
-additional error handling within socket disconnect error and failure to open connection
-fixes extracting endpoint from socket.io messages (in cases of the connect message, where there is 1 less colon for the connect message to the default namespace). Also fixes connecting to the default namespace "/" in the connectToEndpoint method
-add disconnect and onClose handlers to client so that onClose is called in the delegate
-add disconnect test methods to test layers
-change c-style casts to static_casts when using a CCDICT_FOREACH
-remove some unneeded namespace completion
-add usage documentation
-add handling for disconnect from server, cleanup some codes
-update comments and documentation in the socketiotest
-update includes so the NDK doesn't complain when compiling with c++11
-add socketio.cpp and test.cpp to the android makefiles
-update test URL to my public server, test script can also be found in my repo at https://github.com/hannon235/socket.io-testserver.git
Signed-off-by: Chris Hannon <himynameschris@gmail.com>
2013-06-26 10:40:01 +08:00
|
|
|
if(c) c->onConnect();
|
|
|
|
break;
|
|
|
|
case 2:
|
2013-07-24 06:20:22 +08:00
|
|
|
log("Heartbeat received\n");
|
Implements a socket.io client extension, adds a test case and updates the android makefiles.
Contains the following tasks:
-initial socket.io extension commit
-sioclientimpl subclasses websocket:delegate to respond to websocket events
-implement static connect methods and basic client creation
-move SocketIO class files into correct extension folder (network)
-create SocketIO test in TestCpp
-update project references
-add missing static modifier to connect method
-implement basic test methods
-update extensions tests with SocketIO test entry
-implement basic handshake and opensocket methods for SocketIO
-add Delegate class to handle callbacks, implement virtual Delegate methods in test
-implement socket and client registries for lookup when connecting to hosts and endpoints
-connect delegate onOpen method by separating impl creation from connection
-update test to demonstrate onOpen callback
-create send and emit methods, move SIOClient into header file, add send and emit methods to test
-implement basic socket.io message parsing
-improve logging for events and messages
-add logic to pull event name from payload
-schedule heartbeat to keep connection alive, scheduled for 90% of the heartbeat interval from the server for safety
-add onConnect handler to to catch socket.io onconnect vs websocket onopen
-add disconnect and disconnectFromEndpoint methods to properly disconnect and destroy objects
-modify SIOClientImpl to track _uri for easier lookup in registries
-connect handler for onMessage to message event from socket.io, modify onError handler to take a string instead of WebSocket error code
-create SIOEvent callback type, implement event registry in clients, add test for event registration and callback
-update SIOEvent to use std::function and c++11, utilize cocos2d CC_CALLBACK method to bind selectors, this ensures that the *this reference is properly passed
-check for connect before sending or emitting in the client, cleanup some codes
-change connect logic to reuse existing socket connections instead of opening a new one
-implements get and set Tag methods for clients for easy reference
-improve endpoint handling, add endpoint tests to test layer
-additional error handling within socket disconnect error and failure to open connection
-fixes extracting endpoint from socket.io messages (in cases of the connect message, where there is 1 less colon for the connect message to the default namespace). Also fixes connecting to the default namespace "/" in the connectToEndpoint method
-add disconnect and onClose handlers to client so that onClose is called in the delegate
-add disconnect test methods to test layers
-change c-style casts to static_casts when using a CCDICT_FOREACH
-remove some unneeded namespace completion
-add usage documentation
-add handling for disconnect from server, cleanup some codes
-update comments and documentation in the socketiotest
-update includes so the NDK doesn't complain when compiling with c++11
-add socketio.cpp and test.cpp to the android makefiles
-update test URL to my public server, test script can also be found in my repo at https://github.com/hannon235/socket.io-testserver.git
Signed-off-by: Chris Hannon <himynameschris@gmail.com>
2013-06-26 10:40:01 +08:00
|
|
|
break;
|
|
|
|
case 3:
|
2013-07-24 06:20:22 +08:00
|
|
|
log("Message received: %s \n", s_data.c_str());
|
Implements a socket.io client extension, adds a test case and updates the android makefiles.
Contains the following tasks:
-initial socket.io extension commit
-sioclientimpl subclasses websocket:delegate to respond to websocket events
-implement static connect methods and basic client creation
-move SocketIO class files into correct extension folder (network)
-create SocketIO test in TestCpp
-update project references
-add missing static modifier to connect method
-implement basic test methods
-update extensions tests with SocketIO test entry
-implement basic handshake and opensocket methods for SocketIO
-add Delegate class to handle callbacks, implement virtual Delegate methods in test
-implement socket and client registries for lookup when connecting to hosts and endpoints
-connect delegate onOpen method by separating impl creation from connection
-update test to demonstrate onOpen callback
-create send and emit methods, move SIOClient into header file, add send and emit methods to test
-implement basic socket.io message parsing
-improve logging for events and messages
-add logic to pull event name from payload
-schedule heartbeat to keep connection alive, scheduled for 90% of the heartbeat interval from the server for safety
-add onConnect handler to to catch socket.io onconnect vs websocket onopen
-add disconnect and disconnectFromEndpoint methods to properly disconnect and destroy objects
-modify SIOClientImpl to track _uri for easier lookup in registries
-connect handler for onMessage to message event from socket.io, modify onError handler to take a string instead of WebSocket error code
-create SIOEvent callback type, implement event registry in clients, add test for event registration and callback
-update SIOEvent to use std::function and c++11, utilize cocos2d CC_CALLBACK method to bind selectors, this ensures that the *this reference is properly passed
-check for connect before sending or emitting in the client, cleanup some codes
-change connect logic to reuse existing socket connections instead of opening a new one
-implements get and set Tag methods for clients for easy reference
-improve endpoint handling, add endpoint tests to test layer
-additional error handling within socket disconnect error and failure to open connection
-fixes extracting endpoint from socket.io messages (in cases of the connect message, where there is 1 less colon for the connect message to the default namespace). Also fixes connecting to the default namespace "/" in the connectToEndpoint method
-add disconnect and onClose handlers to client so that onClose is called in the delegate
-add disconnect test methods to test layers
-change c-style casts to static_casts when using a CCDICT_FOREACH
-remove some unneeded namespace completion
-add usage documentation
-add handling for disconnect from server, cleanup some codes
-update comments and documentation in the socketiotest
-update includes so the NDK doesn't complain when compiling with c++11
-add socketio.cpp and test.cpp to the android makefiles
-update test URL to my public server, test script can also be found in my repo at https://github.com/hannon235/socket.io-testserver.git
Signed-off-by: Chris Hannon <himynameschris@gmail.com>
2013-06-26 10:40:01 +08:00
|
|
|
if(c) c->getDelegate()->onMessage(c, s_data);
|
|
|
|
break;
|
|
|
|
case 4:
|
2013-07-24 06:20:22 +08:00
|
|
|
log("JSON Message Received: %s \n", s_data.c_str());
|
Implements a socket.io client extension, adds a test case and updates the android makefiles.
Contains the following tasks:
-initial socket.io extension commit
-sioclientimpl subclasses websocket:delegate to respond to websocket events
-implement static connect methods and basic client creation
-move SocketIO class files into correct extension folder (network)
-create SocketIO test in TestCpp
-update project references
-add missing static modifier to connect method
-implement basic test methods
-update extensions tests with SocketIO test entry
-implement basic handshake and opensocket methods for SocketIO
-add Delegate class to handle callbacks, implement virtual Delegate methods in test
-implement socket and client registries for lookup when connecting to hosts and endpoints
-connect delegate onOpen method by separating impl creation from connection
-update test to demonstrate onOpen callback
-create send and emit methods, move SIOClient into header file, add send and emit methods to test
-implement basic socket.io message parsing
-improve logging for events and messages
-add logic to pull event name from payload
-schedule heartbeat to keep connection alive, scheduled for 90% of the heartbeat interval from the server for safety
-add onConnect handler to to catch socket.io onconnect vs websocket onopen
-add disconnect and disconnectFromEndpoint methods to properly disconnect and destroy objects
-modify SIOClientImpl to track _uri for easier lookup in registries
-connect handler for onMessage to message event from socket.io, modify onError handler to take a string instead of WebSocket error code
-create SIOEvent callback type, implement event registry in clients, add test for event registration and callback
-update SIOEvent to use std::function and c++11, utilize cocos2d CC_CALLBACK method to bind selectors, this ensures that the *this reference is properly passed
-check for connect before sending or emitting in the client, cleanup some codes
-change connect logic to reuse existing socket connections instead of opening a new one
-implements get and set Tag methods for clients for easy reference
-improve endpoint handling, add endpoint tests to test layer
-additional error handling within socket disconnect error and failure to open connection
-fixes extracting endpoint from socket.io messages (in cases of the connect message, where there is 1 less colon for the connect message to the default namespace). Also fixes connecting to the default namespace "/" in the connectToEndpoint method
-add disconnect and onClose handlers to client so that onClose is called in the delegate
-add disconnect test methods to test layers
-change c-style casts to static_casts when using a CCDICT_FOREACH
-remove some unneeded namespace completion
-add usage documentation
-add handling for disconnect from server, cleanup some codes
-update comments and documentation in the socketiotest
-update includes so the NDK doesn't complain when compiling with c++11
-add socketio.cpp and test.cpp to the android makefiles
-update test URL to my public server, test script can also be found in my repo at https://github.com/hannon235/socket.io-testserver.git
Signed-off-by: Chris Hannon <himynameschris@gmail.com>
2013-06-26 10:40:01 +08:00
|
|
|
if(c) c->getDelegate()->onMessage(c, s_data);
|
|
|
|
break;
|
|
|
|
case 5:
|
2013-07-24 06:20:22 +08:00
|
|
|
log("Event Received with data: %s \n", s_data.c_str());
|
Implements a socket.io client extension, adds a test case and updates the android makefiles.
Contains the following tasks:
-initial socket.io extension commit
-sioclientimpl subclasses websocket:delegate to respond to websocket events
-implement static connect methods and basic client creation
-move SocketIO class files into correct extension folder (network)
-create SocketIO test in TestCpp
-update project references
-add missing static modifier to connect method
-implement basic test methods
-update extensions tests with SocketIO test entry
-implement basic handshake and opensocket methods for SocketIO
-add Delegate class to handle callbacks, implement virtual Delegate methods in test
-implement socket and client registries for lookup when connecting to hosts and endpoints
-connect delegate onOpen method by separating impl creation from connection
-update test to demonstrate onOpen callback
-create send and emit methods, move SIOClient into header file, add send and emit methods to test
-implement basic socket.io message parsing
-improve logging for events and messages
-add logic to pull event name from payload
-schedule heartbeat to keep connection alive, scheduled for 90% of the heartbeat interval from the server for safety
-add onConnect handler to to catch socket.io onconnect vs websocket onopen
-add disconnect and disconnectFromEndpoint methods to properly disconnect and destroy objects
-modify SIOClientImpl to track _uri for easier lookup in registries
-connect handler for onMessage to message event from socket.io, modify onError handler to take a string instead of WebSocket error code
-create SIOEvent callback type, implement event registry in clients, add test for event registration and callback
-update SIOEvent to use std::function and c++11, utilize cocos2d CC_CALLBACK method to bind selectors, this ensures that the *this reference is properly passed
-check for connect before sending or emitting in the client, cleanup some codes
-change connect logic to reuse existing socket connections instead of opening a new one
-implements get and set Tag methods for clients for easy reference
-improve endpoint handling, add endpoint tests to test layer
-additional error handling within socket disconnect error and failure to open connection
-fixes extracting endpoint from socket.io messages (in cases of the connect message, where there is 1 less colon for the connect message to the default namespace). Also fixes connecting to the default namespace "/" in the connectToEndpoint method
-add disconnect and onClose handlers to client so that onClose is called in the delegate
-add disconnect test methods to test layers
-change c-style casts to static_casts when using a CCDICT_FOREACH
-remove some unneeded namespace completion
-add usage documentation
-add handling for disconnect from server, cleanup some codes
-update comments and documentation in the socketiotest
-update includes so the NDK doesn't complain when compiling with c++11
-add socketio.cpp and test.cpp to the android makefiles
-update test URL to my public server, test script can also be found in my repo at https://github.com/hannon235/socket.io-testserver.git
Signed-off-by: Chris Hannon <himynameschris@gmail.com>
2013-06-26 10:40:01 +08:00
|
|
|
|
|
|
|
if(c) {
|
|
|
|
eventname = "";
|
|
|
|
pos = s_data.find(":");
|
|
|
|
pos2 = s_data.find(",");
|
|
|
|
if(pos2 > pos) {
|
|
|
|
s_data = s_data.substr(pos+1, pos2-pos-1);
|
|
|
|
std::remove_copy(s_data.begin(), s_data.end(),
|
|
|
|
std::back_inserter(eventname), '"');
|
|
|
|
}
|
|
|
|
|
|
|
|
c->fireEvent(eventname, payload);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case 6:
|
2013-07-24 06:20:22 +08:00
|
|
|
log("Message Ack\n");
|
Implements a socket.io client extension, adds a test case and updates the android makefiles.
Contains the following tasks:
-initial socket.io extension commit
-sioclientimpl subclasses websocket:delegate to respond to websocket events
-implement static connect methods and basic client creation
-move SocketIO class files into correct extension folder (network)
-create SocketIO test in TestCpp
-update project references
-add missing static modifier to connect method
-implement basic test methods
-update extensions tests with SocketIO test entry
-implement basic handshake and opensocket methods for SocketIO
-add Delegate class to handle callbacks, implement virtual Delegate methods in test
-implement socket and client registries for lookup when connecting to hosts and endpoints
-connect delegate onOpen method by separating impl creation from connection
-update test to demonstrate onOpen callback
-create send and emit methods, move SIOClient into header file, add send and emit methods to test
-implement basic socket.io message parsing
-improve logging for events and messages
-add logic to pull event name from payload
-schedule heartbeat to keep connection alive, scheduled for 90% of the heartbeat interval from the server for safety
-add onConnect handler to to catch socket.io onconnect vs websocket onopen
-add disconnect and disconnectFromEndpoint methods to properly disconnect and destroy objects
-modify SIOClientImpl to track _uri for easier lookup in registries
-connect handler for onMessage to message event from socket.io, modify onError handler to take a string instead of WebSocket error code
-create SIOEvent callback type, implement event registry in clients, add test for event registration and callback
-update SIOEvent to use std::function and c++11, utilize cocos2d CC_CALLBACK method to bind selectors, this ensures that the *this reference is properly passed
-check for connect before sending or emitting in the client, cleanup some codes
-change connect logic to reuse existing socket connections instead of opening a new one
-implements get and set Tag methods for clients for easy reference
-improve endpoint handling, add endpoint tests to test layer
-additional error handling within socket disconnect error and failure to open connection
-fixes extracting endpoint from socket.io messages (in cases of the connect message, where there is 1 less colon for the connect message to the default namespace). Also fixes connecting to the default namespace "/" in the connectToEndpoint method
-add disconnect and onClose handlers to client so that onClose is called in the delegate
-add disconnect test methods to test layers
-change c-style casts to static_casts when using a CCDICT_FOREACH
-remove some unneeded namespace completion
-add usage documentation
-add handling for disconnect from server, cleanup some codes
-update comments and documentation in the socketiotest
-update includes so the NDK doesn't complain when compiling with c++11
-add socketio.cpp and test.cpp to the android makefiles
-update test URL to my public server, test script can also be found in my repo at https://github.com/hannon235/socket.io-testserver.git
Signed-off-by: Chris Hannon <himynameschris@gmail.com>
2013-06-26 10:40:01 +08:00
|
|
|
break;
|
|
|
|
case 7:
|
2013-07-24 06:20:22 +08:00
|
|
|
log("Error\n");
|
Implements a socket.io client extension, adds a test case and updates the android makefiles.
Contains the following tasks:
-initial socket.io extension commit
-sioclientimpl subclasses websocket:delegate to respond to websocket events
-implement static connect methods and basic client creation
-move SocketIO class files into correct extension folder (network)
-create SocketIO test in TestCpp
-update project references
-add missing static modifier to connect method
-implement basic test methods
-update extensions tests with SocketIO test entry
-implement basic handshake and opensocket methods for SocketIO
-add Delegate class to handle callbacks, implement virtual Delegate methods in test
-implement socket and client registries for lookup when connecting to hosts and endpoints
-connect delegate onOpen method by separating impl creation from connection
-update test to demonstrate onOpen callback
-create send and emit methods, move SIOClient into header file, add send and emit methods to test
-implement basic socket.io message parsing
-improve logging for events and messages
-add logic to pull event name from payload
-schedule heartbeat to keep connection alive, scheduled for 90% of the heartbeat interval from the server for safety
-add onConnect handler to to catch socket.io onconnect vs websocket onopen
-add disconnect and disconnectFromEndpoint methods to properly disconnect and destroy objects
-modify SIOClientImpl to track _uri for easier lookup in registries
-connect handler for onMessage to message event from socket.io, modify onError handler to take a string instead of WebSocket error code
-create SIOEvent callback type, implement event registry in clients, add test for event registration and callback
-update SIOEvent to use std::function and c++11, utilize cocos2d CC_CALLBACK method to bind selectors, this ensures that the *this reference is properly passed
-check for connect before sending or emitting in the client, cleanup some codes
-change connect logic to reuse existing socket connections instead of opening a new one
-implements get and set Tag methods for clients for easy reference
-improve endpoint handling, add endpoint tests to test layer
-additional error handling within socket disconnect error and failure to open connection
-fixes extracting endpoint from socket.io messages (in cases of the connect message, where there is 1 less colon for the connect message to the default namespace). Also fixes connecting to the default namespace "/" in the connectToEndpoint method
-add disconnect and onClose handlers to client so that onClose is called in the delegate
-add disconnect test methods to test layers
-change c-style casts to static_casts when using a CCDICT_FOREACH
-remove some unneeded namespace completion
-add usage documentation
-add handling for disconnect from server, cleanup some codes
-update comments and documentation in the socketiotest
-update includes so the NDK doesn't complain when compiling with c++11
-add socketio.cpp and test.cpp to the android makefiles
-update test URL to my public server, test script can also be found in my repo at https://github.com/hannon235/socket.io-testserver.git
Signed-off-by: Chris Hannon <himynameschris@gmail.com>
2013-06-26 10:40:01 +08:00
|
|
|
if(c) c->getDelegate()->onError(c, s_data);
|
|
|
|
break;
|
|
|
|
case 8:
|
2013-07-24 06:20:22 +08:00
|
|
|
log("Noop\n");
|
Implements a socket.io client extension, adds a test case and updates the android makefiles.
Contains the following tasks:
-initial socket.io extension commit
-sioclientimpl subclasses websocket:delegate to respond to websocket events
-implement static connect methods and basic client creation
-move SocketIO class files into correct extension folder (network)
-create SocketIO test in TestCpp
-update project references
-add missing static modifier to connect method
-implement basic test methods
-update extensions tests with SocketIO test entry
-implement basic handshake and opensocket methods for SocketIO
-add Delegate class to handle callbacks, implement virtual Delegate methods in test
-implement socket and client registries for lookup when connecting to hosts and endpoints
-connect delegate onOpen method by separating impl creation from connection
-update test to demonstrate onOpen callback
-create send and emit methods, move SIOClient into header file, add send and emit methods to test
-implement basic socket.io message parsing
-improve logging for events and messages
-add logic to pull event name from payload
-schedule heartbeat to keep connection alive, scheduled for 90% of the heartbeat interval from the server for safety
-add onConnect handler to to catch socket.io onconnect vs websocket onopen
-add disconnect and disconnectFromEndpoint methods to properly disconnect and destroy objects
-modify SIOClientImpl to track _uri for easier lookup in registries
-connect handler for onMessage to message event from socket.io, modify onError handler to take a string instead of WebSocket error code
-create SIOEvent callback type, implement event registry in clients, add test for event registration and callback
-update SIOEvent to use std::function and c++11, utilize cocos2d CC_CALLBACK method to bind selectors, this ensures that the *this reference is properly passed
-check for connect before sending or emitting in the client, cleanup some codes
-change connect logic to reuse existing socket connections instead of opening a new one
-implements get and set Tag methods for clients for easy reference
-improve endpoint handling, add endpoint tests to test layer
-additional error handling within socket disconnect error and failure to open connection
-fixes extracting endpoint from socket.io messages (in cases of the connect message, where there is 1 less colon for the connect message to the default namespace). Also fixes connecting to the default namespace "/" in the connectToEndpoint method
-add disconnect and onClose handlers to client so that onClose is called in the delegate
-add disconnect test methods to test layers
-change c-style casts to static_casts when using a CCDICT_FOREACH
-remove some unneeded namespace completion
-add usage documentation
-add handling for disconnect from server, cleanup some codes
-update comments and documentation in the socketiotest
-update includes so the NDK doesn't complain when compiling with c++11
-add socketio.cpp and test.cpp to the android makefiles
-update test URL to my public server, test script can also be found in my repo at https://github.com/hannon235/socket.io-testserver.git
Signed-off-by: Chris Hannon <himynameschris@gmail.com>
2013-06-26 10:40:01 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SIOClientImpl::onClose(cocos2d::extension::WebSocket* ws) {
|
|
|
|
|
|
|
|
if(_clients->count() > 0) {
|
|
|
|
|
|
|
|
DictElement *e;
|
|
|
|
|
|
|
|
CCDICT_FOREACH(_clients, e) {
|
|
|
|
|
|
|
|
SIOClient *c = static_cast<SIOClient *>(e->getObject());
|
|
|
|
|
|
|
|
c->receivedDisconnect();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
this->release();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SIOClientImpl::onError(cocos2d::extension::WebSocket* ws, const cocos2d::extension::WebSocket::ErrorCode& error) {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//begin SIOClient methods
|
|
|
|
SIOClient::SIOClient(const std::string& host, int port, const std::string& path, SIOClientImpl* impl, SocketIO::SIODelegate& delegate)
|
|
|
|
: _host(host)
|
|
|
|
, _port(port)
|
|
|
|
, _path(path)
|
|
|
|
, _socket(impl)
|
|
|
|
, _connected(false)
|
|
|
|
, _delegate(&delegate)
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SIOClient::~SIOClient(void) {
|
|
|
|
|
|
|
|
if(_connected) {
|
|
|
|
_socket->disconnectFromEndpoint(_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SIOClient::onOpen() {
|
|
|
|
|
|
|
|
if(_path != "/") {
|
|
|
|
|
|
|
|
_socket->connectToEndpoint(_path);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SIOClient::onConnect() {
|
|
|
|
|
|
|
|
_connected = true;
|
|
|
|
_delegate->onConnect(this);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SIOClient::send(std::string s) {
|
|
|
|
|
|
|
|
if(_connected) {
|
|
|
|
_socket->send(_path, s);
|
|
|
|
} else {
|
|
|
|
_delegate->onError(this, "Client not yet connected");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SIOClient::emit(std::string eventname, std::string args) {
|
|
|
|
|
|
|
|
if(_connected) {
|
|
|
|
_socket->emit(_path, eventname, args);
|
|
|
|
} else {
|
|
|
|
_delegate->onError(this, "Client not yet connected");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SIOClient::disconnect() {
|
|
|
|
|
|
|
|
_connected = false;
|
|
|
|
|
|
|
|
_socket->disconnectFromEndpoint(_path);
|
|
|
|
|
|
|
|
_delegate->onClose(this);
|
|
|
|
|
|
|
|
this->release();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SIOClient::receivedDisconnect() {
|
|
|
|
|
|
|
|
_connected = false;
|
|
|
|
|
|
|
|
_delegate->onClose(this);
|
|
|
|
|
|
|
|
this->release();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SIOClient::on(const std::string& eventName, SIOEvent e) {
|
|
|
|
|
|
|
|
_eventRegistry[eventName] = e;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SIOClient::fireEvent(const std::string& eventName, const std::string& data) {
|
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
log("SIOClient::fireEvent called with event name: %s and data: %s", eventName.c_str(), data.c_str());
|
Implements a socket.io client extension, adds a test case and updates the android makefiles.
Contains the following tasks:
-initial socket.io extension commit
-sioclientimpl subclasses websocket:delegate to respond to websocket events
-implement static connect methods and basic client creation
-move SocketIO class files into correct extension folder (network)
-create SocketIO test in TestCpp
-update project references
-add missing static modifier to connect method
-implement basic test methods
-update extensions tests with SocketIO test entry
-implement basic handshake and opensocket methods for SocketIO
-add Delegate class to handle callbacks, implement virtual Delegate methods in test
-implement socket and client registries for lookup when connecting to hosts and endpoints
-connect delegate onOpen method by separating impl creation from connection
-update test to demonstrate onOpen callback
-create send and emit methods, move SIOClient into header file, add send and emit methods to test
-implement basic socket.io message parsing
-improve logging for events and messages
-add logic to pull event name from payload
-schedule heartbeat to keep connection alive, scheduled for 90% of the heartbeat interval from the server for safety
-add onConnect handler to to catch socket.io onconnect vs websocket onopen
-add disconnect and disconnectFromEndpoint methods to properly disconnect and destroy objects
-modify SIOClientImpl to track _uri for easier lookup in registries
-connect handler for onMessage to message event from socket.io, modify onError handler to take a string instead of WebSocket error code
-create SIOEvent callback type, implement event registry in clients, add test for event registration and callback
-update SIOEvent to use std::function and c++11, utilize cocos2d CC_CALLBACK method to bind selectors, this ensures that the *this reference is properly passed
-check for connect before sending or emitting in the client, cleanup some codes
-change connect logic to reuse existing socket connections instead of opening a new one
-implements get and set Tag methods for clients for easy reference
-improve endpoint handling, add endpoint tests to test layer
-additional error handling within socket disconnect error and failure to open connection
-fixes extracting endpoint from socket.io messages (in cases of the connect message, where there is 1 less colon for the connect message to the default namespace). Also fixes connecting to the default namespace "/" in the connectToEndpoint method
-add disconnect and onClose handlers to client so that onClose is called in the delegate
-add disconnect test methods to test layers
-change c-style casts to static_casts when using a CCDICT_FOREACH
-remove some unneeded namespace completion
-add usage documentation
-add handling for disconnect from server, cleanup some codes
-update comments and documentation in the socketiotest
-update includes so the NDK doesn't complain when compiling with c++11
-add socketio.cpp and test.cpp to the android makefiles
-update test URL to my public server, test script can also be found in my repo at https://github.com/hannon235/socket.io-testserver.git
Signed-off-by: Chris Hannon <himynameschris@gmail.com>
2013-06-26 10:40:01 +08:00
|
|
|
|
|
|
|
if(_eventRegistry[eventName]) {
|
|
|
|
|
|
|
|
SIOEvent e = _eventRegistry[eventName];
|
|
|
|
|
|
|
|
e(this, data);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
log("SIOClient::fireEvent no event with name %s found", eventName.c_str());
|
Implements a socket.io client extension, adds a test case and updates the android makefiles.
Contains the following tasks:
-initial socket.io extension commit
-sioclientimpl subclasses websocket:delegate to respond to websocket events
-implement static connect methods and basic client creation
-move SocketIO class files into correct extension folder (network)
-create SocketIO test in TestCpp
-update project references
-add missing static modifier to connect method
-implement basic test methods
-update extensions tests with SocketIO test entry
-implement basic handshake and opensocket methods for SocketIO
-add Delegate class to handle callbacks, implement virtual Delegate methods in test
-implement socket and client registries for lookup when connecting to hosts and endpoints
-connect delegate onOpen method by separating impl creation from connection
-update test to demonstrate onOpen callback
-create send and emit methods, move SIOClient into header file, add send and emit methods to test
-implement basic socket.io message parsing
-improve logging for events and messages
-add logic to pull event name from payload
-schedule heartbeat to keep connection alive, scheduled for 90% of the heartbeat interval from the server for safety
-add onConnect handler to to catch socket.io onconnect vs websocket onopen
-add disconnect and disconnectFromEndpoint methods to properly disconnect and destroy objects
-modify SIOClientImpl to track _uri for easier lookup in registries
-connect handler for onMessage to message event from socket.io, modify onError handler to take a string instead of WebSocket error code
-create SIOEvent callback type, implement event registry in clients, add test for event registration and callback
-update SIOEvent to use std::function and c++11, utilize cocos2d CC_CALLBACK method to bind selectors, this ensures that the *this reference is properly passed
-check for connect before sending or emitting in the client, cleanup some codes
-change connect logic to reuse existing socket connections instead of opening a new one
-implements get and set Tag methods for clients for easy reference
-improve endpoint handling, add endpoint tests to test layer
-additional error handling within socket disconnect error and failure to open connection
-fixes extracting endpoint from socket.io messages (in cases of the connect message, where there is 1 less colon for the connect message to the default namespace). Also fixes connecting to the default namespace "/" in the connectToEndpoint method
-add disconnect and onClose handlers to client so that onClose is called in the delegate
-add disconnect test methods to test layers
-change c-style casts to static_casts when using a CCDICT_FOREACH
-remove some unneeded namespace completion
-add usage documentation
-add handling for disconnect from server, cleanup some codes
-update comments and documentation in the socketiotest
-update includes so the NDK doesn't complain when compiling with c++11
-add socketio.cpp and test.cpp to the android makefiles
-update test URL to my public server, test script can also be found in my repo at https://github.com/hannon235/socket.io-testserver.git
Signed-off-by: Chris Hannon <himynameschris@gmail.com>
2013-06-26 10:40:01 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//begin SocketIO methods
|
|
|
|
SocketIO *SocketIO::_inst = NULL;
|
|
|
|
|
|
|
|
SocketIO::SocketIO() {
|
|
|
|
|
|
|
|
_sockets = Dictionary::create();
|
|
|
|
_sockets->retain();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SocketIO::~SocketIO(void) {
|
|
|
|
CC_SAFE_DELETE(_sockets);
|
|
|
|
delete _inst;
|
|
|
|
}
|
|
|
|
|
|
|
|
SocketIO* SocketIO::instance() {
|
|
|
|
|
|
|
|
if(!_inst)
|
|
|
|
_inst = new SocketIO();
|
|
|
|
|
|
|
|
return _inst;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SIOClient* SocketIO::connect(SocketIO::SIODelegate& delegate, const std::string& uri) {
|
|
|
|
|
|
|
|
std::string host = uri;
|
2013-07-15 16:14:26 +08:00
|
|
|
int port = 0;
|
|
|
|
int pos = 0;
|
Implements a socket.io client extension, adds a test case and updates the android makefiles.
Contains the following tasks:
-initial socket.io extension commit
-sioclientimpl subclasses websocket:delegate to respond to websocket events
-implement static connect methods and basic client creation
-move SocketIO class files into correct extension folder (network)
-create SocketIO test in TestCpp
-update project references
-add missing static modifier to connect method
-implement basic test methods
-update extensions tests with SocketIO test entry
-implement basic handshake and opensocket methods for SocketIO
-add Delegate class to handle callbacks, implement virtual Delegate methods in test
-implement socket and client registries for lookup when connecting to hosts and endpoints
-connect delegate onOpen method by separating impl creation from connection
-update test to demonstrate onOpen callback
-create send and emit methods, move SIOClient into header file, add send and emit methods to test
-implement basic socket.io message parsing
-improve logging for events and messages
-add logic to pull event name from payload
-schedule heartbeat to keep connection alive, scheduled for 90% of the heartbeat interval from the server for safety
-add onConnect handler to to catch socket.io onconnect vs websocket onopen
-add disconnect and disconnectFromEndpoint methods to properly disconnect and destroy objects
-modify SIOClientImpl to track _uri for easier lookup in registries
-connect handler for onMessage to message event from socket.io, modify onError handler to take a string instead of WebSocket error code
-create SIOEvent callback type, implement event registry in clients, add test for event registration and callback
-update SIOEvent to use std::function and c++11, utilize cocos2d CC_CALLBACK method to bind selectors, this ensures that the *this reference is properly passed
-check for connect before sending or emitting in the client, cleanup some codes
-change connect logic to reuse existing socket connections instead of opening a new one
-implements get and set Tag methods for clients for easy reference
-improve endpoint handling, add endpoint tests to test layer
-additional error handling within socket disconnect error and failure to open connection
-fixes extracting endpoint from socket.io messages (in cases of the connect message, where there is 1 less colon for the connect message to the default namespace). Also fixes connecting to the default namespace "/" in the connectToEndpoint method
-add disconnect and onClose handlers to client so that onClose is called in the delegate
-add disconnect test methods to test layers
-change c-style casts to static_casts when using a CCDICT_FOREACH
-remove some unneeded namespace completion
-add usage documentation
-add handling for disconnect from server, cleanup some codes
-update comments and documentation in the socketiotest
-update includes so the NDK doesn't complain when compiling with c++11
-add socketio.cpp and test.cpp to the android makefiles
-update test URL to my public server, test script can also be found in my repo at https://github.com/hannon235/socket.io-testserver.git
Signed-off-by: Chris Hannon <himynameschris@gmail.com>
2013-06-26 10:40:01 +08:00
|
|
|
|
|
|
|
pos = host.find("//");
|
|
|
|
if(pos >= 0) {
|
|
|
|
host.erase(0, pos+2);
|
|
|
|
}
|
|
|
|
|
|
|
|
pos = host.find(":");
|
|
|
|
if(pos >= 0){
|
|
|
|
port = atoi(host.substr(pos+1, host.size()).c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
pos = host.find("/", 0);
|
|
|
|
std::string path = "/";
|
|
|
|
if(pos >= 0){
|
|
|
|
path += host.substr(pos + 1, host.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
pos = host.find(":");
|
|
|
|
if(pos >= 0){
|
|
|
|
host.erase(pos, host.size());
|
|
|
|
}else if((pos = host.find("/"))>=0) {
|
|
|
|
host.erase(pos, host.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::stringstream s;
|
|
|
|
s << host << ":" << port;
|
|
|
|
|
|
|
|
SIOClientImpl* socket = NULL;
|
|
|
|
SIOClient *c = NULL;
|
|
|
|
|
|
|
|
socket = SocketIO::instance()->getSocket(s.str());
|
|
|
|
|
|
|
|
if(socket == NULL) {
|
|
|
|
//create a new socket, new client, connect
|
|
|
|
socket = SIOClientImpl::create(host, port);
|
|
|
|
|
|
|
|
c = new SIOClient(host, port, path, socket, delegate);
|
|
|
|
|
|
|
|
socket->addClient(path, c);
|
|
|
|
|
|
|
|
socket->connect();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
//check if already connected to endpoint, handle
|
|
|
|
c = socket->getClient(path);
|
|
|
|
|
|
|
|
if(c == NULL) {
|
|
|
|
|
|
|
|
c = new SIOClient(host, port, path, socket, delegate);
|
|
|
|
|
|
|
|
socket->addClient(path, c);
|
|
|
|
|
|
|
|
socket->connectToEndpoint(path);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return c;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SIOClientImpl* SocketIO::getSocket(const std::string& uri) {
|
|
|
|
|
|
|
|
return static_cast<SIOClientImpl*>(_sockets->objectForKey(uri));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SocketIO::addSocket(const std::string& uri, SIOClientImpl* socket) {
|
|
|
|
_sockets->setObject(socket, uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SocketIO::removeSocket(const std::string& uri) {
|
|
|
|
_sockets->removeObjectForKey(uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_CC_EXT_END
|