Skip to content

Commit

Permalink
feat: bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
xhayper committed Oct 24, 2022
1 parent 0f816de commit 6686d8b
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ NOTE: Require `--unstable --allow-read --allow-env --allow-write --allow-net`!
## Example

```ts
import { Client } from "https://deno.land/x/discord_rpc_deno@1.0.10/mod.ts";
import { Client } from "https://deno.land/x/discord_rpc_deno@1.0.11/mod.ts";

const client = new Client({
clientId: "123456789012345678",
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_oauth.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Client } from "https://deno.land/x/discord_rpc_deno@1.0.10/mod.ts";
import { Client } from "https://deno.land/x/discord_rpc_deno@1.0.11/mod.ts";

const client = new Client({
clientId: "123456789012345678",
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_oauth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Client } from "https://deno.land/x/discord_rpc_deno@1.0.10/mod.ts";
import { Client } from "https://deno.land/x/discord_rpc_deno@1.0.11/mod.ts";

const client = new Client({
clientId: "123456789012345678",
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_status.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Client } from "https://deno.land/x/discord_rpc_deno@1.0.10/mod.ts";
import { Client } from "https://deno.land/x/discord_rpc_deno@1.0.11/mod.ts";

const client = new Client({
clientId: "123456789012345678",
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_status.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Client } from "https://deno.land/x/discord_rpc_deno@1.0.10/mod.ts";
import { Client } from "https://deno.land/x/discord_rpc_deno@1.0.11/mod.ts";

const client = new Client({
clientId: "123456789012345678",
Expand Down
54 changes: 30 additions & 24 deletions src/transport/IPC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export enum IPC_OPCODE {
}

export type FormatFunction = (
id: number
id: number,
) => [path: string, skipCheck?: boolean];

export type IPCTransportOptions = {
Expand All @@ -39,7 +39,7 @@ const defaultPathList: FormatFunction[] = [
const { XDG_RUNTIME_DIR, TMPDIR, TMP, TEMP } = Deno.env.toObject();

const prefix = Deno.realPathSync(
XDG_RUNTIME_DIR ?? TMPDIR ?? TMP ?? TEMP ?? `${path.sep}tmp`
XDG_RUNTIME_DIR ?? TMPDIR ?? TMP ?? TEMP ?? `${path.sep}tmp`,
);
return [path.join(prefix, `discord-ipc-${id}`)];
},
Expand All @@ -51,7 +51,7 @@ const defaultPathList: FormatFunction[] = [
const { XDG_RUNTIME_DIR, TMPDIR, TMP, TEMP } = Deno.env.toObject();

const prefix = Deno.realPathSync(
XDG_RUNTIME_DIR ?? TMPDIR ?? TMP ?? TEMP ?? `${path.sep}tmp`
XDG_RUNTIME_DIR ?? TMPDIR ?? TMP ?? TEMP ?? `${path.sep}tmp`,
);
return [path.join(prefix, "snap.discord", `discord-ipc-${id}`)];
},
Expand All @@ -63,7 +63,7 @@ const defaultPathList: FormatFunction[] = [
const { XDG_RUNTIME_DIR, TMPDIR, TMP, TEMP } = Deno.env.toObject();

const prefix = Deno.realPathSync(
XDG_RUNTIME_DIR ?? TMPDIR ?? TMP ?? TEMP ?? `${path.sep}tmp`
XDG_RUNTIME_DIR ?? TMPDIR ?? TMP ?? TEMP ?? `${path.sep}tmp`,
);
return [
path.join(prefix, "app", "com.discordapp.Discord", `discord-ipc-${id}`),
Expand Down Expand Up @@ -129,7 +129,7 @@ export class IPCTransport extends Transport {
};

const handleSocketId = async (
id: number
id: number,
): Promise<net.Socket | undefined> => {
const [socketPath, skipCheck] = formatFunc(id);

Expand Down Expand Up @@ -161,8 +161,8 @@ export class IPCTransport extends Transport {
reject(
new RPCError(
CUSTOM_RPC_ERROR_CODE.RPC_COULD_NOT_CONNECT,
"Could not connect"
)
"Could not connect",
),
);
});
}
Expand All @@ -181,31 +181,35 @@ export class IPCTransport extends Transport {
v: 1,
client_id: this.client.clientId,
},
IPC_OPCODE.HANDSHAKE
IPC_OPCODE.HANDSHAKE,
);

this.socket.on("readable", () => {
let data = this.socket?.read() as Buffer | undefined;
if (!data) return;
this.client.emit(
"debug",
`SERVER => CLIENT | ${data
.toString("hex")
.match(/.{1,2}/g)
?.join(" ")
.toUpperCase()}`
`SERVER => CLIENT | ${
data
.toString("hex")
.match(/.{1,2}/g)
?.join(" ")
.toUpperCase()
}`,
);

do {
const chunk = this.socket?.read() as Buffer | undefined;
if (!chunk) break;
this.client.emit(
"debug",
`SERVER => CLIENT | ${chunk
.toString("hex")
.match(/.{1,2}/g)
?.join(" ")
.toUpperCase()}`
`SERVER => CLIENT | ${
chunk
.toString("hex")
.match(/.{1,2}/g)
?.join(" ")
.toUpperCase()
}`,
);
data = Buffer.concat([data, chunk]);
} while (true);
Expand All @@ -217,7 +221,7 @@ export class IPCTransport extends Transport {
this.client.emit(
"debug",
`SERVER => CLIENT | OPCODE.${IPC_OPCODE[op]} |`,
parsedData
parsedData,
);

switch (op) {
Expand All @@ -243,11 +247,13 @@ export class IPCTransport extends Transport {
send(message?: any, op: IPC_OPCODE = IPC_OPCODE.FRAME): void {
this.client.emit(
"debug",
`| [CLIENT] => [SERVER] | OPCODE.${IPC_OPCODE[op]} | ${JSON.stringify(
message,
null,
2
)}`
`| [CLIENT] => [SERVER] | OPCODE.${IPC_OPCODE[op]} | ${
JSON.stringify(
message,
null,
2,
)
}`,
);

const dataBuffer = message
Expand Down

0 comments on commit 6686d8b

Please sign in to comment.