Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: tlaverdure/laravel-echo-server
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: kefu-chat/laravel-echo-server
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Sep 23, 2020

  1. Copy the full SHA
    46fd9cd View commit details

Commits on Sep 24, 2020

  1. Copy the full SHA
    5c5d415 View commit details
Showing with 36 additions and 12 deletions.
  1. +6 −4 src/channels/channel.ts
  2. +10 −7 src/channels/presence-channel.ts
  3. +20 −1 src/channels/private-channel.ts
10 changes: 6 additions & 4 deletions src/channels/channel.ts
Original file line number Diff line number Diff line change
@@ -62,11 +62,13 @@ export class Channel {
if (data.event && data.channel) {
if (this.isClientEvent(data.event) &&
this.isPrivate(data.channel) &&
this.isInChannel(socket, data.channel)) {
this.isInChannel(socket, socket.id, data.channel)) {
this.io.sockets.connected[socket.id]
.broadcast.to(data.channel)
.emit(data.event, data.channel, data.data);
}
} else {
Log.error('bad client event' + data);
}
}

@@ -76,7 +78,7 @@ export class Channel {
leave(socket: any, channel: string, reason: string): void {
if (channel) {
if (this.isPresence(channel)) {
this.presence.leave(socket, channel)
this.presence.leave(socket, channel, this)
}

socket.leave(channel);
@@ -161,7 +163,7 @@ export class Channel {
/**
* Check if a socket has joined a channel.
*/
isInChannel(socket: any, channel: string): boolean {
return !!socket.rooms[channel];
isInChannel(socket: any, socketId: string, channel: string): boolean {
return !!socket.rooms[socketId] || !!socket.rooms[channel];
}
}
17 changes: 10 additions & 7 deletions src/channels/presence-channel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Database } from './../database';
import { Log } from './../log';
import { Channel } from './channel';
var _ = require("lodash");

export class PresenceChannel {
@@ -115,23 +116,25 @@ export class PresenceChannel {
* Remove a member from a presenece channel and broadcast they have left
* only if not other presence channel instances exist.
*/
leave(socket: any, channel: string): void {
this.getMembers(channel).then(
leave(socket: any, channelName: string, channel: Channel): void {
this.getMembers(channelName).then(
(members) => {
members = members || [];
let member = members.find(
(member) => member.socketId == socket.id
);
members = members.filter((m) => m.socketId != member.socketId);

this.db.set(channel + ":members", members);
this.db.set(channelName + ":members", members);

this.isMember(channel, member).then((is_member) => {
this.isMember(channelName, member).then((is_member) => {
if (!is_member) {
delete member.socketId;
this.onLeave(channel, member);
this.onLeave(socket, channelName, member);
}
});

channel.private.leave(socket, channelName, member);
},
(error) => Log.error(error)
);
@@ -149,8 +152,8 @@ export class PresenceChannel {
/**
* On leave emitter.
*/
onLeave(channel: string, member: any): void {
this.io.to(channel).emit("presence:leaving", channel, member);
onLeave(socket: any, channelName: string, member: any): void {
this.io.to(channelName).emit("presence:leaving", channelName, member);
}

/**
21 changes: 20 additions & 1 deletion src/channels/private-channel.ts
Original file line number Diff line number Diff line change
@@ -34,6 +34,25 @@ export class PrivateChannel {
return this.serverRequest(socket, options);
}


/**
* Send authentication request to application server.
*/
leave(socket: any, channel: string, member: any): Promise<any> {
let options = {
url: this.authHost(socket) + '/broadcasting/leave',
form: { channel_name: channel, member: member.user_info || null },
headers: {}, //(data.auth && data.auth.headers) ? data.auth.headers : {},
rejectUnauthorized: false
};

if (this.options.devMode) {
Log.info(`[${new Date().toISOString()}] - Sending leaving request to: ${options.url}\n`);
}

return this.serverRequest(socket, options);
}

/**
* Get the auth host based on the Socket.
*/
@@ -61,7 +80,7 @@ export class PrivateChannel {
}

if (this.options.devMode) {
Log.error(`[${new Date().toISOString()}] - Preparing authentication request to: ${authHostSelected}`);
Log.info(`[${new Date().toISOString()}] - Preparing authentication request to: ${authHostSelected}`);
}

return authHostSelected;