From ba37c0705316ae7ef78c63a2794bdfda6b3d7e13 Mon Sep 17 00:00:00 2001 From: Chris Hannon Date: Fri, 21 Mar 2014 11:44:54 -0400 Subject: [PATCH] [add-socketio-jsb] implement fireEventToScript method to integrate JSB event handling with the original native code -update static connect method to match JS API, kept original method but marked deprecated Signed-off-by: Chris Hannon --- cocos/network/SocketIO.cpp | 13 +++++++++++-- cocos/network/SocketIO.h | 5 ++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/cocos/network/SocketIO.cpp b/cocos/network/SocketIO.cpp index af7b295543..60ca7f1689 100644 --- a/cocos/network/SocketIO.cpp +++ b/cocos/network/SocketIO.cpp @@ -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 @@ -603,7 +605,14 @@ void SocketIO::destroyInstance() CC_SAFE_DELETE(_inst); } -SIOClient* SocketIO::connect(SocketIO::SIODelegate& delegate, const std::string& uri) +CC_DEPRECATED_ATTRIBUTE 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; diff --git a/cocos/network/SocketIO.h b/cocos/network/SocketIO.h index 4721810c5c..92160d836e 100644 --- a/cocos/network/SocketIO.h +++ b/cocos/network/SocketIO.h @@ -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: