Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Join the admin channel
- app.channel('admins').join(connection);
- // Leave the admin channel
- app.channel('admins').leave(connection);
- // Leave a channel conditionally
- app.channel('admins', 'rooms').leave(connection => connection.userId === user._id);
- // Leave all room channels
- const roomChannels = app.channels.filter(channel => channel.indexOf('room/') === 0);
- app.channel(roomChannels).leave(connection);
- // Leave all channels
- app.channel(app.channels).leave(connection);
- // Example: Join an anonymous channel
- app.on('connection', connection => {
- // Add to the anonymous channel
- app.channel('anonymous').join(connection);
- });
- // Example: Join the users rooms
- app.on('login', (payload, meta) => {
- const connection = meta.connection;
- // Connection can be undefined e.g. when logging in via REST
- if(connection) {
- // Leave anonymous channel first
- app.channel('anonymous').leave(connection);
- // Get the user object and stick into channels
- app.service('users').get(payload.userId).then(user => {
- // A channel just for this user
- app.channel(`users/${user._id}`).join(connection);
- // Put user into the chat rooms they joined
- user.rooms.forEach(roomId => {
- app.channel(`rooms/${roomId}`).join(connection);
- });
- });
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement