Skip to content

Commit 0069f7b

Browse files
James Chenminggo
authored andcommitted
JSB SocketIO.connect supports to pass a CA cert file (cocos2d#17736)
* JSB SocketIO.connect supports to pass a CA cert file * The second parameter of SocketIO.connect function is probably a `option` object. JSB just ignores it.
1 parent 05f5af0 commit 0069f7b

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

cocos/scripting/js-bindings/manual/network/jsb_socketio.cpp

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,20 +143,45 @@ bool js_cocos2dx_SocketIO_connect(JSContext* cx, uint32_t argc, jsval* vp)
143143
CCLOG("JSB SocketIO.connect method called");
144144

145145
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
146-
if (argc == 1 || argc == 2)
146+
if (argc >= 1 && argc <= 3)
147147
{
148148
std::string url;
149+
std::string caFilePath;
150+
bool ok = false;
149151

150-
do
152+
ok = jsval_to_std_string(cx, args[0], &url);
153+
JSB_PRECONDITION2( ok, cx, false, "Error processing arguments");
154+
155+
if (argc == 2)
151156
{
152-
bool ok = jsval_to_std_string(cx, args.get(0), &url);
153-
JSB_PRECONDITION2( ok, cx, false, "Error processing arguments");
154-
} while (0);
157+
if (args[1].isObject())
158+
{
159+
// Just ignore the option argument
160+
}
161+
else if (args[1].isString())
162+
{
163+
// Assume it's CA root file path
164+
ok = jsval_to_std_string(cx, args[1], &caFilePath);
165+
JSB_PRECONDITION2( ok, cx, false, "Error processing arguments");
166+
}
167+
}
168+
169+
if (argc == 3)
170+
{
171+
// Just ignore the option argument
172+
173+
if (args[2].isString())
174+
{
175+
// Assume it's CA root file path
176+
ok = jsval_to_std_string(cx, args[2], &caFilePath);
177+
JSB_PRECONDITION2( ok, cx, false, "Error processing arguments");
178+
}
179+
}
155180

156181
JSB_SocketIODelegate* siodelegate = new (std::nothrow) JSB_SocketIODelegate();
157182

158183
CCLOG("Calling native SocketIO.connect method");
159-
SIOClient* ret = SocketIO::connect(url, *siodelegate);
184+
SIOClient* ret = SocketIO::connect(url, *siodelegate, caFilePath);
160185

161186
jsval jsret;
162187
do

0 commit comments

Comments
 (0)