2015-05-05 10:50:19 +08:00
|
|
|
/*
|
|
|
|
* Created by Chris Hannon 2014 http://www.channon.us
|
|
|
|
* Copyright (c) 2014 Chukong Technologies Inc.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "jsb_socketio.h"
|
|
|
|
#include "jsb_helper.h"
|
|
|
|
#include "cocos2d.h"
|
|
|
|
#include "network/WebSocket.h"
|
|
|
|
#include "network/SocketIO.h"
|
|
|
|
#include "spidermonkey_specifics.h"
|
|
|
|
#include "ScriptingCore.h"
|
|
|
|
#include "cocos2d_specifics.hpp"
|
|
|
|
|
|
|
|
using namespace cocos2d::network;
|
|
|
|
|
|
|
|
//c++11 map to callbacks
|
2015-08-06 17:20:04 +08:00
|
|
|
typedef std::unordered_map<std::string, std::shared_ptr<JSFunctionWrapper>> JSB_SIOCallbackRegistry;
|
2015-05-05 10:50:19 +08:00
|
|
|
|
2015-08-06 17:20:04 +08:00
|
|
|
class JSB_SocketIODelegate : public SocketIO::SIODelegate
|
|
|
|
{
|
2015-05-05 10:50:19 +08:00
|
|
|
public:
|
|
|
|
|
2015-08-06 17:20:04 +08:00
|
|
|
JSB_SocketIODelegate()
|
|
|
|
{
|
2015-05-05 10:50:19 +08:00
|
|
|
std::string s = "default";
|
2015-08-06 17:20:04 +08:00
|
|
|
_eventRegistry[s] = nullptr;
|
2015-11-25 14:32:19 +08:00
|
|
|
JSContext* cx = ScriptingCore::getInstance()->getGlobalContext();
|
|
|
|
_JSDelegate.construct(cx);
|
|
|
|
}
|
|
|
|
|
|
|
|
~JSB_SocketIODelegate()
|
|
|
|
{
|
|
|
|
_JSDelegate.destroyIfConstructed();
|
2015-05-05 10:50:19 +08:00
|
|
|
}
|
|
|
|
|
2015-08-06 17:20:04 +08:00
|
|
|
virtual void onConnect(SIOClient* client)
|
|
|
|
{
|
2015-05-05 10:50:19 +08:00
|
|
|
CCLOG("JSB SocketIO::SIODelegate->onConnect method called from native");
|
|
|
|
this->fireEventToScript(client, "connect", "");
|
|
|
|
}
|
|
|
|
|
2015-08-06 17:20:04 +08:00
|
|
|
virtual void onMessage(SIOClient* client, const std::string& data)
|
|
|
|
{
|
2015-05-05 10:50:19 +08:00
|
|
|
CCLOG("JSB SocketIO::SIODelegate->onMessage method called from native with data: %s", data.c_str());
|
|
|
|
this->fireEventToScript(client, "message", data);
|
|
|
|
}
|
|
|
|
|
2015-08-06 17:20:04 +08:00
|
|
|
virtual void onClose(SIOClient* client)
|
|
|
|
{
|
2015-05-05 10:50:19 +08:00
|
|
|
CCLOG("JSB SocketIO::SIODelegate->onClose method called from native");
|
|
|
|
this->fireEventToScript(client, "disconnect", "");
|
|
|
|
}
|
|
|
|
|
2015-08-06 17:20:04 +08:00
|
|
|
virtual void onError(SIOClient* client, const std::string& data)
|
|
|
|
{
|
2015-05-05 10:50:19 +08:00
|
|
|
CCLOG("JSB SocketIO::SIODelegate->onError method called from native with data: %s", data.c_str());
|
|
|
|
this->fireEventToScript(client, "error", data);
|
|
|
|
}
|
|
|
|
|
2015-08-06 17:20:04 +08:00
|
|
|
virtual void fireEventToScript(SIOClient* client, const std::string& eventName, const std::string& data)
|
|
|
|
{
|
2015-05-05 10:50:19 +08:00
|
|
|
CCLOG("JSB SocketIO::SIODelegate->fireEventToScript method called from native with name '%s' data: %s", eventName.c_str(), data.c_str());
|
|
|
|
|
|
|
|
js_proxy_t * p = jsb_get_native_proxy(client);
|
|
|
|
if (!p) return;
|
|
|
|
|
|
|
|
JSContext* cx = ScriptingCore::getInstance()->getGlobalContext();
|
|
|
|
|
|
|
|
jsval args;
|
2015-08-06 17:20:04 +08:00
|
|
|
if(data == "")
|
|
|
|
{
|
2015-05-05 10:50:19 +08:00
|
|
|
args = JSVAL_NULL;
|
2015-08-06 17:20:04 +08:00
|
|
|
} else
|
|
|
|
{
|
2015-05-05 10:50:19 +08:00
|
|
|
args = std_string_to_jsval(cx, data);
|
|
|
|
}
|
|
|
|
|
2015-08-06 17:20:04 +08:00
|
|
|
JSB_SIOCallbackRegistry::iterator it = _eventRegistry.find(eventName);
|
2015-05-05 10:50:19 +08:00
|
|
|
|
2015-08-06 17:20:04 +08:00
|
|
|
if(it != _eventRegistry.end())
|
|
|
|
{
|
|
|
|
std::shared_ptr<JSFunctionWrapper> callback = it->second;
|
|
|
|
if (callback != nullptr)
|
|
|
|
{
|
|
|
|
JS::RootedValue rval(cx);
|
|
|
|
callback->invoke(1, &args, &rval);
|
|
|
|
}
|
2015-05-05 10:50:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-11-25 14:32:19 +08:00
|
|
|
void setJSDelegate(JS::HandleObject pJSDelegate)
|
2015-08-06 17:20:04 +08:00
|
|
|
{
|
2015-11-25 14:32:19 +08:00
|
|
|
_JSDelegate.ref() = pJSDelegate;
|
2015-05-05 10:50:19 +08:00
|
|
|
}
|
|
|
|
|
2015-08-06 17:20:04 +08:00
|
|
|
void addEvent(const std::string& eventName, std::shared_ptr<JSFunctionWrapper> callback)
|
|
|
|
{
|
|
|
|
_eventRegistry[eventName] = callback;
|
2015-05-05 10:50:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-11-25 14:32:19 +08:00
|
|
|
mozilla::Maybe<JS::PersistentRootedObject> _JSDelegate;
|
2015-08-06 17:20:04 +08:00
|
|
|
JSB_SIOCallbackRegistry _eventRegistry;
|
2015-05-05 10:50:19 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
JSClass *js_cocos2dx_socketio_class;
|
|
|
|
JSObject *js_cocos2dx_socketio_prototype;
|
|
|
|
|
2015-08-06 17:20:04 +08:00
|
|
|
void js_cocos2dx_SocketIO_finalize(JSFreeOp *fop, JSObject *obj)
|
|
|
|
{
|
2015-05-05 10:50:19 +08:00
|
|
|
CCLOG("jsbindings: finalizing JS object %p (SocketIO)", obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool js_cocos2dx_SocketIO_constructor(JSContext *cx, uint32_t argc, jsval *vp)
|
|
|
|
{
|
|
|
|
JS_ReportError(cx, "SocketIO isn't meant to be instantiated, use SocketIO.connect() instead");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-06 17:20:04 +08:00
|
|
|
bool js_cocos2dx_SocketIO_connect(JSContext* cx, uint32_t argc, jsval* vp)
|
|
|
|
{
|
2015-05-05 10:50:19 +08:00
|
|
|
CCLOG("JSB SocketIO.connect method called");
|
|
|
|
|
|
|
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
2015-08-06 17:20:04 +08:00
|
|
|
if (argc == 1 || argc == 2)
|
|
|
|
{
|
2015-05-05 10:50:19 +08:00
|
|
|
std::string url;
|
|
|
|
|
2015-08-06 17:20:04 +08:00
|
|
|
do
|
|
|
|
{
|
2015-05-05 10:50:19 +08:00
|
|
|
bool ok = jsval_to_std_string(cx, args.get(0), &url);
|
|
|
|
JSB_PRECONDITION2( ok, cx, false, "Error processing arguments");
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
JSB_SocketIODelegate* siodelegate = new JSB_SocketIODelegate();
|
|
|
|
|
|
|
|
CCLOG("Calling native SocketIO.connect method");
|
2015-08-06 17:20:04 +08:00
|
|
|
SIOClient* ret = SocketIO::connect(url, *siodelegate);
|
2015-05-05 10:50:19 +08:00
|
|
|
|
|
|
|
jsval jsret;
|
2015-08-06 17:20:04 +08:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if (ret)
|
|
|
|
{
|
2015-05-05 10:50:19 +08:00
|
|
|
// link the native object with the javascript object
|
|
|
|
js_proxy_t *p;
|
|
|
|
HASH_FIND_PTR(_native_js_global_ht, &ret, p);
|
2015-08-06 17:20:04 +08:00
|
|
|
if(!p)
|
|
|
|
{
|
2015-05-05 10:50:19 +08:00
|
|
|
//previous connection not found, create a new one
|
2015-11-27 01:26:54 +08:00
|
|
|
JS::RootedObject proto(cx, js_cocos2dx_socketio_prototype);
|
|
|
|
JSObject *obj = JS_NewObject(cx, js_cocos2dx_socketio_class, proto, JS::NullPtr());
|
2015-05-05 10:50:19 +08:00
|
|
|
p = jsb_new_proxy(ret, obj);
|
2015-11-27 01:26:54 +08:00
|
|
|
JS::RootedObject jsdelegate(cx, p->obj);
|
|
|
|
siodelegate->setJSDelegate(jsdelegate);
|
2015-05-05 10:50:19 +08:00
|
|
|
}
|
|
|
|
jsret = OBJECT_TO_JSVAL(p->obj);
|
|
|
|
}
|
2015-08-06 17:20:04 +08:00
|
|
|
else
|
|
|
|
{
|
2015-05-05 10:50:19 +08:00
|
|
|
jsret = JSVAL_NULL;
|
|
|
|
}
|
|
|
|
} while(0);
|
|
|
|
|
|
|
|
args.rval().set(jsret);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
JS_ReportError(cx, "JSB SocketIO.connect: Wrong number of arguments");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-06 17:20:04 +08:00
|
|
|
bool js_cocos2dx_SocketIO_send(JSContext* cx, uint32_t argc, jsval* vp)
|
|
|
|
{
|
2015-05-05 10:50:19 +08:00
|
|
|
CCLOG("JSB SocketIO.send method called");
|
|
|
|
|
|
|
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
2015-11-25 14:33:43 +08:00
|
|
|
JS::RootedObject obj(cx, args.thisv().toObjectOrNull());
|
2015-05-05 10:50:19 +08:00
|
|
|
js_proxy_t *proxy = jsb_get_js_proxy(obj);
|
|
|
|
SIOClient* cobj = (SIOClient *)(proxy ? proxy->ptr : NULL);
|
|
|
|
JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object");
|
|
|
|
|
2015-08-06 17:20:04 +08:00
|
|
|
if (argc == 1)
|
|
|
|
{
|
2015-05-05 10:50:19 +08:00
|
|
|
std::string payload;
|
|
|
|
|
2015-08-06 17:20:04 +08:00
|
|
|
do
|
|
|
|
{
|
2015-05-05 10:50:19 +08:00
|
|
|
bool ok = jsval_to_std_string(cx, args.get(0), &payload);
|
|
|
|
JSB_PRECONDITION2( ok, cx, false, "Error processing arguments");
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
CCLOG("JSB SocketIO send mesage: %s", payload.c_str());
|
|
|
|
|
|
|
|
cobj->send(payload);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
JS_ReportError(cx, "Wrong number of arguments");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-06 17:20:04 +08:00
|
|
|
bool js_cocos2dx_SocketIO_emit(JSContext* cx, uint32_t argc, jsval* vp)
|
|
|
|
{
|
2015-05-05 10:50:19 +08:00
|
|
|
CCLOG("JSB SocketIO.emit method called");
|
|
|
|
|
|
|
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
2015-11-25 14:33:43 +08:00
|
|
|
JS::RootedObject obj(cx, args.thisv().toObjectOrNull());
|
2015-05-05 10:50:19 +08:00
|
|
|
js_proxy_t *proxy = jsb_get_js_proxy(obj);
|
|
|
|
SIOClient* cobj = (SIOClient *)(proxy ? proxy->ptr : NULL);
|
|
|
|
JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object");
|
|
|
|
|
2015-08-06 17:20:04 +08:00
|
|
|
if (argc == 2)
|
|
|
|
{
|
2015-05-05 10:50:19 +08:00
|
|
|
std::string eventName;
|
2015-08-06 17:20:04 +08:00
|
|
|
do
|
|
|
|
{
|
2015-05-05 10:50:19 +08:00
|
|
|
bool ok = jsval_to_std_string(cx, args.get(0), &eventName);
|
|
|
|
JSB_PRECONDITION2( ok, cx, false, "Error processing arguments");
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
std::string payload;
|
|
|
|
do {
|
|
|
|
bool ok = jsval_to_std_string(cx, args.get(1), &payload);
|
|
|
|
JSB_PRECONDITION2( ok, cx, false, "Error processing arguments");
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
CCLOG("JSB SocketIO emit event '%s' with payload: %s", eventName.c_str(), payload.c_str());
|
|
|
|
|
|
|
|
cobj->emit(eventName, payload);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
JS_ReportError(cx, "JSB SocketIO.emit: Wrong number of arguments");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-06 17:20:04 +08:00
|
|
|
bool js_cocos2dx_SocketIO_disconnect(JSContext* cx, uint32_t argc, jsval* vp)
|
|
|
|
{
|
2015-05-05 10:50:19 +08:00
|
|
|
CCLOG("JSB SocketIO.disconnect method called");
|
|
|
|
|
|
|
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
2015-11-25 14:33:43 +08:00
|
|
|
JS::RootedObject obj(cx, args.thisv().toObjectOrNull());
|
2015-05-05 10:50:19 +08:00
|
|
|
js_proxy_t *proxy = jsb_get_js_proxy(obj);
|
|
|
|
SIOClient* cobj = (SIOClient *)(proxy ? proxy->ptr : NULL);
|
|
|
|
JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object");
|
|
|
|
|
2015-08-06 17:20:04 +08:00
|
|
|
if(argc == 0)
|
|
|
|
{
|
2015-05-05 10:50:19 +08:00
|
|
|
cobj->disconnect();
|
|
|
|
args.rval().setUndefined();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ReportError(cx, "JSB SocketIO.disconnect: Wrong number of arguments");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-06 17:20:04 +08:00
|
|
|
bool js_cocos2dx_SocketIO_close(JSContext* cx, uint32_t argc, jsval* vp)
|
|
|
|
{
|
2015-05-05 10:50:19 +08:00
|
|
|
CCLOG("JSB SocketIO.close method called");
|
|
|
|
|
2015-08-06 17:20:04 +08:00
|
|
|
if(argc == 0)
|
|
|
|
{
|
2015-05-05 10:50:19 +08:00
|
|
|
|
|
|
|
//This method was previously implemented to take care of the HTTPClient instance not being destroyed properly
|
|
|
|
//SocketIO::close();
|
|
|
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
|
|
|
args.rval().setUndefined();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ReportError(cx, "JSB SocketIO.close: Wrong number of arguments");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool _js_set_SIOClient_tag(JSContext* cx, uint32_t argc, jsval* vp)
|
|
|
|
{
|
|
|
|
CCLOG("JSB SocketIO.setTag method called");
|
|
|
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
|
|
|
JSObject* jsobj = args.thisv().toObjectOrNull();
|
|
|
|
js_proxy_t *proxy = jsb_get_js_proxy(jsobj);
|
|
|
|
SIOClient* cobj = (SIOClient *)(proxy ? proxy->ptr : NULL);
|
|
|
|
JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object");
|
|
|
|
|
2015-08-06 17:20:04 +08:00
|
|
|
if (cobj)
|
|
|
|
{
|
2015-05-05 10:50:19 +08:00
|
|
|
std::string out = "";
|
|
|
|
|
|
|
|
jsval_to_std_string(cx, args.get(0), &out);
|
|
|
|
cobj->setTag(out.c_str());
|
|
|
|
return true;
|
2015-08-06 17:20:04 +08:00
|
|
|
} else
|
|
|
|
{
|
2015-05-05 10:50:19 +08:00
|
|
|
JS_ReportError(cx, "Error: SocketIO instance is invalid.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool _js_get_SIOClient_tag(JSContext* cx, uint32_t argc, jsval* vp)
|
|
|
|
{
|
|
|
|
CCLOG("JSB SocketIO.getTag method called");
|
|
|
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
|
|
|
JSObject* jsobj = args.thisv().toObjectOrNull();
|
|
|
|
js_proxy_t *proxy = jsb_get_js_proxy(jsobj);
|
|
|
|
SIOClient* cobj = (SIOClient *)(proxy ? proxy->ptr : NULL);
|
|
|
|
JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object");
|
|
|
|
|
2015-08-06 17:20:04 +08:00
|
|
|
if (cobj)
|
|
|
|
{
|
2015-05-05 10:50:19 +08:00
|
|
|
args.rval().set(std_string_to_jsval(cx, cobj->getTag()));
|
|
|
|
return true;
|
2015-08-06 17:20:04 +08:00
|
|
|
} else
|
|
|
|
{
|
2015-05-05 10:50:19 +08:00
|
|
|
JS_ReportError(cx, "Error: SocketIO instance is invalid.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-06 17:20:04 +08:00
|
|
|
bool js_cocos2dx_SocketIO_on(JSContext* cx, uint32_t argc, jsval* vp)
|
|
|
|
{
|
2015-05-05 10:50:19 +08:00
|
|
|
CCLOG("JSB SocketIO.on method called");
|
|
|
|
|
|
|
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
2015-11-25 14:33:43 +08:00
|
|
|
JS::RootedObject obj(cx, args.thisv().toObjectOrNull());
|
2015-05-05 10:50:19 +08:00
|
|
|
js_proxy_t *proxy = jsb_get_js_proxy(obj);
|
|
|
|
SIOClient* cobj = (SIOClient *)(proxy ? proxy->ptr : NULL);
|
|
|
|
JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object");
|
|
|
|
|
2015-08-06 17:20:04 +08:00
|
|
|
if(argc == 2)
|
|
|
|
{
|
2015-05-05 10:50:19 +08:00
|
|
|
std::string eventName;
|
2015-08-06 17:20:04 +08:00
|
|
|
do
|
|
|
|
{
|
2015-05-05 10:50:19 +08:00
|
|
|
bool ok = jsval_to_std_string(cx, args.get(0), &eventName);
|
|
|
|
JSB_PRECONDITION2( ok, cx, false, "Error processing arguments");
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
CCLOG("JSB SocketIO eventName to: '%s'", eventName.c_str());
|
2015-08-06 17:20:04 +08:00
|
|
|
|
2015-11-25 14:32:19 +08:00
|
|
|
std::shared_ptr<JSFunctionWrapper> callback(new JSFunctionWrapper(cx, obj, args.get(1)));
|
2015-05-05 10:50:19 +08:00
|
|
|
|
2015-08-06 17:20:04 +08:00
|
|
|
((JSB_SocketIODelegate *)cobj->getDelegate())->addEvent(eventName, callback);
|
2015-05-05 10:50:19 +08:00
|
|
|
|
|
|
|
args.rval().set(OBJECT_TO_JSVAL(proxy->obj));
|
|
|
|
JS_SetReservedSlot(proxy->obj, 0, args.get(1));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
JS_ReportError(cx, "JSB SocketIO.close: Wrong number of arguments");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-06 17:20:04 +08:00
|
|
|
void register_jsb_socketio(JSContext *cx, JS::HandleObject global)
|
|
|
|
{
|
2015-05-05 10:50:19 +08:00
|
|
|
js_cocos2dx_socketio_class = (JSClass *)calloc(1, sizeof(JSClass));
|
|
|
|
js_cocos2dx_socketio_class->name = "SocketIO";
|
|
|
|
js_cocos2dx_socketio_class->addProperty = JS_PropertyStub;
|
|
|
|
js_cocos2dx_socketio_class->delProperty = JS_DeletePropertyStub;
|
|
|
|
js_cocos2dx_socketio_class->getProperty = JS_PropertyStub;
|
|
|
|
js_cocos2dx_socketio_class->setProperty = JS_StrictPropertyStub;
|
|
|
|
js_cocos2dx_socketio_class->enumerate = JS_EnumerateStub;
|
|
|
|
js_cocos2dx_socketio_class->resolve = JS_ResolveStub;
|
|
|
|
js_cocos2dx_socketio_class->convert = JS_ConvertStub;
|
|
|
|
js_cocos2dx_socketio_class->finalize = js_cocos2dx_SocketIO_finalize;
|
|
|
|
js_cocos2dx_socketio_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);
|
|
|
|
|
2015-08-06 17:20:04 +08:00
|
|
|
static JSPropertySpec properties[] =
|
|
|
|
{
|
2015-05-05 10:50:19 +08:00
|
|
|
JS_PSGS("tag", _js_get_SIOClient_tag, _js_set_SIOClient_tag, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
|
|
|
JS_PS_END
|
|
|
|
};
|
|
|
|
|
2015-08-06 17:20:04 +08:00
|
|
|
static JSFunctionSpec funcs[] =
|
|
|
|
{
|
2015-05-05 10:50:19 +08:00
|
|
|
JS_FN("send", js_cocos2dx_SocketIO_send, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
|
|
|
JS_FN("emit", js_cocos2dx_SocketIO_emit, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
|
|
|
JS_FN("disconnect", js_cocos2dx_SocketIO_disconnect, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
|
|
|
JS_FN("on", js_cocos2dx_SocketIO_on, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
|
|
|
JS_FS_END
|
|
|
|
};
|
|
|
|
|
2015-08-06 17:20:04 +08:00
|
|
|
static JSFunctionSpec st_funcs[] =
|
|
|
|
{
|
2015-05-05 10:50:19 +08:00
|
|
|
JS_FN("connect", js_cocos2dx_SocketIO_connect, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
|
|
|
JS_FN("close", js_cocos2dx_SocketIO_close, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
|
|
|
JS_FS_END
|
|
|
|
};
|
|
|
|
|
|
|
|
js_cocos2dx_socketio_prototype = JS_InitClass(
|
|
|
|
cx, global,
|
|
|
|
JS::NullPtr(),
|
|
|
|
js_cocos2dx_socketio_class,
|
|
|
|
js_cocos2dx_SocketIO_constructor, 0, // constructor
|
|
|
|
nullptr,
|
|
|
|
funcs,
|
2015-08-06 17:20:04 +08:00
|
|
|
properties,
|
2015-05-05 10:50:19 +08:00
|
|
|
st_funcs);
|
|
|
|
|
2015-08-06 17:20:04 +08:00
|
|
|
anonEvaluate(cx, global, "(function () { return SocketIO; })()").toObjectOrNull();
|
2015-05-05 10:50:19 +08:00
|
|
|
}
|
|
|
|
|