Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 16 additions & 19 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export class RedisAdapter extends Adapter {
*
* @private
*/
private onmessage(pattern, channel, msg) {
private async onmessage(pattern, channel, msg) {
channel = channel.toString();

const channelMatches = channel.startsWith(this.channel);
Expand All @@ -212,7 +212,7 @@ export class RedisAdapter extends Adapter {
return debug("ignore unknown room %s", room);
}

const args = this.parser.decode(msg);
const args = await this.parser.decode(msg);

const [uid, packet, opts] = args;
if (this.uid === uid) return debug("ignore same uid");
Expand Down Expand Up @@ -257,7 +257,7 @@ export class RedisAdapter extends Adapter {
if (msg[0] === 0x7b) {
request = JSON.parse(msg.toString());
} else {
request = this.parser.decode(msg);
request = await this.parser.decode(msg);
}
} catch (err) {
debug("ignoring malformed request");
Expand Down Expand Up @@ -450,17 +450,14 @@ export class RedisAdapter extends Adapter {
})
);
},
(arg) => {
async (arg) => {
debug("received acknowledgement with value %j", arg);

this.publishResponse(
request,
this.parser.encode({
type: RequestType.BROADCAST_ACK,
requestId: request.requestId,
packet: arg,
})
);
const encodedData = await this.parser.encode({
type: RequestType.BROADCAST_ACK,
requestId: request.requestId,
packet: arg,
});
this.publishResponse(request, encodedData);
}
);
break;
Expand Down Expand Up @@ -490,15 +487,15 @@ export class RedisAdapter extends Adapter {
*
* @private
*/
private onresponse(channel, msg) {
private async onresponse(channel, msg) {
let response;

try {
// if the buffer starts with a "{" character
if (msg[0] === 0x7b) {
response = JSON.parse(msg.toString());
} else {
response = this.parser.decode(msg);
response = await this.parser.decode(msg);
}
} catch (err) {
debug("ignoring malformed response");
Expand Down Expand Up @@ -616,7 +613,7 @@ export class RedisAdapter extends Adapter {
*
* @public
*/
public broadcast(packet: any, opts: BroadcastOptions) {
public async broadcast(packet: any, opts: BroadcastOptions) {
packet.nsp = this.nsp.name;

const onlyLocal = opts && opts.flags && opts.flags.local;
Expand All @@ -627,7 +624,7 @@ export class RedisAdapter extends Adapter {
except: [...new Set(opts.except)],
flags: opts.flags,
};
const msg = this.parser.encode([this.uid, packet, rawOpts]);
const msg = await this.parser.encode([this.uid, packet, rawOpts]);
let channel = this.channel;
if (opts.rooms && opts.rooms.size === 1) {
channel += opts.rooms.keys().next().value + "#";
Expand All @@ -638,7 +635,7 @@ export class RedisAdapter extends Adapter {
super.broadcast(packet, opts);
}

public broadcastWithAck(
public async broadcastWithAck(
packet: any,
opts: BroadcastOptions,
clientCountCallback: (clientCount: number) => void,
Expand All @@ -657,7 +654,7 @@ export class RedisAdapter extends Adapter {
flags: opts.flags,
};

const request = this.parser.encode({
const request = await this.parser.encode({
uid: this.uid,
requestId,
type: RequestType.BROADCAST,
Expand Down