Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- `
- @@ -60,15 +61,16 @@ class RedisAdapter extends socket_io_adapter_1.Adapter {
- + const subEvent = opts.subEvent || 'messageBuffer';
- const onError = (err) => {
- if (err) {
- this.emit("error", err);
- }
- };
- - this.subClient.psubscribe(this.channel + "*", onError);
- - this.subClient.on("pmessageBuffer", this.onmessage.bind(this));
- - this.subClient.subscribe([this.requestChannel, this.responseChannel], onError);
- - this.subClient.on("messageBuffer", this.onrequest.bind(this));
- + this.subClient.subscribe([this.channel, this.requestChannel, this.responseChannel], onError);
- + this.subClient.on(subEvent, this.onmessage.bind(this));
- this.pubClient.on("error", onError);
- this.subClient.on("error", onError);
- }
- @@ -77,11 +79,19 @@ class RedisAdapter extends socket_io_adapter_1.Adapter {
- *
- * @private
- */
- - onmessage(pattern, channel, msg) {
- + onmessage(channel, msg) {
- channel = channel.toString();
- - const channelMatches = channel.startsWith(this.channel);
- - if (!channelMatches) {
- - return debug("ignore different channel");
- + // const channelMatches = channel.startsWith(this.channel);
- + // if (!channelMatches) {
- + // return debug("ignore different channel");
- + // }
- +
- + if (channel.startsWith(this.requestChannel)) {
- + return this.onrequest(channel, msg);
- + } else if (channel.startsWith(this.responseChannel)) {
- + return this.onresponse(channel, msg);
- + } else if (!channel.startsWith(this.channel)) {
- + return debug('ignore different channel');
- }
- const room = channel.slice(this.channel.length, -1);
- if (room !== "" && !this.rooms.has(room)) {
- @@ -111,12 +121,12 @@ class RedisAdapter extends socket_io_adapter_1.Adapter {
- if (channel.startsWith(this.responseChannel)) {
- return this.onresponse(channel, msg);
- }
- - else if (!channel.startsWith(this.requestChannel)) {
- - return debug("ignore different channel");
- - }
- + // else if (!channel.startsWith(this.requestChannel)) {
- + // return debug("ignore different channel");
- + // }
- let request;
- try {
- - request = JSON.parse(msg);
- + request = JSON.parse(msg.toString());
- }
- catch (err) {
- this.emit("error", err);
- @@ -607,5 +617,32 @@ class RedisAdapter extends socket_io_adapter_1.Adapter {
- });
- }
- }
- +
- + addAll(id, rooms) {
- + const roomsArr = Array.from(rooms);
- + roomsArr.forEach((room) => {
- + const roomName = this.channel + room + '#';
- + this.subClient.subscribe(roomName);
- + });
- + return super.addAll(id, rooms);
- + }
- +
- + del(id, room) {
- + const unsubRoom = this.channel + room + '#';
- + this.subClient.unsubscribe(unsubRoom);
- + return super.del(id, room)
- + }
- +
- + delAll (id) {
- + const roomsSet = this.sids.get(id);
- + if (roomsSet !== undefined) {
- + const roomsArr = Array.from(roomsSet);
- + roomsArr.forEach((room) => {
- + const roomName = this.channel + room + '#';
- + this.subClient.unsubscribe(roomName);
- + });
- + }
- + return super.delAll(id);
- + }
- }
- exports.RedisAdapter = RedisAdapter;
- `
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement