Does jsb support

Does jsb support
0.0 0


as the title says, thanks!


Cpp supports, but we haven’t exposed it to JS. Could you finish that ?


Sorry that i don’t know how to bind cpp to js, do you guys plan to expose it in the near future?


Can the Cpp version’s emit function pass in a function as a callback like the js version does?


I also need it , but i haven’t experience with jsb , socketio interface , who can implement that ?


@James Chen: I wonder if it’s possible to write a multiplayer game with Cocos2d HTML5 + completely in javascript and then run it natively with Cocos2d-X?

Would the approach be:

  1. Create a C++ client and interface that back to the javascript engine, or
  2. Run within the javascript engine?

Here’s a few examples:

I’m willing to help out on this. :slight_smile:


i think you can use websocket in jsb


Confirmed. You can now use WebSocket in jsb. Tested with Cocos2d-X 2.2.2 iOS. Good job Cocos2d-X team!

It’s possible to run by mimicking window.location, including some code for setTimeout/clearTimeout and then including Like this:

// mimic window.location
this.location = "";

// implement timers
this.timerLoop = makeWindowTimer(this, function (ms) { /*sleep(ms / 1000);*/ });

// load

Get timers.js from here:

Note: I couldn’t figure out how to get timers.js to actually work. You’ll notice the sleep(ms/1000) is commented out above. It seems that if setTimeout/clearTimeout is defined, is happy. So if anyone knows how to get setTimeout() to function correctly, please share.


Here’s a script that verifies WebSocket is accessible via jsb:

function testWebSocket()
    var ws = new WebSocket("ws://");

    ws.onopen = function(evt)
        ws.send("Hello WebSocket中文, I'm a text message.");

    ws.onmessage = function(evt)
        cc.log("Test WebSocket response: " +;

    ws.onerror = function(evt) {
        cc.log("Test WebSocket error");

    ws.onclose = function(evt) {
        cc.log("Test WebSocket closed");
        ws = null;


Cocos2d: JS: Test WebSocket response: Hello WebSocket中文, I'm a text message.

Cocos2d: websocket (0xa5b05d0) connection closed by client
Cocos2d: connection closing..
Cocos2d: JS: Test WebSocket closed