Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to specify the protocol (SSL) #68

Closed
greaterweb opened this issue May 1, 2020 · 9 comments
Closed

Allow to specify the protocol (SSL) #68

greaterweb opened this issue May 1, 2020 · 9 comments

Comments

@greaterweb
Copy link

The createMatchMakeRequest method currently only supports requests with the http protocol, it would be nice to have support for https.

I think the constructor could be modified to accept an optional second parameter to either explicitly set the protocol for http requests or it could be a flag to indicate that https is available.

// explicitly set the protocol
enum SupportedProtocols {
  HTTP = 'http',
  HTTPS = 'https',
}
const client = new Colyseus.Client('ws://my-awesome.game', SupportedProtocols.HTTPS);

// or have a flag to use https
const USE_HTTPS = true;
const client = new Colyseus.Client('ws://my-awesome.game', USE_HTTPS);

As the parameter could be optional/have defaults this could viewed as a backward compatible enhancement.

I don't do have much game development experience but have been enjoying using this library, thanks for sharing it! I'd be happy to provide a PR for this feature if you have a preference to how you'd like to see this implemented.

Keep up the great work!

@endel
Copy link
Member

endel commented May 1, 2020

Hi @greaterweb, thanks for the kind words.

If you use wss:// instead of ws:// it works though :)

I agree that the Client could have some options to "toggle" this automatically, as we currently do a hacky thing to perform the http(s) requests here: https://github.com/colyseus/colyseus.js/blob/master/src/Client.ts#L83

@greaterweb
Copy link
Author

Thank you, @endel! That solution worked :)

@babacarcissedia
Copy link

nice solution by the way. I am closing #77

Thank you 👍

@endel endel closed this as completed Oct 20, 2020
@endel endel changed the title (feature) support https in Client requests Allow to specify the protocol (SSL) Oct 20, 2020
@endel
Copy link
Member

endel commented Oct 20, 2020

Related: colyseus/colyseus-unity-sdk#120

@endel endel reopened this Oct 20, 2020
@endel endel pinned this issue Oct 20, 2020
@endel endel added the feature label Oct 20, 2020
leNicDev added a commit to leNicDev/colyseus.js that referenced this issue Nov 22, 2020
@ttcong194
Copy link

ttcong194 commented Dec 9, 2020

@endel Currently, I use colyseus.js on cocos creator. My sever use https and wss. I saw Connection.ts of Client.ts extend from WebSocket. Everything is right on web but as I built my project to android, I encountered an error . it says websocket on native android of cocos doesn't support ssl. You can see the problem here('cocos/engine-native#1722')
There is one solution that add cacert.pem to Websocket like that

let ws = new WebSocket( url, [], cc.url.raw("resources/cacert.pem") );

I saw WebSocketClient in package @gamestdio extend WebSocket. But I dont know how to insert cacert.pem to Connection of Client?

@ttcong194
Copy link

@luckybk93 Không biết bạn dùng client là gì bạn. Client mình là cocos creator. Trong example của nó có file cacert.pem luôn bạn ah.
https://github.com/cocos-creator/example-cases/blob/v2.4.3/assets/cases/05_scripting/10_network/cacert.pem

@luckybk93
Copy link

For Cocos Creator
The solution in here:
cocos/engine-native#1722
Download file pem
https://curl.haxx.se/docs/caextract.html
Config file pem in here:
https://github.com/id-ilych/cc-web-socket-issue

@luckybk93
Copy link

luckybk93 commented Dec 31, 2020 via email

@endel
Copy link
Member

endel commented May 5, 2023

On version 0.15, this can be achieved like this:

import { Client } from "colyseus.js";

const client = new Client({
  hostname: "us1.game.io", 
  secure: true,
  port: 1234, // optional
});

@endel endel closed this as completed May 5, 2023
@endel endel unpinned this issue May 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants