Merge pull request #5939 from dumganhar/merge5923

Merge PR #5923: implement fireEventToScript method to integrate JSB event handling with the original native code
This commit is contained in:
James Chen 2014-03-24 18:08:02 +08:00
commit ec4b1ee485
3 changed files with 389 additions and 377 deletions

View File

@ -567,6 +567,8 @@ void SIOClient::fireEvent(const std::string& eventName, const std::string& data)
{
log("SIOClient::fireEvent called with event name: %s and data: %s", eventName.c_str(), data.c_str());
_delegate->fireEventToScript(this, eventName, data);
if(_eventRegistry[eventName])
{
SIOEvent e = _eventRegistry[eventName];
@ -576,7 +578,7 @@ void SIOClient::fireEvent(const std::string& eventName, const std::string& data)
return;
}
log("SIOClient::fireEvent no event with name %s found", eventName.c_str());
log("SIOClient::fireEvent no native event with name %s found", eventName.c_str());
}
//begin SocketIO methods
@ -604,6 +606,13 @@ void SocketIO::destroyInstance()
}
SIOClient* SocketIO::connect(SocketIO::SIODelegate& delegate, const std::string& uri)
{
return SocketIO::connect(uri, delegate);
}
SIOClient* SocketIO::connect(const std::string& uri, SocketIO::SIODelegate& delegate)
{
std::string host = uri;
int port = 0;

View File

@ -92,6 +92,7 @@ public:
virtual void onMessage(SIOClient* client, const std::string& data) = 0;
virtual void onClose(SIOClient* client) = 0;
virtual void onError(SIOClient* client, const std::string& data) = 0;
virtual void fireEventToScript(SIOClient* client, const std::string& eventName, const std::string& data) { CCLOG("SIODelegate event '%s' fired with data: %s", eventName.c_str(), data.c_str()); };
};
/**
@ -100,7 +101,9 @@ public:
* @param uri The URI of the socket.io server
* @return An initialized SIOClient if connected successfully, otherwise NULL
*/
static SIOClient* connect(SocketIO::SIODelegate& delegate, const std::string& uri);
static SIOClient* connect(const std::string& uri, SocketIO::SIODelegate& delegate);
CC_DEPRECATED_ATTRIBUTE static SIOClient* connect(SocketIO::SIODelegate& delegate, const std::string& uri);
private: