Giter Club home page Giter Club logo

quack's Introduction

README

Quack! is a single page clone of Slack built with Ruby on Rails, PostgreSQL, Action Cable Web Sockets, and React/Redux.

Overview of Live Chat

Quack! makes use of websockets through Rails Action Cable module. Standard HTTP connections only allow for a one way communication at any one time (known as half-duplex). A helpful anaology is using a radio or walkie-talkie, where only one person can talk at a time. The standard HTTP request can be upgraded to a web socket connection which is a full duplex connection. A full duplex connection enables full 2 way communction, analagous to a cell phone, where both parties can communicate at the same time.

The web sockets make use of a publisher-subscriber model, where users are subscribed to a channel. A user sends a message to the channel at large, and anyone subscribed to that channel will recieve it.

The core functionality of live chat resides in app/controllers/api/messages_controller.rb and app/channels/channels_channel.rb

When an incoming message is saved to the database in the MessagesController, it broadcasts to all the subscribers

From app/controllers/api/messages_controller.rb:

class Api::MessagesController < ApplicationController
	def create
		@message = Message.new(message_params)
		@channel = Channel.find_by_id(message_params[:channel_id])

		if @message.save
			ChannelsChannel.broadcast_to(@channel, {
				room: @channel.id,
				message_id: @message.id,
				message: @message.content,
				sender_id: @message.sender_id,
				created_at: @message.created_at,
				updated_at: @message.updated_at

			})
			render json: @message;
		else
			render json: @message.errors.full_messages, status: 422
		end
	end

	def message_params
		params.require(:message).permit(:content, :channel_id, :sender_id)
	end
end

The ChannelsChannel class handles the subscription and publishing (aka. broadcasting) functionality.

From app/channels/channels_channel.rb:

class ChannelsChannel < ApplicationCable::Channel
	def subscribed
		@room =  Channel.find_by_id(params[:room])
		stream_for @room
	end

	def received(data)
		ChannelsChannel.broadcast_to(@room, {channel: @room, users: @room.users, messages: @room.messages})
	end
  ....

Additional Features

Quack! has a number of features simlar to it's inspiration Slack.

Rich Text Editor

Quack! features a Rich Text editor built using Quill JS with font formats of Bold, Italic, and Underline. Also, a user can make bulleted or numbered lists.

Emojis

Quack! integrates emojis since they are a fun part of using any chat applciation.

Channel Creation and Direct Messages

Quack! allows users to create their own channels and send direct messages to selected members.

Avatars and AWS Itegration

Avatars are stored on AWS to ensure rapid availability and efficient delivery. In addition, members can update their avatars through a modal update form.

quack's People

Contributors

greathmaster avatar dependabot[bot] avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.