Skip to content

Commit

Permalink
null checking
Browse files Browse the repository at this point in the history
Signed-off-by: Sahil Gupte <[email protected]>
  • Loading branch information
Ovenoboyo committed Dec 22, 2021
1 parent c4bf850 commit a0e9888
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
31 changes: 17 additions & 14 deletions src/discordRPC/ipcTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class IPCTransport {
}

let raw: any;
if (working.full === '') {
if (working && working.full === '') {
working.op = packet.readInt32LE(0);
const len = packet.readInt32LE(4);
raw = packet.slice(8, len + 8);
Expand All @@ -99,7 +99,7 @@ export class IPCTransport {

try {
const data = JSON.parse(working.full + raw);
return { data, op: working.op }
return { data, op: working ? working.op : OPCodes.CLOSE }
} catch (err) {
working.full += raw;
}
Expand All @@ -126,22 +126,25 @@ export class IPCTransport {
this.eventHandler.emit('message', data);
}

private handleCloseCall(data: any) {
private handleCloseCall(data?: any) {
this.eventHandler.emit('close', data);
}

private async onReadable({ op, data }) {
if (op === OPCodes.PING) {
return this.handlePingCall(data)
}
private async onReadable(d: { op: number, data: any }) {
if (d) {
if (d.op === OPCodes.PING) {
return this.handlePingCall(d.data)
}

if (op === OPCodes.FRAME) {
return this.handleFrameCall(data)
}
if (d.op === OPCodes.FRAME) {
return this.handleFrameCall(d.data)
}

if (op === OPCodes.CLOSE) {
return this.handleCloseCall(data)
if (d.op === OPCodes.CLOSE) {
return this.handleCloseCall(d.data)
}
}
return this.handleCloseCall()
}

public async connect() {
Expand All @@ -165,9 +168,9 @@ export class IPCTransport {
}

public async close() {
return new Promise((r) => {
return new Promise<void>((r) => {
this.eventHandler.once('close', r);
this.send({}, OPCodes.CLOSE);
this.send('', OPCodes.CLOSE);
this.socket.end();
});
}
Expand Down
1 change: 0 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export class MyExtension implements MoosyncExtensionTemplate {
}

async onStopped() {
console.log('closing')
await close()
}

Expand Down

0 comments on commit a0e9888

Please sign in to comment.