jegolize 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/app/controllers/jegol_controller.rb +43 -0
- data/app/views/_jegol.html.erb +49 -0
- data/app/views/jebol_demo.html.erb +3 -0
- data/config/initializers/jegol.rb +3 -0
- data/config/jegol.yml +31 -0
- data/jegolize.gemspec +31 -1
- data/lib/jegolize.rb +31 -0
- data/lib/ruby_bosh.rb +161 -0
- data/public/javascripts/jegol.js +571 -0
- data/public/javascripts/jegol.plugin/jegol.plugin.update.subject_docs/images/doc_background.gif +0 -0
- data/public/javascripts/jegol.plugin/jegol.plugin.update.subject_docs/images/shared.css +360 -0
- data/public/javascripts/jegol.plugin/jegol.plugin.update.subject_docs/index.html +1 -0
- data/public/javascripts/jegol.plugin/jegol.plugin.update.subject_docs/index.html.xml +2 -0
- data/public/javascripts/jegol.plugin/jegol.plugin.update.tag_docs/images/doc_background.gif +0 -0
- data/public/javascripts/jegol.plugin/jegol.plugin.update.tag_docs/images/shared.css +360 -0
- data/public/javascripts/jegol.plugin/jegol.plugin.update.tag_docs/index.html +1 -0
- data/public/javascripts/jegol.plugin/jegol.plugin.update.tag_docs/index.html.xml +2 -0
- data/public/javascripts/jegol.plugin/update.notify.js +53 -0
- data/public/javascripts/jegol.plugin/update.subject.js +17 -0
- data/public/javascripts/jegol.plugin/update.tag.js +84 -0
- data/public/javascripts/jegol.plugin/viewer.default.js +17 -0
- data/public/javascripts/jegol.plugin/viewer.image.js +7 -0
- data/public/javascripts/jegol.plugin/viewer.poll.js +6 -0
- data/public/javascripts/jegol.plugin/viewer.youtube.js +7 -0
- data/public/javascripts/jegol.tag.js +102 -0
- data/public/javascripts/jegol_docs/images/doc_background.gif +0 -0
- data/public/javascripts/jegol_docs/images/shared.css +360 -0
- data/public/javascripts/jegol_docs/index.html +1 -0
- data/public/javascripts/jegol_docs/index.html.xml +200 -0
- data/public/javascripts/strophe.js +3543 -0
- data/public/stylesheets/.gitkeep +0 -0
- data/public/stylesheets/jegol.css +181 -0
- metadata +32 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'ruby_bosh'
|
2
|
+
require 'xmpp4r'
|
3
|
+
require 'xmpp4r/muc/helper/mucclient'
|
4
|
+
require 'xmpp4r/muc/helper/simplemucclient'
|
5
|
+
|
6
|
+
class JegolController < ApplicationController
|
7
|
+
def new_boshsession
|
8
|
+
username = session[:user_jid].nil? ? get_jid() : session[:user_jid]
|
9
|
+
password = session[:user_password].nil? ? JEGOL_CONFIG['default_pwd'] : session[:user_password]
|
10
|
+
|
11
|
+
xmpp_server = JEGOL_CONFIG['xmpp_server']
|
12
|
+
xmpp_bosh_port = JEGOL_CONFIG['xmpp_bosh_port']
|
13
|
+
jid = "#{username}@#{xmpp_server}"
|
14
|
+
server_url = "http://#{xmpp_server}:#{xmpp_bosh_port}/http-bind/"
|
15
|
+
room = "#{params[:room_jid]}@#{JEGOL_CONFIG['muc_namespace']}"
|
16
|
+
nickname = "#{username}:~:#{Time.new.tv_sec}" #append timestamp to make sure nickname is unique
|
17
|
+
|
18
|
+
@session_jid, @session_id, @session_random_id = RubyBOSH.initialize_session(jid,
|
19
|
+
password,
|
20
|
+
server_url,
|
21
|
+
{:timeout => 20})
|
22
|
+
|
23
|
+
render :json => {:jid=>@session_jid, :sid=>@session_id, :rid=>@session_random_id, :room => room, :nickname => nickname}
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_jid
|
27
|
+
if(session[:user_jid].nil?)
|
28
|
+
session[:user_jid] = "#{JEGOL_CONFIG['guest_jid']}#{rand(9999)}"
|
29
|
+
create_jid(session[:user_jid])
|
30
|
+
end
|
31
|
+
session[:user_jid]
|
32
|
+
end
|
33
|
+
|
34
|
+
def create_jid(username)
|
35
|
+
jid = "#{username}@#{JEGOL_CONFIG['xmpp_server']}"
|
36
|
+
client = Jabber::Client.new(jid)
|
37
|
+
client.connect(nil, JEGOL_CONFIG['c2s_port'].to_i)
|
38
|
+
client.register(JEGOL_CONFIG['default_pwd'])
|
39
|
+
|
40
|
+
client.close
|
41
|
+
return username
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
|
2
|
+
<%= stylesheet_link_tag "jegol", "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" %>
|
3
|
+
<%= javascript_include_tag 'jegol', 'strophe', 'jegol.tag', 'jegol/plugin/viewer.default', 'jegol/plugin/update.tag', 'jegol/plugin/viewer.image', 'jegol/plugin/viewer.youtube', 'jegol/plugin/viewer.poll', 'jegol/plugin/update.subject', 'jegol/plugin/update.notify', 'http://platform.twitter.com/widgets.js', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js'%>
|
4
|
+
<div id="jegol_box">
|
5
|
+
<input type='hidden' id='jegol_service_url' value='<%= service %>' />
|
6
|
+
<div>
|
7
|
+
<div id="jegol_version">
|
8
|
+
<strong>jeGol</strong><span style="font-size:xx-small;">beta</span>
|
9
|
+
</div>
|
10
|
+
</div>
|
11
|
+
<div>
|
12
|
+
<div id="jegol_buzz">
|
13
|
+
<div id="jegol_feedback">
|
14
|
+
<input class="jegol_Button" type="button" onclick='javascript:window.open("https://github.com/alemyis/jeGol/issues", "blank")' value="Feedback" />
|
15
|
+
</div>
|
16
|
+
<% if(!tweeturl.nil?) %>
|
17
|
+
<a href='http://twitter.com/share?url=<%= tweeturl %>&via=jegol' class="twitter-share-button">Tweet</a>
|
18
|
+
<% end %>
|
19
|
+
|
20
|
+
</div>
|
21
|
+
<div id="jegol_topic">Welcome</div>
|
22
|
+
</div>
|
23
|
+
<div id="jegol_tabs">
|
24
|
+
<ul>
|
25
|
+
<li><a href="#jegol_chatlog"><span>All</span></a></li>
|
26
|
+
<li><a href="#jegol_tags"><span>Tagged</span></a></li>
|
27
|
+
<li><a href="#jegol_roster"><span>Roster</span></a></li>
|
28
|
+
</ul>
|
29
|
+
<div id="jegol_chatlog"></div>
|
30
|
+
<div id="jegol_tags"></div>
|
31
|
+
<div id="jegol_roster"></div>
|
32
|
+
</div>
|
33
|
+
<div>
|
34
|
+
|
35
|
+
</div>
|
36
|
+
<% if(!readonly) %>
|
37
|
+
<div>
|
38
|
+
<textarea id='jegol_msgArea'></textarea>
|
39
|
+
<input id='jegol_postButton' class="jegol_Button" type="submit" value="Post" tabindex="3"/>
|
40
|
+
<span id='jegol_connection_status'>loading...</span>
|
41
|
+
</div>
|
42
|
+
<% end %>
|
43
|
+
</div>
|
44
|
+
|
45
|
+
<script>
|
46
|
+
$(document).ready(function() {
|
47
|
+
$("#jegol_tabs").tabs();
|
48
|
+
});
|
49
|
+
</script>
|
data/config/jegol.yml
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
#Set true if you want a chat room created when create a meeting.
|
2
|
+
create_muc: true
|
3
|
+
|
4
|
+
#Set true to send xmpp update stanza when meeting/items get updated
|
5
|
+
send_xmpp_CRUD: true
|
6
|
+
|
7
|
+
# XMPP server address e.g jabber.net
|
8
|
+
xmpp_server: <TODO: XMPP.MYSERVER.COM>
|
9
|
+
xmpp_bosh_port: 5280
|
10
|
+
c2s_port: 5333
|
11
|
+
|
12
|
+
# Credential used to create chat rooms
|
13
|
+
username: <TODO:BACKEND-ADMIN-USERNAME>
|
14
|
+
password: <TODO:BACKEND-ADMIN-PASSWORD>
|
15
|
+
|
16
|
+
#Set true if you want a JID to be created on xmpp_server when users register on qworky site
|
17
|
+
create_jid: true
|
18
|
+
|
19
|
+
#Guest JIDs will be Guest<random-number>
|
20
|
+
guest_jid: Juest
|
21
|
+
|
22
|
+
#default password for user JIDs on xmpp_server
|
23
|
+
default_pwd: <TODO: DEFAULT-GUEST-PASSWORD>
|
24
|
+
|
25
|
+
#sub-domain for chat rooms
|
26
|
+
muc_namespace: conference.<TODO: XMPP.MYSERVER.COM>
|
27
|
+
|
28
|
+
#chat rooms are named [jegolizating_<ID>]
|
29
|
+
muc_name_constant: jegolizing_
|
30
|
+
|
31
|
+
|
data/jegolize.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{jegolize}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Alemeshet Alemu"]
|
@@ -24,8 +24,38 @@ Gem::Specification.new do |s|
|
|
24
24
|
"README.rdoc",
|
25
25
|
"Rakefile",
|
26
26
|
"VERSION",
|
27
|
+
"app/controllers/jegol_controller.rb",
|
28
|
+
"app/views/_jegol.html.erb",
|
29
|
+
"app/views/jebol_demo.html.erb",
|
30
|
+
"config/initializers/jegol.rb",
|
31
|
+
"config/jegol.yml",
|
27
32
|
"jegolize.gemspec",
|
28
33
|
"lib/jegolize.rb",
|
34
|
+
"lib/ruby_bosh.rb",
|
35
|
+
"public/javascripts/jegol.js",
|
36
|
+
"public/javascripts/jegol.plugin/jegol.plugin.update.subject_docs/images/doc_background.gif",
|
37
|
+
"public/javascripts/jegol.plugin/jegol.plugin.update.subject_docs/images/shared.css",
|
38
|
+
"public/javascripts/jegol.plugin/jegol.plugin.update.subject_docs/index.html",
|
39
|
+
"public/javascripts/jegol.plugin/jegol.plugin.update.subject_docs/index.html.xml",
|
40
|
+
"public/javascripts/jegol.plugin/jegol.plugin.update.tag_docs/images/doc_background.gif",
|
41
|
+
"public/javascripts/jegol.plugin/jegol.plugin.update.tag_docs/images/shared.css",
|
42
|
+
"public/javascripts/jegol.plugin/jegol.plugin.update.tag_docs/index.html",
|
43
|
+
"public/javascripts/jegol.plugin/jegol.plugin.update.tag_docs/index.html.xml",
|
44
|
+
"public/javascripts/jegol.plugin/update.notify.js",
|
45
|
+
"public/javascripts/jegol.plugin/update.subject.js",
|
46
|
+
"public/javascripts/jegol.plugin/update.tag.js",
|
47
|
+
"public/javascripts/jegol.plugin/viewer.default.js",
|
48
|
+
"public/javascripts/jegol.plugin/viewer.image.js",
|
49
|
+
"public/javascripts/jegol.plugin/viewer.poll.js",
|
50
|
+
"public/javascripts/jegol.plugin/viewer.youtube.js",
|
51
|
+
"public/javascripts/jegol.tag.js",
|
52
|
+
"public/javascripts/jegol_docs/images/doc_background.gif",
|
53
|
+
"public/javascripts/jegol_docs/images/shared.css",
|
54
|
+
"public/javascripts/jegol_docs/index.html",
|
55
|
+
"public/javascripts/jegol_docs/index.html.xml",
|
56
|
+
"public/javascripts/strophe.js",
|
57
|
+
"public/stylesheets/.gitkeep",
|
58
|
+
"public/stylesheets/jegol.css",
|
29
59
|
"test/helper.rb",
|
30
60
|
"test/test_jegolize.rb"
|
31
61
|
]
|
data/lib/jegolize.rb
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'xmpp4r'
|
2
|
+
require 'xmpp4r/muc/helper/mucclient'
|
3
|
+
require 'xmpp4r/muc/helper/simplemucclient'
|
4
|
+
|
5
|
+
class Jegol
|
6
|
+
def self.create_room(unique_id)
|
7
|
+
muc_name = get_MUC_name(unique_id)
|
8
|
+
if JEGOL_CONFIG['create_muc']
|
9
|
+
jid = "#{JEGOL_CONFIG['username']}@#{JEGOL_CONFIG['xmpp_server']}"
|
10
|
+
client = Jabber::Client.new(jid)
|
11
|
+
client.connect
|
12
|
+
client.auth("#{JEGOL_CONFIG['password']}")
|
13
|
+
client.send(Jabber::Presence.new.set_show(:chat).set_status('backend'))
|
14
|
+
|
15
|
+
muc = Jabber::MUC::MUCClient.new(client)
|
16
|
+
muc.join(Jabber::JID.new("#{muc_name}@#{JEGOL_CONFIG['muc_namespace']}/jegol"))
|
17
|
+
muc.configure('muc#roomconfig_roomname' => "#{muc_name}",
|
18
|
+
'muc#roomconfig_persistentroom' => 1,
|
19
|
+
'muc#roomconfig_changesubject' => 1)
|
20
|
+
|
21
|
+
muc.exit
|
22
|
+
client.close
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.get_MUC_name (unique_id)
|
27
|
+
muc_name = JEGOL_CONFIG['muc_name_constant'].nil? ? 'jegol_room_' : JEGOL_CONFIG['muc_name_constant']
|
28
|
+
muc_name += unique_id
|
29
|
+
muc_name
|
30
|
+
end
|
31
|
+
end
|
data/lib/ruby_bosh.rb
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
require 'builder'
|
3
|
+
require 'rexml/document'
|
4
|
+
require 'base64'
|
5
|
+
require 'hpricot'
|
6
|
+
require 'timeout'
|
7
|
+
|
8
|
+
class RubyBOSH
|
9
|
+
BOSH_XMLNS = 'http://jabber.org/protocol/httpbind'
|
10
|
+
TLS_XMLNS = 'urn:ietf:params:xml:ns:xmpp-tls'
|
11
|
+
SASL_XMLNS = 'urn:ietf:params:xml:ns:xmpp-sasl'
|
12
|
+
BIND_XMLNS = 'urn:ietf:params:xml:ns:xmpp-bind'
|
13
|
+
SESSION_XMLNS = 'urn:ietf:params:xml:ns:xmpp-session'
|
14
|
+
CLIENT_XMLNS = 'jabber:client'
|
15
|
+
|
16
|
+
class Error < StandardError; end
|
17
|
+
class Timeout < RubyBOSH::Error; end
|
18
|
+
class AuthFailed < RubyBOSH::Error; end
|
19
|
+
class ConnFailed < RubyBOSH::Error; end
|
20
|
+
|
21
|
+
@@logging = true
|
22
|
+
def self.logging=(value)
|
23
|
+
@@logging = value
|
24
|
+
end
|
25
|
+
|
26
|
+
attr_accessor :jid, :rid, :sid, :success
|
27
|
+
def initialize(jid, pw, service_url, opts={})
|
28
|
+
@service_url = service_url
|
29
|
+
@jid, @pw = jid, pw
|
30
|
+
@host = jid.split("@").last
|
31
|
+
@success = false
|
32
|
+
@timeout = opts[:timeout] || 3 #seconds
|
33
|
+
@headers = {"Content-Type" => "text/xml; charset=utf-8",
|
34
|
+
"Accept" => "text/xml"}
|
35
|
+
@wait = opts[:wait] || 5
|
36
|
+
@hold = opts[:hold] || 3
|
37
|
+
@window = opts[:window] || 5
|
38
|
+
end
|
39
|
+
|
40
|
+
def success?
|
41
|
+
@success == true
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.initialize_session(*args)
|
45
|
+
new(*args).connect
|
46
|
+
end
|
47
|
+
|
48
|
+
def connect
|
49
|
+
initialize_bosh_session
|
50
|
+
if send_auth_request
|
51
|
+
send_restart_request
|
52
|
+
request_resource_binding
|
53
|
+
@success = send_session_request
|
54
|
+
end
|
55
|
+
|
56
|
+
raise RubyBOSH::AuthFailed, "could not authenticate #{@jid}" unless success?
|
57
|
+
@rid += 1 #updates the rid for the next call from the browser
|
58
|
+
|
59
|
+
[@jid, @sid, @rid]
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
def initialize_bosh_session
|
64
|
+
response = deliver(construct_body(:wait => @wait, :to => @host,
|
65
|
+
:hold => @hold, :window => @window,
|
66
|
+
"xmpp:version" => '1.0'))
|
67
|
+
parse(response)
|
68
|
+
end
|
69
|
+
|
70
|
+
def construct_body(params={}, &block)
|
71
|
+
@rid ? @rid+=1 : @rid=rand(100000)
|
72
|
+
|
73
|
+
builder = Builder::XmlMarkup.new
|
74
|
+
parameters = {:rid => @rid, :xmlns => BOSH_XMLNS,
|
75
|
+
"xmpp:version" => "1.0",
|
76
|
+
"xmlns:xmpp" => "urn:xmpp:xbosh"}.merge(params)
|
77
|
+
|
78
|
+
if block_given?
|
79
|
+
builder.body(parameters) {|body| yield(body)}
|
80
|
+
else
|
81
|
+
builder.body(parameters)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def send_auth_request
|
86
|
+
request = construct_body(:sid => @sid) do |body|
|
87
|
+
auth_string = "#{@jid}\x00#{@jid.split("@").first.strip}\x00#{@pw}"
|
88
|
+
body.auth(Base64.encode64(auth_string).gsub(/\s/,''),
|
89
|
+
:xmlns => SASL_XMLNS, :mechanism => 'PLAIN')
|
90
|
+
end
|
91
|
+
|
92
|
+
response = deliver(request)
|
93
|
+
response.include?("success")
|
94
|
+
end
|
95
|
+
|
96
|
+
def send_restart_request
|
97
|
+
request = construct_body(:sid => @sid, "xmpp:restart" => true, "xmlns:xmpp" => 'urn:xmpp:xbosh')
|
98
|
+
deliver(request).include?("stream:features")
|
99
|
+
end
|
100
|
+
|
101
|
+
def request_resource_binding
|
102
|
+
request = construct_body(:sid => @sid) do |body|
|
103
|
+
body.iq(:id => "bind_#{rand(100000)}", :type => "set",
|
104
|
+
:xmlns => "jabber:client") do |iq|
|
105
|
+
iq.bind(:xmlns => BIND_XMLNS) do |bind|
|
106
|
+
bind.resource("bosh_#{rand(10000)}")
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
response = deliver(request)
|
112
|
+
response.include?("<jid>")
|
113
|
+
end
|
114
|
+
|
115
|
+
def send_session_request
|
116
|
+
request = construct_body(:sid => @sid) do |body|
|
117
|
+
body.iq(:xmlns => CLIENT_XMLNS, :type => "set",
|
118
|
+
:id => "sess_#{rand(100000)}") do |iq|
|
119
|
+
iq.session(:xmlns => SESSION_XMLNS)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
response = deliver(request)
|
124
|
+
response.include?("body")
|
125
|
+
end
|
126
|
+
|
127
|
+
def parse(_response)
|
128
|
+
doc = Hpricot(_response)
|
129
|
+
doc.search("//body").each do |body|
|
130
|
+
@sid = body.attributes["sid"].to_s
|
131
|
+
end
|
132
|
+
_response
|
133
|
+
end
|
134
|
+
|
135
|
+
def deliver(xml)
|
136
|
+
#SystemTimer.timeout(@timeout) do
|
137
|
+
send(xml)
|
138
|
+
recv(RestClient.post(@service_url, xml, @headers))
|
139
|
+
#end
|
140
|
+
rescue ::Timeout::Error => e
|
141
|
+
raise RubyBOSH::Timeout, e.message
|
142
|
+
rescue Errno::ECONNREFUSED => e
|
143
|
+
raise RubyBOSH::ConnFailed, "could not connect to #{@host}\n#{e.message}"
|
144
|
+
rescue Exception => e
|
145
|
+
raise RubyBOSH::Error, e.message
|
146
|
+
end
|
147
|
+
|
148
|
+
def send(msg)
|
149
|
+
puts("Ruby-BOSH - SEND\n#{msg}") if @@logging; msg
|
150
|
+
end
|
151
|
+
|
152
|
+
def recv(msg)
|
153
|
+
puts("Ruby-BOSH - RECV\n#{msg}") if @logging; msg
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
|
158
|
+
if __FILE__ == $0
|
159
|
+
p RubyBOSH.initialize_session(ARGV[0], ARGV[1],
|
160
|
+
"http://localhost:5280/http-bind")
|
161
|
+
end
|