gramjs icon indicating copy to clipboard operation
gramjs copied to clipboard

incorrect wss connection url in test DC

Open aguerrieri82 opened this issue 4 years ago • 4 comments

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

aguerrieri82 avatar Sep 19 '21 09:09 aguerrieri82

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

painor avatar Sep 19 '21 09:09 painor

In my understanding setDC accept these params, and then call getWebSocketLink to 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

aguerrieri82 avatar Sep 19 '21 09:09 aguerrieri82

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.

painor avatar Sep 19 '21 10:09 painor

seems i don't have permission to create a PR

aguerrieri82 avatar Sep 19 '21 11:09 aguerrieri82

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;

davie-robertson avatar May 12 '23 16:05 davie-robertson