discordjs / RPC

A simple RPC client for Discord
MIT License
467 stars 192 forks source link

IPC transport is broken #31

Closed TotomInc closed 6 years ago

TotomInc commented 6 years ago

I'm trying to use the DiscordJS RPC as a userscript with Tampermonkey (original issue which redirect me to this repo here). I am unable to use the IPC transport (since websocket is in private beta according to Discord docs).

Here is the sample code I'm trying to make it work on Chrome v66.0.3359.139:

    // I require DiscordJS/RPC from JSDelivr:
    // https://cdn.jsdelivr.net/npm/discord-rpc@3.0.0-beta.10/browser.min.js

    const clientID = 'my-client-id';
    const accessToken = 'my-access-token';
    const scopes = ['rpc', 'rpc.api'];

    const client = new DiscordRPC.Client({ transport: 'ipc' });

    client.on('ready', () => {
        console.log('Logged in as', client.application.name);
        console.log('Authed for user', client.user.tag);
    });

    client.login(clientID, { accessToken, scopes });

Here is the error I have:

    TypeError: t is not a constructor
        at new e.exports (userscript.html?id=49e3d5d8-3aeb-40a2-96dc-0270cf660ee9:8)
        at eval (userscript.html?id=49e3d5d8-3aeb-40a2-96dc-0270cf660ee9:30)
        at Window.eval (userscript.html?id=49e3d5d8-3aeb-40a2-96dc-0270cf660ee9:40)
        at <anonymous>:2:120
        at eval (userscript.html?id=49e3d5d8-3aeb-40a2-96dc-0270cf660ee9:2)
        at eval (userscript.html?id=49e3d5d8-3aeb-40a2-96dc-0270cf660ee9:3)
        at Object.eval (userscript.html?id=49e3d5d8-3aeb-40a2-96dc-0270cf660ee9:41)
        at eval (userscript.html?id=49e3d5d8-3aeb-40a2-96dc-0270cf660ee9:43)
        at eval (<anonymous>)
        at <anonymous>:2:120

which points to this source-code (no source-map in production, can't really help on the debugging):

constructor(e={}) {
    super(Object.assign({
        _tokenType: "Bearer"
    }, e)),
    this.accessToken = null,
    this.clientID = null,
    this.application = null,
    this.user = null;
    const t = o[e.transport];
    if (!t)
        throw new T("RPC_INVALID_TRANSPORT",e.transport);
    this.transport = new t(this),
    this.transport.on("message", this._onRpcMessage.bind(this)),
    this._expecting = new Map,
    this._subscriptions = new Map,
    this.users = I(e=>new f(this,e)),
    this.channels = I((e,t)=>E.create(this, e, t)),
    this.guilds = I(e=>new m(this,e))
}

EDIT: source-code that is causing the bug

https://github.com/discordjs/RPC/blob/175aa54a7f12b4e2958605b874aafdb3adeb0c63/src/Client.js#L46-L92

devsnek commented 6 years ago

you can't use ipc from a tampermonkey script anyway, and i don't really feel like taking minified stack traces so i'm going to consider this not a bug