JuanMBarba / Schwack

1 stars 0 forks source link

Schwack

Schwack is a clone of the business communication platform, Slack. Schwack gives users the ability to create their very own channel, or already join a pre-existing one. In these channels, users can chat through live messaging.

Schwack Live Link

Go to Schwack!

Technologies Used

Features

Live Messaging

Screen Shot 2021-06-11 at 9 56 07 AM Screen Shot 2021-06-11 at 10 00 00 AM Screen Shot 2021-06-11 at 10 01 40 AM

const createConnection = (currentUserId, channelId, dispatch) => {
    return App.cable.subscriptions.create(
        { channel: "ChatChannel", id: channelId },
        {
            received: data => {
                if (data.type === "REMOVE_MESSAGE") {
                    dispatch(removeMessage(data.messageId))
                }
                else if (data.message.userId !== currentUserId) {
                    dispatch(receiveMessage(data.message));
                }
            },
            speak: function (data) {
                return this.perform("speak", data);
            }
        }
    );
}
class ChatChannel < ApplicationCable::Channel
  def subscribed
    @channel = Channel.find_by(id: params[:id])
    stream_for @channel if @channel
  end

  def speak(data)
    socket = data
    @channel = Channel.find_by(id: data["message"]["channelId"])
    ChatChannel.broadcast_to(@channel, socket)
  end

  def unsubscribed
    # Any cleanup needed when channel is unsubscribed
  end
end

Future Directions