binnacle_chat 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 429f6bc23921c41b9efb5dced56dbc108a77bc60
4
+ data.tar.gz: d5e827a40a9127ce6f25ceed2f137ccf089e5fdf
5
+ SHA512:
6
+ metadata.gz: 6859dd8b63bed9dcf6f61b1e5183141e87b317b568a25b87b701847cab6557b1659950ac45d247bacc77573f74b0437897dcfd17380863841d27b867fef7bee4
7
+ data.tar.gz: 8b570d45bd4ef15fafc0d18532a1a06c7ee237d7409525fa22c03880829cd943b5615f469c64c2d0acaeddab42b7ec4ce198378a3b29907424c9889230b8e4bb
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Brian Sam-Bodden
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,7 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'bundler/gem_tasks'
@@ -0,0 +1,149 @@
1
+ #= require jquery
2
+ #= require jquery-ui
3
+ #= require binnacle
4
+ #= require jspanel
5
+ #= require gravatarjs
6
+
7
+ $ ->
8
+ if $('.binnacle_chat').length > 0
9
+ identity = $('.binnacle_chat').data('identity')
10
+ email = $('.binnacle_chat').data('email')
11
+ displayName = $('.binnacle_chat').data('display-name')
12
+ room = $('.binnacle_chat').data('room')
13
+ id = $('.binnacle_chat').data('binnacle_chat_id')
14
+ title = $('.binnacle_chat').data('title')
15
+
16
+ # configure jspanel
17
+ binnacleChat = $.jsPanel
18
+ title: title
19
+ position:
20
+ top: (panel) ->
21
+ $(window).height() - parseInt(panel.css('height'))
22
+ right: "auto"
23
+ offset: top: -10, left: 10
24
+ bootstrap: 'default'
25
+ iconfont: 'font-awesome'
26
+ controls:
27
+ buttons: 'none'
28
+ id: id
29
+ addClass:
30
+ header: 'panel-heading'
31
+ content: 'panel-body'
32
+ overflow: 'scroll'
33
+ size: width: '450px', height: '300px'
34
+
35
+ # Pass footer toolbar so it won't scroll with the messages
36
+ toolbarFooter: '<div id="binnacle-chat-footer"><a class="pull-left members" data-toggle="popover" data-placement="top" data-html="true" data-content="<ul><li>Room Member</li></ul>"><i class="fa fa-user"></i></a><form id="chat-form" class="form pull-right"><input id="message" type="text" class="form-control" placeholder="Type something…" /></form></div>'
37
+
38
+ binnacleChat.content.append $('.binnacle_chat')
39
+
40
+ $('.jsPanel').addClass 'panel-primary panel'
41
+
42
+ #if minimized, change footer position absolute to relative
43
+ $('.jsPanel-btn-min').click ->
44
+ $('.jsPanel #binnacle-chat-footer').css 'position', 'relative'
45
+
46
+ #else change it back to absolute
47
+ $('.jsPanel-btn-norm').click ->
48
+ $('.jsPanel #binnacle-chat-footer').css 'position', 'absolute'
49
+
50
+ client = null
51
+ sessionId = Math.random().toString(36).substr(2)
52
+
53
+ binnacleEventHandler = (event) ->
54
+ console.log("Received message! #{event}")
55
+ $messages = $('#messages')
56
+
57
+ if event.clientId == identity
58
+ $message = $("#binnacle-chat-right").clone()
59
+ else
60
+ $message = $("#binnacle-chat-left").clone()
61
+
62
+ $message.find('.message p').text(event.json.message)
63
+ $message.find('.name').text(event.json.displayName)
64
+ $message.find('.time span').text((new Date(event.eventTime)).toLocaleString())
65
+ $message.removeAttr('id').removeClass('template')
66
+ $message.find('.chat-user img').attr('src', gravatar(event.json.email))
67
+
68
+ displayEvent($message)
69
+
70
+ subscriberJoined = (event) ->
71
+ if event.presenceId isnt client.options.identity
72
+ $messages = $('#messages')
73
+ activity = $('.user-joined.template').clone()
74
+ activity.find('span').text(event.presenceId)
75
+ activity.removeClass('template')
76
+
77
+ displayEvent(activity)
78
+
79
+ client && client.subscribers(displaySubscribers)
80
+
81
+ subscriberLeft = (event) ->
82
+ if event.presenceId isnt client.options.identity
83
+ $messages = $('#messages')
84
+ activity = $('.user-left.template').clone()
85
+ activity.find('span').text(event.presenceId)
86
+ activity.removeClass('template')
87
+
88
+ displayEvent(activity)
89
+
90
+ client && client.subscribers(displaySubscribers)
91
+
92
+ $('#chat-form').submit (e) ->
93
+ e.preventDefault()
94
+ message = $('#message').val()
95
+ return false unless message
96
+
97
+ binnacleEvent = new (Binnacle.Event)(
98
+ sessionId: sessionId
99
+ eventName: room
100
+ clientId: client.options.identity
101
+ json:
102
+ user: client.options.identity
103
+ email: email
104
+ displayName: displayName
105
+ message: message
106
+ )
107
+
108
+ client.signal binnacleEvent
109
+ $('#message').val ''
110
+
111
+ client = new (Binnacle.Client)(
112
+ apiKey: gon.apiKey
113
+ apiSecret: gon.apiSecret
114
+ endPoint: gon.endPoint
115
+ channelId: gon.channelId
116
+ missedMessages: true
117
+ limit: 5
118
+ since: 30
119
+ identity: identity
120
+ filterBy: 'event'
121
+ filterByValue: room
122
+ onSignal: binnacleEventHandler
123
+ onSubscriberJoined: subscriberJoined
124
+ onSubscriberLeft: subscriberLeft
125
+ )
126
+
127
+ client.subscribe()
128
+
129
+ displayEvent = (event) ->
130
+ $messages = $('#messages')
131
+ $messages.append event
132
+ event.removeClass('hidden')
133
+
134
+ $('.jsPanel-content').animate { scrollTop: $('.jsPanel-content').prop('scrollHeight') }, 500
135
+ event.effect 'highlight', {}, 2000
136
+
137
+ displaySubscribers = (subscribers, xhrData) ->
138
+ subscribersList = "<ul>"
139
+ subscribers.sort()
140
+ for subscriber in subscribers
141
+ subscribersList += "<li>#{subscriber}</li>"
142
+
143
+ subscribersList += "</ul>"
144
+
145
+ $('#binnacle-chat-footer .members').attr('data-content', subscribersList)
146
+
147
+ client.subscribers(displaySubscribers)
148
+
149
+ $('[data-toggle="popover"]').popover()
@@ -0,0 +1,86 @@
1
+ /*
2
+ *= require jspanel/jquery.jspanel
3
+ */
4
+
5
+ .jsPanel { overflow: visible; }
6
+ .jsPanel-hdr { padding: 5px 10px; }
7
+ .jsPanel-hdr-r span { color: #fff; font-size: 12px; }
8
+
9
+ .binnacle_chat .template { display: none !important; }
10
+ #messages { margin-bottom: 45px; padding: 10px; }
11
+ .jsPanel-btn-small { display: none !important; }
12
+ #binnacle-chat-footer {
13
+ position: absolute;
14
+ width: 100%;
15
+ background: #eee;
16
+ bottom: 0;
17
+ left: 0;
18
+ padding: 10px;
19
+ }
20
+ #binnacle-chat-footer .members {
21
+ cursor: pointer;
22
+ color: #444;
23
+ font-size: 14px;
24
+ margin-right: 10px;
25
+ padding: 5px 0;
26
+ text-decoration: none;
27
+ }
28
+ #binnacle-chat-footer .members:hover { color: #337ab7; }
29
+ #binnacle-chat-footer .popover-content ul {
30
+ margin: 0;
31
+ padding: 0;
32
+ list-style: none;
33
+ font-size: 12px;
34
+ }
35
+ #binnacle-chat-footer .popover-content li { padding: 3px 0; }
36
+ #binnacle-chat-footer form { width: 95%; }
37
+ h3.jsPanel-title {
38
+ color: #fff !important;
39
+ font-size: 14px;
40
+ font-variant: normal;
41
+ text-transform: capitalize;
42
+ padding: 0;
43
+ line-height: 1.5;
44
+ }
45
+ .binnacle_chat .chat-item { padding: 5px 0; }
46
+ .binnacle_chat .chat-user {
47
+ width: 50px;
48
+ height: 50px;
49
+ overflow: hidden;
50
+ background-clip: padding-box;
51
+ margin-top: 6px;
52
+ }
53
+ .binnacle_chat .item-left .chat-user { float: left; }
54
+ .binnacle_chat .item-right .chat-user { float: right; }
55
+ .binnacle_chat .chat-body {
56
+ padding: 8px 10px;
57
+ border-radius: 5px;
58
+ position: relative;
59
+ background-clip: padding-box;
60
+ width: 75%;
61
+ }
62
+ .binnacle_chat .item-left .chat-body { background: #f5f5f5; margin-left: 60px; }
63
+ .binnacle_chat .item-right .chat-body { background: #dceffc; margin-right: 10px; float: right; }
64
+ .binnacle_chat .chat-item .chat-body:before {
65
+ border-style: solid;
66
+ border-width: 6px;
67
+ content: "";
68
+ cursor: pointer;
69
+ position: absolute;
70
+ top: 25px;
71
+ }
72
+ .binnacle_chat .item-left .chat-body:before { border-color: transparent #f5f5f5 transparent transparent; left: -12px; }
73
+ .binnacle_chat .item-right .chat-body:before { border-color: transparent transparent transparent #dceffc; right: -12px; }
74
+ .binnacle_chat .chat-item .name { font-weight: 600; margin-bottom: 5px; }
75
+ .binnacle_chat .chat-item .time {
76
+ position: absolute;
77
+ right: 10px;
78
+ top: 8px;
79
+ color: #666;
80
+ font-size: 10px;
81
+ font-weight: 300;
82
+ }
83
+ .binnacle_chat .user-activity {
84
+ margin: 10px auto;
85
+ color: #aaa;
86
+ }
@@ -0,0 +1,18 @@
1
+ module BinnacleChatHelper
2
+ def chat(options = {})
3
+ options[:id] ||= "binnacle_chat"
4
+ options[:room] ||= "binnacle_chat"
5
+ options[:title] ||= "Chat"
6
+ render(
7
+ partial: "binnacle_chat/binnacle_chat",
8
+ locals: {
9
+ binnacle_chat_id: options[:id],
10
+ binnacle_chat_room: options[:room],
11
+ binnacle_chat_identity: options[:identity],
12
+ binnacle_chat_email: options[:email],
13
+ binnacle_chat_display_name: options[:display_name],
14
+ binnacle_chat_title: options[:title]
15
+ }
16
+ )
17
+ end
18
+ end
@@ -0,0 +1,46 @@
1
+ <% content_for :binnacle_chat do %>
2
+ <%= Gon::Base.render_data %>
3
+ <% end %>
4
+
5
+ <div class="binnacle_chat" id="<%= binnacle_chat_id %>"
6
+ data-identity="<%= binnacle_chat_identity %>"
7
+ data-email="<%= binnacle_chat_email %>"
8
+ data-display-name="<%= binnacle_chat_display_name %>"
9
+ data-room="<%= binnacle_chat_room %>"
10
+ data-title="<%= binnacle_chat_title %>"
11
+ >
12
+ <div id="messages">
13
+ <div id='binnacle-chat-left' class="chat-item item-left clearfix template hidden">
14
+ <div class="chat-user">
15
+ <img src="#" class="img-responsive img-circle">
16
+ </div>
17
+ <div class="chat-body">
18
+ <div class="name">#{name}</div>
19
+ <div class="time hidden-xs"><i class="fa fa-clock-o"></i> <span>#{time}</span></div>
20
+ <div class="message">
21
+ <p>#{message}</p>
22
+ </div>
23
+ </div>
24
+ </div> <!-- /binnacle-chat-left -->
25
+ <div id='binnacle-chat-right' class="chat-item item-right clearfix template hidden">
26
+ <div class="chat-user">
27
+ <img src="#" class="img-responsive img-circle">
28
+ </div>
29
+ <div class="chat-body">
30
+ <div class="name">#{name}</div>
31
+ <div class="time hidden-xs"><i class="fa fa-clock-o"></i> <span>#{time}</span></div>
32
+ <div class="message">
33
+ <p>#{message}</p>
34
+ </div>
35
+ </div>
36
+ </div> <!-- /binnacle-chat-right -->
37
+
38
+ <div class="user-activity user-joined text-center template">
39
+ <i class="fa fa-smile-o"></i> <span>#{Room Member}</span> has joined the room
40
+ </div>
41
+
42
+ <div class="user-activity user-left text-center template">
43
+ <i class="fa fa-frown-o"></i> <span>#{Room Member}</span> has left the room
44
+ </div>
45
+ </div> <!-- /#messages -->
46
+ </div>
@@ -0,0 +1,2 @@
1
+ Rails.application.routes.draw do
2
+ end
@@ -0,0 +1,6 @@
1
+ require "binnacle_chat/engine"
2
+ require "binnacle_chat/initializer"
3
+ require "gon"
4
+
5
+ module BinnacleChat
6
+ end
@@ -0,0 +1,11 @@
1
+ require 'bundler/setup'
2
+
3
+ module BinnacleChat
4
+ class Engine < ::Rails::Engine
5
+ initializer "binnacle_chat.load_initializer" do
6
+ ActiveSupport.on_load(:action_controller) do
7
+ include BinnacleChat::Initializer
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ module BinnacleChat
2
+ module Initializer
3
+ extend ActiveSupport::Concern
4
+
5
+ def initialize_binnacle_chat
6
+ gon.apiKey = ENV["BINNACLE_API_KEY"]
7
+ gon.apiSecret = ENV["BINNACLE_API_SECRET"]
8
+ gon.channelId = ENV["BINNACLE_CHAT_CHANNEL"]
9
+ if Rails.env.production?
10
+ gon.endPoint = "https://#{ENV["BINNACLE_ENDPOINT"]}"
11
+ else
12
+ gon.endPoint = "http://#{ENV["BINNACLE_ENDPOINT"]}:8080"
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module BinnacleChat
2
+ VERSION = "0.0.8"
3
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: binnacle_chat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.8
5
+ platform: ruby
6
+ authors:
7
+ - Brian Sam-Bodden
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-04-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: coffee-rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.1'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 4.1.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '4.1'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 4.1.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: sass-rails
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '5.0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '5.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: gon
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '6.0'
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 6.0.1
57
+ type: :runtime
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '6.0'
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 6.0.1
67
+ - !ruby/object:Gem::Dependency
68
+ name: sqlite3
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '1.3'
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 1.3.10
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '1.3'
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: 1.3.10
87
+ - !ruby/object:Gem::Dependency
88
+ name: puma
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - "~>"
92
+ - !ruby/object:Gem::Version
93
+ version: '2'
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 2.14.0
97
+ type: :development
98
+ prerelease: false
99
+ version_requirements: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2'
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: 2.14.0
107
+ description: A Chat Widget for Rails powered by Binnacle.
108
+ email:
109
+ - brian@binnacle.io
110
+ executables: []
111
+ extensions: []
112
+ extra_rdoc_files: []
113
+ files:
114
+ - MIT-LICENSE
115
+ - Rakefile
116
+ - app/assets/javascripts/binnacle_chat.coffee
117
+ - app/assets/stylesheets/binnacle_chat.css.scss
118
+ - app/helpers/binnacle_chat_helper.rb
119
+ - app/views/binnacle_chat/_binnacle_chat.html.erb
120
+ - config/routes.rb
121
+ - lib/binnacle_chat.rb
122
+ - lib/binnacle_chat/engine.rb
123
+ - lib/binnacle_chat/initializer.rb
124
+ - lib/binnacle_chat/version.rb
125
+ homepage: https://binnacle.io/docs/03_widgets
126
+ licenses:
127
+ - MIT
128
+ metadata: {}
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 2.6.11
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: A Chat Widget for Rails.
149
+ test_files: []