Created
August 6, 2017 12:34
-
-
Save vaibhavgeek/7ba256b4097a5dda588072de19da4cbc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ApplicationCable | |
class Connection < ActionCable::Connection::Base | |
identified_by :current_chat | |
identified_by :current_visitor | |
def connect | |
if cookies.signed['chat'] == nil | |
cookies.signed['chat'] = return_random_string | |
end | |
puts cookies.signed['chat'] | |
puts "\n this is from connection.rb file" | |
if cookies.signed['visitor'] == nil | |
cookies.signed['visitor'] = return_random_string | |
end | |
# puts cookies.signed['a'] | |
# puts cookies.signed['auth'] | |
self.current_chat = find_verified_chat | |
self.current_visitor = find_verified_vistor | |
# #logger.add_tags 'ActionCable', current_chat.id | |
end | |
protected | |
def find_verified_chat | |
if verified_chat = Chat.where(session_var: cookies.signed['chat']).first_or_create | |
verified_chat | |
end | |
end | |
def find_verified_vistor | |
if verified_visitor = Visitor.where(auth_token: cookies.signed['auth']).first_or_create(ipaddr: request.remote_ip) | |
verified_visitor | |
end | |
end | |
def return_random_string | |
o = [('a'..'z'), ('A'..'Z')].map(&:to_a).flatten | |
string = (0...100).map { o[rand(o.length)] }.join | |
string | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment