2013-06-04 10:06:16 +08:00
|
|
|
#include "jsb_pluginx_manual_callback.h"
|
2013-04-07 16:58:26 +08:00
|
|
|
#include "jsb_pluginx_basic_conversions.h"
|
|
|
|
#include "jsb_pluginx_spidermonkey_specifics.h"
|
2013-04-24 09:43:40 +08:00
|
|
|
#include "ProtocolAds.h"
|
2013-04-07 16:58:26 +08:00
|
|
|
|
|
|
|
using namespace pluginx;
|
|
|
|
|
|
|
|
static JSContext* s_cx = NULL;
|
|
|
|
|
|
|
|
class Pluginx_PurchaseResult : public cocos2d::plugin::PayResultListener
|
|
|
|
{
|
|
|
|
public:
|
2013-04-27 11:32:12 +08:00
|
|
|
virtual void onPayResult(cocos2d::plugin::PayResultCode ret, const char* msg, cocos2d::plugin::TProductInfo info)
|
2013-04-07 16:58:26 +08:00
|
|
|
{
|
|
|
|
char goodInfo[1024] = { 0 };
|
|
|
|
sprintf(goodInfo, "商品名称:%s\n商品价格:%s\n商品描述:%s",
|
|
|
|
info.find("productName")->second.c_str(),
|
|
|
|
info.find("productPrice")->second.c_str(),
|
|
|
|
info.find("productDesc")->second.c_str());
|
|
|
|
LOGD(goodInfo);
|
|
|
|
|
|
|
|
JSContext* cx = s_cx;
|
|
|
|
|
|
|
|
JSBool hasAction;
|
|
|
|
jsval retval;
|
|
|
|
jsval temp_retval;
|
|
|
|
jsval dataVal[3];
|
|
|
|
dataVal[0] = INT_TO_JSVAL(ret);
|
|
|
|
std::string strMsgInfo = msg;
|
|
|
|
dataVal[1] = std_string_to_jsval(cx, strMsgInfo);
|
|
|
|
dataVal[2] = TProductInfo_to_jsval(cx, info);
|
|
|
|
|
2013-06-20 16:31:12 +08:00
|
|
|
JSObject* obj = _JSDelegate;
|
2013-04-07 16:58:26 +08:00
|
|
|
|
2013-04-27 11:32:12 +08:00
|
|
|
if (JS_HasProperty(cx, obj, "onPayResult", &hasAction) && hasAction) {
|
|
|
|
if(!JS_GetProperty(cx, obj, "onPayResult", &temp_retval)) {
|
2013-04-07 16:58:26 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(temp_retval == JSVAL_VOID) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
JSAutoCompartment ac(cx, obj);
|
2013-04-27 11:32:12 +08:00
|
|
|
JS_CallFunctionName(cx, obj, "onPayResult",
|
2013-04-07 16:58:26 +08:00
|
|
|
3, dataVal, &retval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void setJSDelegate(JSObject* pJSDelegate)
|
|
|
|
{
|
2013-06-20 16:31:12 +08:00
|
|
|
_JSDelegate = pJSDelegate;
|
2013-04-07 16:58:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-06-20 16:31:12 +08:00
|
|
|
JSObject* _JSDelegate;
|
2013-04-07 16:58:26 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
JSBool js_pluginx_ProtocolIAP_setResultListener(JSContext *cx, uint32_t argc, jsval *vp)
|
|
|
|
{
|
|
|
|
s_cx = cx;
|
|
|
|
jsval *argv = JS_ARGV(cx, vp);
|
2013-04-27 11:32:12 +08:00
|
|
|
JSObject *obj = JS_THIS_OBJECT(cx, vp);
|
|
|
|
js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj);
|
|
|
|
cocos2d::plugin::ProtocolIAP* cobj = (cocos2d::plugin::ProtocolIAP *)(proxy ? proxy->ptr : NULL);
|
2013-04-07 16:58:26 +08:00
|
|
|
JSBool ok = JS_TRUE;
|
|
|
|
|
|
|
|
if (argc == 1) {
|
|
|
|
// save the delegate
|
|
|
|
JSObject *jsDelegate = JSVAL_TO_OBJECT(argv[0]);
|
|
|
|
Pluginx_PurchaseResult* nativeDelegate = new Pluginx_PurchaseResult();
|
|
|
|
nativeDelegate->setJSDelegate(jsDelegate);
|
2013-04-27 11:32:12 +08:00
|
|
|
cobj->setResultListener(nativeDelegate);
|
2013-04-07 16:58:26 +08:00
|
|
|
|
|
|
|
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
|
2013-04-27 11:32:12 +08:00
|
|
|
class Pluginx_AdsListener : public cocos2d::plugin::AdsListener
|
2013-04-07 16:58:26 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-04-27 11:32:12 +08:00
|
|
|
|
|
|
|
virtual void onAdsResult(AdsResultCode code, const char* msg)
|
2013-04-24 09:43:40 +08:00
|
|
|
{
|
|
|
|
JSContext* cx = s_cx;
|
|
|
|
|
|
|
|
JSBool hasAction;
|
|
|
|
jsval retval;
|
|
|
|
jsval temp_retval;
|
2013-04-27 11:32:12 +08:00
|
|
|
jsval dataVal[2];
|
|
|
|
dataVal[0] = INT_TO_JSVAL(code);
|
|
|
|
std::string strMsgInfo = msg;
|
|
|
|
dataVal[1] = std_string_to_jsval(cx, strMsgInfo);
|
2013-04-24 09:43:40 +08:00
|
|
|
|
2013-06-20 16:31:12 +08:00
|
|
|
JSObject* obj = _JSDelegate;
|
2013-04-27 11:32:12 +08:00
|
|
|
JSBool bRet = JS_HasProperty(cx, obj, "onAdsResult", &hasAction);
|
2013-04-24 09:43:40 +08:00
|
|
|
if (bRet && hasAction) {
|
2013-04-27 11:32:12 +08:00
|
|
|
if(!JS_GetProperty(cx, obj, "onAdsResult", &temp_retval)) {
|
2013-04-24 09:43:40 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(temp_retval == JSVAL_VOID) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
JSAutoCompartment ac(cx, obj);
|
2013-04-27 11:32:12 +08:00
|
|
|
JS_CallFunctionName(cx, obj, "onAdsResult",
|
|
|
|
2, dataVal, &retval);
|
2013-04-24 09:43:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-27 11:32:12 +08:00
|
|
|
virtual void onPlayerGetPoints(ProtocolAds* pAdsPlugin, int points)
|
2013-04-24 09:43:40 +08:00
|
|
|
{
|
|
|
|
JSContext* cx = s_cx;
|
|
|
|
|
|
|
|
JSBool hasAction;
|
|
|
|
jsval retval;
|
|
|
|
jsval temp_retval;
|
2013-04-27 11:32:12 +08:00
|
|
|
|
|
|
|
js_proxy_t * p;
|
|
|
|
JS_GET_PROXY(p, pAdsPlugin);
|
|
|
|
|
|
|
|
if (! p) return;
|
|
|
|
jsval dataVal[2];
|
|
|
|
jsval arg = OBJECT_TO_JSVAL(p->obj);
|
|
|
|
dataVal[0] = arg;
|
|
|
|
dataVal[1] = INT_TO_JSVAL(points);
|
2013-04-24 09:43:40 +08:00
|
|
|
|
2013-06-20 16:31:12 +08:00
|
|
|
JSObject* obj = _JSDelegate;
|
2013-04-27 11:32:12 +08:00
|
|
|
JSBool bRet = JS_HasProperty(cx, obj, "onPlayerGetPoints", &hasAction);
|
2013-04-24 09:43:40 +08:00
|
|
|
if (bRet && hasAction) {
|
2013-04-27 11:32:12 +08:00
|
|
|
if(!JS_GetProperty(cx, obj, "onPlayerGetPoints", &temp_retval)) {
|
2013-04-24 09:43:40 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(temp_retval == JSVAL_VOID) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
JSAutoCompartment ac(cx, obj);
|
2013-04-27 11:32:12 +08:00
|
|
|
JS_CallFunctionName(cx, obj, "onPlayerGetPoints",
|
|
|
|
2, NULL, &retval);
|
2013-04-24 09:43:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-27 11:32:12 +08:00
|
|
|
void setJSDelegate(JSObject* pJSDelegate)
|
2013-04-07 16:58:26 +08:00
|
|
|
{
|
2013-06-20 16:31:12 +08:00
|
|
|
_JSDelegate = pJSDelegate;
|
2013-04-27 11:32:12 +08:00
|
|
|
}
|
2013-04-07 16:58:26 +08:00
|
|
|
|
2013-04-27 11:32:12 +08:00
|
|
|
private:
|
2013-06-20 16:31:12 +08:00
|
|
|
JSObject* _JSDelegate;
|
2013-04-27 11:32:12 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
JSBool js_pluginx_ProtocolAds_setAdsListener(JSContext *cx, uint32_t argc, jsval *vp)
|
|
|
|
{
|
|
|
|
s_cx = cx;
|
|
|
|
jsval *argv = JS_ARGV(cx, vp);
|
|
|
|
JSObject *obj = JS_THIS_OBJECT(cx, vp);
|
|
|
|
js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj);
|
|
|
|
cocos2d::plugin::ProtocolAds* cobj = (cocos2d::plugin::ProtocolAds *)(proxy ? proxy->ptr : NULL);
|
|
|
|
JSBool ok = JS_TRUE;
|
|
|
|
if (argc == 1) {
|
|
|
|
// save the delegate
|
|
|
|
JSObject *jsDelegate = JSVAL_TO_OBJECT(argv[0]);
|
|
|
|
Pluginx_AdsListener* nativeDelegate = new Pluginx_AdsListener();
|
|
|
|
nativeDelegate->setJSDelegate(jsDelegate);
|
|
|
|
cobj->setAdsListener(nativeDelegate);
|
2013-04-07 16:58:26 +08:00
|
|
|
|
2013-04-27 11:32:12 +08:00
|
|
|
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
|
|
|
return JS_TRUE;
|
2013-04-07 16:58:26 +08:00
|
|
|
}
|
|
|
|
|
2013-04-27 11:32:12 +08:00
|
|
|
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
class Pluginx_ShareResult : public cocos2d::plugin::ShareResultListener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void onShareResult(cocos2d::plugin::ShareResultCode ret, const char* msg)
|
2013-04-24 09:43:40 +08:00
|
|
|
{
|
|
|
|
JSContext* cx = s_cx;
|
|
|
|
|
|
|
|
JSBool hasAction;
|
|
|
|
jsval retval;
|
|
|
|
jsval temp_retval;
|
2013-04-27 11:32:12 +08:00
|
|
|
jsval dataVal[2];
|
|
|
|
dataVal[0] = INT_TO_JSVAL(ret);
|
|
|
|
std::string strMsgInfo = msg;
|
|
|
|
dataVal[1] = std_string_to_jsval(cx, strMsgInfo);
|
2013-04-24 09:43:40 +08:00
|
|
|
|
2013-06-20 16:31:12 +08:00
|
|
|
JSObject* obj = _JSDelegate;
|
2013-04-27 11:32:12 +08:00
|
|
|
|
|
|
|
if (JS_HasProperty(cx, obj, "onShareResult", &hasAction) && hasAction) {
|
|
|
|
if(!JS_GetProperty(cx, obj, "onShareResult", &temp_retval)) {
|
2013-04-24 09:43:40 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(temp_retval == JSVAL_VOID) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
JSAutoCompartment ac(cx, obj);
|
2013-04-27 11:32:12 +08:00
|
|
|
JS_CallFunctionName(cx, obj, "onShareResult",
|
|
|
|
2, dataVal, &retval);
|
2013-04-24 09:43:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-07 16:58:26 +08:00
|
|
|
void setJSDelegate(JSObject* pJSDelegate)
|
|
|
|
{
|
2013-06-20 16:31:12 +08:00
|
|
|
_JSDelegate = pJSDelegate;
|
2013-04-07 16:58:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-06-20 16:31:12 +08:00
|
|
|
JSObject* _JSDelegate;
|
2013-04-07 16:58:26 +08:00
|
|
|
};
|
|
|
|
|
2013-06-24 17:00:02 +08:00
|
|
|
JSBool js_pluginx_ProtocolShare_setResultListener(JSContext *cx, uint32_t argc, jsval *vp)
|
2013-04-07 16:58:26 +08:00
|
|
|
{
|
|
|
|
s_cx = cx;
|
|
|
|
jsval *argv = JS_ARGV(cx, vp);
|
2013-04-27 11:32:12 +08:00
|
|
|
JSObject *obj = JS_THIS_OBJECT(cx, vp);
|
|
|
|
js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj);
|
2013-06-24 17:00:02 +08:00
|
|
|
cocos2d::plugin::ProtocolShare* cobj = (cocos2d::plugin::ProtocolShare *)(proxy ? proxy->ptr : NULL);
|
2013-04-07 16:58:26 +08:00
|
|
|
JSBool ok = JS_TRUE;
|
2013-04-27 11:32:12 +08:00
|
|
|
|
2013-04-07 16:58:26 +08:00
|
|
|
if (argc == 1) {
|
|
|
|
// save the delegate
|
|
|
|
JSObject *jsDelegate = JSVAL_TO_OBJECT(argv[0]);
|
2013-04-27 11:32:12 +08:00
|
|
|
Pluginx_ShareResult* nativeDelegate = new Pluginx_ShareResult();
|
2013-04-07 16:58:26 +08:00
|
|
|
nativeDelegate->setJSDelegate(jsDelegate);
|
2013-04-27 11:32:12 +08:00
|
|
|
cobj->setResultListener(nativeDelegate);
|
2013-04-07 16:58:26 +08:00
|
|
|
|
|
|
|
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
2013-07-25 16:07:09 +08:00
|
|
|
|
|
|
|
class Pluginx_SocialResult : public cocos2d::plugin::SocialListener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void onSocialResult(cocos2d::plugin::SocialRetCode ret, const char* msg)
|
|
|
|
{
|
|
|
|
JSContext* cx = s_cx;
|
|
|
|
|
|
|
|
JSBool hasAction;
|
|
|
|
jsval retval;
|
|
|
|
jsval temp_retval;
|
|
|
|
jsval dataVal[2];
|
|
|
|
dataVal[0] = INT_TO_JSVAL(ret);
|
|
|
|
std::string strMsgInfo = msg;
|
|
|
|
dataVal[1] = std_string_to_jsval(cx, strMsgInfo);
|
|
|
|
|
|
|
|
JSObject* obj = _JSDelegate;
|
|
|
|
|
|
|
|
if (JS_HasProperty(cx, obj, "onSocialResult", &hasAction) && hasAction) {
|
|
|
|
if(!JS_GetProperty(cx, obj, "onSocialResult", &temp_retval)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(temp_retval == JSVAL_VOID) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
JSAutoCompartment ac(cx, obj);
|
|
|
|
JS_CallFunctionName(cx, obj, "onSocialResult",
|
|
|
|
2, dataVal, &retval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void setJSDelegate(JSObject* pJSDelegate)
|
|
|
|
{
|
|
|
|
_JSDelegate = pJSDelegate;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
JSObject* _JSDelegate;
|
|
|
|
};
|
|
|
|
|
|
|
|
JSBool js_pluginx_ProtocolSocial_setListener(JSContext *cx, uint32_t argc, jsval *vp)
|
|
|
|
{
|
|
|
|
s_cx = cx;
|
|
|
|
jsval *argv = JS_ARGV(cx, vp);
|
|
|
|
JSObject *obj = JS_THIS_OBJECT(cx, vp);
|
|
|
|
js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj);
|
|
|
|
cocos2d::plugin::ProtocolSocial* cobj = (cocos2d::plugin::ProtocolSocial *)(proxy ? proxy->ptr : NULL);
|
|
|
|
JSBool ok = JS_TRUE;
|
|
|
|
|
|
|
|
if (argc == 1) {
|
|
|
|
// save the delegate
|
|
|
|
JSObject *jsDelegate = JSVAL_TO_OBJECT(argv[0]);
|
|
|
|
Pluginx_SocialResult* nativeDelegate = new Pluginx_SocialResult();
|
|
|
|
nativeDelegate->setJSDelegate(jsDelegate);
|
|
|
|
cobj->setListener(nativeDelegate);
|
|
|
|
|
|
|
|
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
class Pluginx_UserActionListener : public cocos2d::plugin::UserActionListener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void onActionResult(ProtocolUser* userPlugin, cocos2d::plugin::UserActionResultCode ret, const char* msg)
|
|
|
|
{
|
|
|
|
JSContext* cx = s_cx;
|
|
|
|
|
|
|
|
JSBool hasAction;
|
|
|
|
jsval retval;
|
|
|
|
jsval temp_retval;
|
|
|
|
|
|
|
|
js_proxy_t * p;
|
|
|
|
JS_GET_PROXY(p, userPlugin);
|
|
|
|
|
|
|
|
if (! p) return;
|
|
|
|
jsval dataVal[3];
|
|
|
|
jsval arg1 = OBJECT_TO_JSVAL(p->obj);
|
|
|
|
dataVal[0] = arg1;
|
|
|
|
dataVal[1] = INT_TO_JSVAL(ret);
|
|
|
|
std::string strMsgInfo = msg;
|
|
|
|
dataVal[2] = std_string_to_jsval(cx, strMsgInfo);
|
|
|
|
|
|
|
|
JSObject* obj = _JSDelegate;
|
|
|
|
|
|
|
|
if (JS_HasProperty(cx, obj, "onActionResult", &hasAction) && hasAction) {
|
|
|
|
if(!JS_GetProperty(cx, obj, "onActionResult", &temp_retval)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(temp_retval == JSVAL_VOID) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
JSAutoCompartment ac(cx, obj);
|
|
|
|
JS_CallFunctionName(cx, obj, "onActionResult",
|
|
|
|
3, dataVal, &retval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void setJSDelegate(JSObject* pJSDelegate)
|
|
|
|
{
|
|
|
|
_JSDelegate = pJSDelegate;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
JSObject* _JSDelegate;
|
|
|
|
};
|
|
|
|
|
|
|
|
JSBool js_pluginx_ProtocolUser_setActionListener(JSContext *cx, uint32_t argc, jsval *vp)
|
|
|
|
{
|
|
|
|
s_cx = cx;
|
|
|
|
jsval *argv = JS_ARGV(cx, vp);
|
|
|
|
JSObject *obj = JS_THIS_OBJECT(cx, vp);
|
|
|
|
js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj);
|
|
|
|
cocos2d::plugin::ProtocolUser* cobj = (cocos2d::plugin::ProtocolUser *)(proxy ? proxy->ptr : NULL);
|
|
|
|
JSBool ok = JS_TRUE;
|
|
|
|
|
|
|
|
if (argc == 1) {
|
|
|
|
// save the delegate
|
|
|
|
JSObject *jsDelegate = JSVAL_TO_OBJECT(argv[0]);
|
|
|
|
Pluginx_UserActionListener* nativeDelegate = new Pluginx_UserActionListener();
|
|
|
|
nativeDelegate->setJSDelegate(jsDelegate);
|
|
|
|
cobj->setActionListener(nativeDelegate);
|
|
|
|
|
|
|
|
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
|