Skip to content

Commit 9f3c3a5

Browse files
committed
some cleanup
1 parent 6991599 commit 9f3c3a5

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

src/client.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ class RPCClient extends EventEmitter {
5858
headers: {
5959
Authorization: `Bearer ${this.accessToken}`,
6060
},
61-
}).then((r) => r.json());
61+
}).then((r) => {
62+
if (!r.ok) {
63+
throw new Error(r.status);
64+
}
65+
return r.json();
66+
});
6267

6368
this.fetch.endpoint = 'https://discord.com/api';
6469

@@ -212,7 +217,6 @@ class RPCClient extends EventEmitter {
212217
scopes,
213218
client_id: this.clientId,
214219
rpc_token: rpcToken,
215-
redirect_uri: redirectUri,
216220
});
217221

218222
const response = await this.fetch('POST', '/oauth2/token', {

src/transports/ipc.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ async function findEndpoint(tries = 0) {
4747
const endpoint = `http://127.0.0.1:${6463 + (tries % 10)}`;
4848
try {
4949
const r = await fetch(endpoint);
50-
if (r.status !== 401) {
51-
return findEndpoint(tries + 1);
50+
if (r.status === 404) {
51+
return endpoint;
5252
}
53-
return endpoint;
53+
return findEndpoint(tries + 1);
5454
} catch (e) {
5555
return findEndpoint(tries + 1);
5656
}

src/transports/websocket.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@ class WebSocketTransport extends EventEmitter {
1717
this.tries = 0;
1818
}
1919

20-
async connect(options, tries = this.tries) {
20+
async connect(tries = this.tries) {
2121
if (this.connected) {
2222
return;
2323
}
2424
const port = 6463 + (tries % 10);
2525
this.hostAndPort = `127.0.0.1:${port}`;
2626
const ws = this.ws = new WebSocket(
2727
`ws://${this.hostAndPort}/?v=1&client_id=${this.client.clientId}`,
28+
{
29+
origin: this.client.options.origin,
30+
},
2831
);
2932
ws.onopen = this.onOpen.bind(this);
3033
ws.onclose = ws.onerror = this.onClose.bind(this);
@@ -65,7 +68,7 @@ class WebSocketTransport extends EventEmitter {
6568
}
6669
if (!derr) {
6770
// eslint-disable-next-line no-plusplus
68-
setTimeout(() => this.connect(undefined, e.code === 1006 ? ++this.tries : 0), 250);
71+
setTimeout(() => this.connect(e.code === 1006 ? ++this.tries : 0), 250);
6972
}
7073
}
7174
}

0 commit comments

Comments
 (0)