GitHub | Documentation | Become a Patron

Is there a way to use colyseus.js on a node environment in a non "hack" way ?



  • For the moment I have found one can "hack" it using something like:

      const Storage = require("dom-storage");
      global.WebSocket = require("uws");
      global.window = global;
      global.localStorage = new Storage(null, { strict: true });
    

    But it has many problems, like populating the global namespace.
    If this is still not good enough, one may prefer to create colyseus.js/server and use that inside node. I don't believe it should be required a new package to make a node integration, mostly because a lot of the code should be the same.


  • administrators

    Thanks for sharing, @holywyvern!

    This is not as bad as I thought it would be. You'll want to use this just for testing purposes, right?

    The JavaScript client already does a couple of checks to support multiple client-side environments, such as React Native and Cocos Creator.

    I'm not sure it's possible to have optional dependencies just for the Node.js environment. It wouldn't be feasible to have dom-storage and uws as dependencies for the client-side.

    Let me know if you have any ideas. Cheers!


  • administrators

    @holywyvern I've added a new issue about this here: https://github.com/gamestdio/colyseus.js/issues/25