gram-js / gramjs

NodeJS/Browser MTProto API Telegram client library,
MIT License
1.32k stars 181 forks source link

incorrect wss connection url in test DC #159

Open aguerrieri82 opened 3 years ago

aguerrieri82 commented 3 years ago

when using the test datacenter over https, the url should be with the domain name (es. venus.web.telegram.org for DC 2), and the path should include "_test" after "/apiws". I suggest to modify "setDC" function with an additional argument (isTest) in order to build the correct url

npm packet version: 1.8.15

painor commented 3 years ago

you can just pass that url to setDC (with _test)

aguerrieri82 commented 3 years ago

In my understanding setDC accept these params, and then call getWebSocketLinkto build the url:

abstract setDC(dcId: number, serverAddress: string, port: number): void;

and currently there is no way to pass the full url (tell me if I'm wrong)

Current code (extensions/PromisedWebSockets.ts)

    getWebSocketLink(ip: string, port: number) {
        if (port === 443) {
            return `wss://${ip}:${port}/apiws`;
        } else {
            return `ws://${ip}:${port}/apiws`;
        }
    }

my edit:


abstract setDC(dcId: number, serverAddress: string, port: number, isTest = false): void;

//
getWebSocketLink(ip: string, port: number, isTest = false) {
    if (port === 443) // just over https, in http you can specify the ip {
        let result = `wss://${ip}:${port}/apiws`;
        if (isTest)
            result += "_test";
        return test;
    } else {
        return `ws://${ip}:${port}/apiws`;
    }
}

ALSO

Session interface for:

abstract save(): void;

should return string

painor commented 3 years ago

if you want you can add a PR for that.

About the session interface. Sessions can be of different types and some of them don't return string in save. if you want to use StringSession you'll need to cast it so TS can understand it.

aguerrieri82 commented 3 years ago

seems i don't have permission to create a PR

davie-robertson commented 1 year ago

if you want you can add a PR for that.

About the session interface. Sessions can be of different types and some of them don't return string in save. if you want to use StringSession you'll need to cast it so TS can understand it.

I was just looking at https://gram.js.org/beta/classes/sessions.StringSession.html#save and it is shown as returning a string rather than a void shown in Abstract.d.ts so I'm keeping my linter happy by:

const sessionString: string = client.session.save() as unknown as string;