social_stream 0.26.1 → 0.26.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +10 -0
- data/base/lib/social_stream/base/version.rb +1 -1
- data/base/social_stream-base.gemspec +1 -1
- data/lib/social_stream/release/component.rb +5 -0
- data/lib/social_stream/release/global.rb +8 -7
- data/lib/social_stream/release/kernel.rb +24 -0
- data/lib/social_stream/version.rb +1 -1
- data/presence/app/assets/javascripts/jquery.flexselect.sstreampresence.js +2 -2
- data/presence/app/assets/javascripts/jquery.ui.chatbox.sstreampresence.js +5 -5
- data/presence/app/assets/javascripts/presence.js.erb +6 -4
- data/presence/app/assets/javascripts/presence_XmppClient.js.erb +1146 -996
- data/presence/app/assets/javascripts/presence_audio.js.erb +74 -60
- data/presence/app/assets/javascripts/presence_game.js.erb +35 -22
- data/presence/app/assets/javascripts/presence_game_comunication.js.erb +22 -5
- data/presence/app/assets/javascripts/presence_game_factory.js.erb +1 -1
- data/presence/app/assets/javascripts/presence_game_interface.js.erb +33 -13
- data/presence/app/assets/javascripts/presence_notifications.js +206 -183
- data/presence/app/assets/javascripts/presence_parser.js +265 -247
- data/presence/app/assets/javascripts/presence_persistence.js +199 -188
- data/presence/app/assets/javascripts/presence_store.js +22 -11
- data/presence/app/assets/javascripts/presence_uiManager.js.erb +553 -530
- data/presence/app/assets/javascripts/presence_utilities.js +244 -219
- data/presence/app/assets/javascripts/presence_videochat.js.erb +436 -409
- data/presence/app/assets/javascripts/presence_windowManager.js +586 -532
- data/presence/app/views/chat/_index.html.erb +7 -13
- data/presence/config/locales/en.yml +2 -1
- data/presence/config/locales/es.yml +2 -1
- data/presence/ejabberd/ejabberd_files.zip +0 -0
- data/presence/ejabberd/ejabberd_scripts/authentication_script +9 -2
- data/presence/ejabberd/mod_sspresence/mod_sspresence.beam +0 -0
- data/presence/lib/generators/social_stream/presence/templates/initializer.rb +4 -0
- data/presence/lib/social_stream-presence.rb +3 -0
- data/presence/lib/social_stream/presence/version.rb +1 -1
- data/presence/lib/social_stream/presence/xmpp_server_order.rb +1 -0
- data/release.thor +33 -13
- data/social_stream.gemspec +2 -2
- metadata +90 -29
data/README.rdoc
CHANGED
@@ -50,6 +50,16 @@ Since {Social Stream}[http://github.com/ging/social_stream] depends on {Devise}[
|
|
50
50
|
|
51
51
|
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
|
52
52
|
|
53
|
+
Social Stream is not compatible with default mass attributes protection shipped with Rails 3.2.3
|
54
|
+
http://weblog.rubyonrails.org/2012/3/30/ann-rails-3-2-3-has-been-released/
|
55
|
+
|
56
|
+
You must set
|
57
|
+
|
58
|
+
config.active_record.whitelist_attributes = false in config/application.rb
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
53
63
|
= Social Stream components
|
54
64
|
|
55
65
|
Social Stream is divided into components. Developers can customize their social
|
@@ -58,7 +58,7 @@ Gem::Specification.new do |s|
|
|
58
58
|
# Autolink text blocks
|
59
59
|
s.add_runtime_dependency('rails_autolink', '~> 1.0.4')
|
60
60
|
# SocialCheesecake
|
61
|
-
s.add_runtime_dependency('social_cheesecake','~> 0.
|
61
|
+
s.add_runtime_dependency('social_cheesecake','~> 0.5.0')
|
62
62
|
# I18n-js
|
63
63
|
s.add_runtime_dependency('i18n-js','~>2.1.2')
|
64
64
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require File.expand_path('../kernel', __FILE__)
|
1
2
|
require File.expand_path('../dependency_update', __FILE__)
|
2
3
|
require File.expand_path('../global/version_file', __FILE__)
|
3
4
|
|
@@ -10,8 +11,8 @@ module SocialStream
|
|
10
11
|
|
11
12
|
attr_reader :name, :version
|
12
13
|
|
13
|
-
def initialize(target = nil
|
14
|
-
@target
|
14
|
+
def initialize(target = nil)
|
15
|
+
@target = target
|
15
16
|
end
|
16
17
|
|
17
18
|
def bump
|
@@ -21,11 +22,7 @@ module SocialStream
|
|
21
22
|
end
|
22
23
|
|
23
24
|
def publish
|
24
|
-
|
25
|
-
puts rake_release_command
|
26
|
-
else
|
27
|
-
system(rake_release_command) || raise(RuntimeError.new)
|
28
|
-
end
|
25
|
+
release_cmd rake_release_command
|
29
26
|
end
|
30
27
|
|
31
28
|
def dependencies
|
@@ -37,6 +34,10 @@ module SocialStream
|
|
37
34
|
"#{ @version_file.filename } #{ gemspec }"
|
38
35
|
end
|
39
36
|
|
37
|
+
def last_tag
|
38
|
+
`git describe`.split('-').first
|
39
|
+
end
|
40
|
+
|
40
41
|
protected
|
41
42
|
|
42
43
|
def bump_version
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module SocialStream
|
2
|
+
module Release
|
3
|
+
module Kernel
|
4
|
+
class << self
|
5
|
+
attr_accessor :release_action
|
6
|
+
end
|
7
|
+
|
8
|
+
@release_action = :system
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module Kernel
|
14
|
+
def release_cmd(cmd)
|
15
|
+
case SocialStream::Release::Kernel.release_action
|
16
|
+
when :system
|
17
|
+
system(cmd) || raise(RuntimeError.new)
|
18
|
+
when :test
|
19
|
+
puts "* release_cmd * #{ cmd }"
|
20
|
+
else
|
21
|
+
raise "Unknown release_action #{ SocialStream::Release::Kernel.release_action }"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -257,8 +257,8 @@
|
|
257
257
|
//this.picked = true;
|
258
258
|
this.hidden.val(selected.value);
|
259
259
|
this.input.val("");
|
260
|
-
if(typeof changeSelectContactValue == "function"){
|
261
|
-
return changeSelectContactValue(selected.name,selected.value);
|
260
|
+
if(typeof PRESENCE.UIMANAGER.changeSelectContactValue == "function"){
|
261
|
+
return PRESENCE.UIMANAGER.changeSelectContactValue(selected.name,selected.value);
|
262
262
|
}
|
263
263
|
} else if (this.settings.allowMismatch) {
|
264
264
|
this.hidden.val("");
|
@@ -66,7 +66,7 @@
|
|
66
66
|
self.elem.uiChatboxTitlebar.effect("highlight", options, 300);
|
67
67
|
|
68
68
|
|
69
|
-
if (((typeof mustBounceBoxForChatWindow == 'function')&&(mustBounceBoxForChatWindow(self)))||((typeof mustBounceBoxForChatWindow != 'function'))) {
|
69
|
+
if (((typeof PRESENCE.UTILITIES.mustBounceBoxForChatWindow == 'function')&&(PRESENCE.UTILITIES.mustBounceBoxForChatWindow(self)))||((typeof PRESENCE.UTILITIES.mustBounceBoxForChatWindow != 'function'))) {
|
70
70
|
self.elem.uiChatbox.effect("bounce", {times:3}, 300, function(){
|
71
71
|
self.highlightLock = false;
|
72
72
|
self._scrollToBottom();
|
@@ -185,7 +185,7 @@
|
|
185
185
|
.hover(function() {uiChatboxTitlebarVideo.addClass('ui-state-hover');},
|
186
186
|
function() {uiChatboxTitlebarVideo.removeClass('ui-state-hover');})
|
187
187
|
.click(function(event) {
|
188
|
-
toggleVideoBox(self)
|
188
|
+
PRESENCE.WINDOW.toggleVideoBox(self)
|
189
189
|
return false;
|
190
190
|
})
|
191
191
|
.appendTo(uiChatboxTitlebar),
|
@@ -204,7 +204,7 @@
|
|
204
204
|
.hover(function() {uiChatboxTitlebarVideoChange.addClass('ui-state-hover');},
|
205
205
|
function() {uiChatboxTitlebarVideoChange.removeClass('ui-state-hover');})
|
206
206
|
.click(function(event) {
|
207
|
-
toggleVideoBoxChange(self)
|
207
|
+
PRESENCE.WINDOW.toggleVideoBoxChange(self)
|
208
208
|
return false;
|
209
209
|
})
|
210
210
|
.appendTo(uiChatboxTitlebar),
|
@@ -247,7 +247,7 @@
|
|
247
247
|
'ui-chatbox-notify'
|
248
248
|
)
|
249
249
|
.click(function(event) {
|
250
|
-
onClickChatNotification(self.uiChatboxNotify)
|
250
|
+
PRESENCE.NOTIFICATIONS.onClickChatNotification(self.uiChatboxNotify)
|
251
251
|
})
|
252
252
|
.appendTo(uiChatboxContent),
|
253
253
|
|
@@ -289,7 +289,7 @@
|
|
289
289
|
.appendTo(uiChatboxInput)
|
290
290
|
.keydown(function(event) {
|
291
291
|
if(event.keyCode && event.keyCode == $.ui.keyCode.ENTER) {
|
292
|
-
var userChatDataInputControlBoolean = (((typeof userChatDataInputControl == 'function')&&(userChatDataInputControl()))||((typeof userChatDataInputControl != 'function')));
|
292
|
+
var userChatDataInputControlBoolean = (((typeof PRESENCE.UTILITIES.userChatDataInputControl == 'function')&&(PRESENCE.UTILITIES.userChatDataInputControl()))||((typeof PRESENCE.UTILITIES.userChatDataInputControl != 'function')));
|
293
293
|
if (userChatDataInputControlBoolean) {
|
294
294
|
msg = $.trim($(this).val());
|
295
295
|
if (msg.length > 0) {
|
@@ -7,10 +7,12 @@ PRESENCE.AUTHORS = 'Aldo Gordillo';
|
|
7
7
|
PRESENCE.CORE = (function(P,$,undefined){
|
8
8
|
|
9
9
|
var init = function(){
|
10
|
-
|
11
|
-
|
12
|
-
PRESENCE.
|
13
|
-
|
10
|
+
PRESENCE.UIMANAGER.init();
|
11
|
+
PRESENCE.UTILITIES.init();
|
12
|
+
PRESENCE.XMPPClient.init();
|
13
|
+
PRESENCE.VIDEOCHAT.init();
|
14
|
+
PRESENCE.GAME.init();
|
15
|
+
PRESENCE.AUDIO.init();
|
14
16
|
};
|
15
17
|
|
16
18
|
return {
|
@@ -1,1062 +1,1212 @@
|
|
1
1
|
////////////////////
|
2
|
-
//
|
2
|
+
//XMPP Client Module
|
3
3
|
////////////////////
|
4
|
-
var domain = '<%=SocialStream::Presence.domain%>';
|
5
4
|
|
6
|
-
////////////////////
|
7
|
-
//Hash tables
|
8
|
-
////////////////////
|
9
|
-
|
10
|
-
//Keys: Social Stream Chat Status
|
11
|
-
//Value: Xmpp status
|
12
|
-
var sstreamChatStatus = new Array();
|
13
|
-
sstreamChatStatus['available'] = "chat";
|
14
|
-
sstreamChatStatus['away'] = "away";
|
15
|
-
sstreamChatStatus['autoaway'] = "away";
|
16
|
-
sstreamChatStatus['dnd'] = "dnd";
|
17
|
-
|
18
|
-
//Keys: Xmpp status
|
19
|
-
//Value: Message associated with Xmpp Status
|
20
|
-
var statusMessage = new Array();
|
21
|
-
statusMessage[''] = "";
|
22
|
-
statusMessage['chat'] = "";
|
23
|
-
statusMessage['away'] = "Away";
|
24
|
-
statusMessage['xa'] = "Away";
|
25
|
-
statusMessage['dnd'] = "Busy";
|
26
5
|
|
27
|
-
//
|
28
|
-
//Value: Icon name (Same as Social Stream Status)
|
29
|
-
var statusIcons = new Array();
|
30
|
-
statusIcons[''] = "available";
|
31
|
-
statusIcons['chat'] = "available";
|
32
|
-
statusIcons['away'] = "away";
|
33
|
-
statusIcons['xa'] = "away";
|
34
|
-
statusIcons['dnd'] = "dnd";
|
35
|
-
|
36
|
-
//Contacts information
|
6
|
+
//Global variable: Contacts information
|
37
7
|
var contactsInfo = new Array();
|
38
8
|
//contactsInfo['slug'] = "[Object chatContact]";
|
39
9
|
|
40
|
-
//Manage contact information
|
41
|
-
function chatContact(domain,resource,client,version) {
|
42
|
-
this.domain=domain
|
43
|
-
this.resource=resource
|
44
|
-
this.client=client;
|
45
|
-
this.version=version;
|
46
|
-
|
47
|
-
//Videochat params
|
48
|
-
//Sender: disconnected, negotiating , connecting , waiting, establishing, connected
|
49
|
-
//Receiver: disconnected , pending , establishing, connected
|
50
|
-
this.videoChatStatus = "disconnected";
|
51
|
-
this.session_id=null;
|
52
|
-
this.user_token=null;
|
53
|
-
this.guest_token=null;
|
54
|
-
this.session=null;
|
55
|
-
this.publisher=null;
|
56
|
-
|
57
|
-
//Game params
|
58
|
-
//Sender: disconnected, waiting, playing
|
59
|
-
//Receiver: disconnected , pending , playing
|
60
|
-
this.gameStatus="disconnected";
|
61
|
-
this.game=null;
|
62
|
-
}
|
63
|
-
|
64
|
-
//Rooms information
|
65
|
-
var roomsInfo = new Array();
|
66
|
-
//roomsInfo['groupSlug'] = "[Object chatRoom]";
|
67
|
-
|
68
|
-
//Manage room information
|
69
|
-
function chatRoom() {
|
70
|
-
this.occupants=[];
|
71
|
-
this.joined = false;
|
72
|
-
this.affiliation = "none";
|
73
|
-
this.role = "none";
|
74
|
-
this.nick = getBaseNickFromUserName();
|
75
|
-
}
|
76
10
|
|
11
|
+
PRESENCE.XMPPClient = (function(P,$,undefined){
|
77
12
|
|
78
|
-
//
|
79
|
-
var
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
13
|
+
//XMPP Client Variables
|
14
|
+
var domain = '<%=SocialStream::Presence.domain%>';
|
15
|
+
|
16
|
+
////////////////////
|
17
|
+
//Hash tables
|
18
|
+
////////////////////
|
19
|
+
|
20
|
+
//Keys: Social Stream Chat Status
|
21
|
+
//Value: Xmpp status
|
22
|
+
var sstreamChatStatus = new Array();
|
23
|
+
sstreamChatStatus['available'] = "chat";
|
24
|
+
sstreamChatStatus['away'] = "away";
|
25
|
+
sstreamChatStatus['autoaway'] = "away";
|
26
|
+
sstreamChatStatus['dnd'] = "dnd";
|
27
|
+
|
28
|
+
//Keys: Xmpp status
|
29
|
+
//Value: Message associated with Xmpp Status
|
30
|
+
var statusMessage = new Array();
|
31
|
+
statusMessage[''] = "";
|
32
|
+
statusMessage['chat'] = "";
|
33
|
+
statusMessage['away'] = "Away";
|
34
|
+
statusMessage['xa'] = "Away";
|
35
|
+
statusMessage['dnd'] = "Busy";
|
36
|
+
|
37
|
+
//Manage contact information
|
38
|
+
function chatContact(domain,resource,client,version) {
|
39
|
+
this.domain=domain
|
40
|
+
this.resource=resource
|
41
|
+
this.client=client;
|
42
|
+
this.version=version;
|
43
|
+
|
44
|
+
//Videochat params
|
45
|
+
//Sender: disconnected, negotiating , connecting , waiting, establishing, connected
|
46
|
+
//Receiver: disconnected , pending , establishing, connected
|
47
|
+
this.videoChatStatus = "disconnected";
|
48
|
+
this.session_id=null;
|
49
|
+
this.user_token=null;
|
50
|
+
this.guest_token=null;
|
51
|
+
this.session=null;
|
52
|
+
this.publisher=null;
|
53
|
+
|
54
|
+
//Game params
|
55
|
+
//Sender: disconnected, waiting, playing
|
56
|
+
//Receiver: disconnected , pending , playing
|
57
|
+
this.gameStatus="disconnected";
|
58
|
+
this.game=null;
|
59
|
+
}
|
60
|
+
|
61
|
+
//Rooms information
|
62
|
+
var roomsInfo = new Array();
|
63
|
+
//roomsInfo['groupSlug'] = "[Object chatRoom]";
|
64
|
+
|
65
|
+
//Manage room information
|
66
|
+
function chatRoom() {
|
67
|
+
this.occupants=[];
|
68
|
+
this.joined = false;
|
69
|
+
this.affiliation = "none";
|
70
|
+
this.role = "none";
|
71
|
+
this.nick = getBaseNickFromUserName();
|
72
|
+
this.lastMessageId = null;
|
73
|
+
}
|
74
|
+
|
89
75
|
|
90
|
-
|
76
|
+
//IQsIDs
|
77
|
+
var iqStanzaID = new Array();
|
78
|
+
iqStanzaID['cinfo'] = "versionID";
|
79
|
+
iqStanzaID['videochatRequest'] = "videochatRequestID";
|
80
|
+
iqStanzaID['videochatRequestCancel'] = "videochatRequestCancelID";
|
81
|
+
|
82
|
+
|
83
|
+
var init = function(){
|
84
|
+
getConnection();
|
85
|
+
}
|
86
|
+
|
87
|
+
|
88
|
+
////////////////////
|
89
|
+
//Connect functions
|
90
|
+
////////////////////
|
91
|
+
|
92
|
+
var connectToChat = function(user_jid,credential){
|
93
|
+
|
94
|
+
if (isUserConnected()){
|
95
|
+
return true;
|
96
|
+
}
|
97
|
+
|
98
|
+
if (authByCookie()){
|
99
|
+
if (connectToServerWithCookie(user_jid, credential)==false){
|
100
|
+
PRESENCE.UIMANAGER.updateChatWindow();
|
101
|
+
}
|
102
|
+
} else {
|
103
|
+
if (connectToServerWithPassword(user_jid,credential)==false){
|
104
|
+
PRESENCE.UIMANAGER.updateChatWindow();
|
105
|
+
}
|
106
|
+
}
|
107
|
+
}
|
108
|
+
|
109
|
+
var isStropheConnected = function(){
|
110
|
+
if((strophe_connection!=null)&&(strophe_connection.connected)){
|
111
|
+
return true;
|
112
|
+
} else {
|
113
|
+
return false;
|
114
|
+
}
|
115
|
+
}
|
116
|
+
|
117
|
+
var isUserConnected = function(){
|
118
|
+
return ((isStropheConnected()) && (userStatus!="offline") && (!disconnectionFlag));
|
119
|
+
}
|
120
|
+
|
121
|
+
var connectToServerWithCookie = function(user_jid, cookie){
|
122
|
+
try {
|
123
|
+
strophe_connection = getConnection();
|
124
|
+
strophe_connection.connect(user_jid, cookie, onConnect);
|
125
|
+
} catch (err) {
|
126
|
+
//"Handle errors"
|
127
|
+
return false;
|
128
|
+
}
|
129
|
+
return true;
|
130
|
+
}
|
131
|
+
|
132
|
+
//Password: Get from chatPassword param if exists, instead try to get from sessionStorage.
|
133
|
+
var connectToServerWithPassword = function(user_jid, chatPassword){
|
134
|
+
|
135
|
+
//Get Password
|
136
|
+
if ((chatPassword!=null)&&(chatPassword!="")){
|
137
|
+
var password = chatPassword;
|
138
|
+
} else if ((window.sessionStorage)&&(sessionStorage.getItem("ss_user_pass") != null)) {
|
139
|
+
var password = sessionStorage.getItem("ss_user_pass");
|
140
|
+
} else {
|
141
|
+
return false;
|
142
|
+
}
|
143
|
+
|
144
|
+
try {
|
145
|
+
//Connect actual user to the chat
|
146
|
+
strophe_connection = getConnection();
|
147
|
+
strophe_connection.connect(user_jid, password, onConnect);
|
148
|
+
} catch (err) {
|
149
|
+
//"Handle errors"
|
150
|
+
return false;
|
151
|
+
}
|
152
|
+
|
153
|
+
return true;
|
154
|
+
}
|
155
|
+
|
156
|
+
|
157
|
+
////////
|
158
|
+
//Auth Methods
|
159
|
+
///////
|
160
|
+
var authByCookie = function(){
|
161
|
+
var authMethod = '<%= SocialStream::Presence.auth_method %>';
|
162
|
+
return authMethod=="cookie";
|
163
|
+
}
|
164
|
+
|
165
|
+
var authByPassword = function(){
|
166
|
+
var authMethod = '<%= SocialStream::Presence.auth_method %>';
|
167
|
+
return authMethod=="password";
|
168
|
+
}
|
169
|
+
|
170
|
+
|
171
|
+
////////////////////
|
172
|
+
//Stanza management using Strophe
|
173
|
+
////////////////////
|
174
|
+
|
175
|
+
//Global variables
|
176
|
+
var userStatus;
|
177
|
+
var awayTimerPeriod = 60000;
|
178
|
+
var awayTime = 10*60000; //10 minutes
|
179
|
+
var awayCounter = 0;
|
180
|
+
var strophe_connection = null;
|
181
|
+
var reconnectAttempts = 3;
|
182
|
+
var awayTimer;
|
183
|
+
var reconnectTimer;
|
184
|
+
var disconnectionFlag = false;
|
185
|
+
var afterNewConnectionFlag = false;
|
186
|
+
var afterFirstConnectionFlag = true;
|
187
|
+
|
188
|
+
|
189
|
+
var onConnect = function(status) {
|
190
|
+
|
191
|
+
//Status.ERROR An error has occurred
|
192
|
+
//Status.CONNECTING The connection is currently being made
|
193
|
+
//Status.CONNFAIL The connection attempt failed
|
194
|
+
//Status.AUTHENTICATING The connection is authenticating
|
195
|
+
//Status.AUTHFAIL The authentication attempt failed
|
196
|
+
//Status.CONNECTED The connection has succeeded
|
197
|
+
//Status.DISCONNECTED The connection has been terminated
|
198
|
+
//Status.DISCONNECTING The connection is currently being terminated
|
199
|
+
//Status.ATTACHED The connection has been attached
|
200
|
+
|
201
|
+
PRESENCE.UTILITIES.log('Strophe onConnect callback call with status ' + status);
|
202
|
+
|
203
|
+
if (status == Strophe.Status.ERROR){
|
204
|
+
PRESENCE.UTILITIES.log('Strophe connection error');
|
205
|
+
return;
|
206
|
+
}
|
207
|
+
|
208
|
+
if (status == Strophe.Status.ATTACHED){
|
209
|
+
PRESENCE.UTILITIES.log('Strophe connection attached');
|
210
|
+
return;
|
211
|
+
}
|
212
|
+
|
213
|
+
if (status == Strophe.Status.AUTHENTICATING ){
|
214
|
+
PRESENCE.UTILITIES.log('Strophe connection AUTHENTICATING');
|
215
|
+
return;
|
216
|
+
}
|
217
|
+
|
218
|
+
if (status == Strophe.Status.CONNECTING) {
|
219
|
+
PRESENCE.UTILITIES.log('Strophe is connecting.');
|
220
|
+
return;
|
221
|
+
}
|
222
|
+
|
223
|
+
if (status == Strophe.Status.DISCONNECTING) {
|
224
|
+
PRESENCE.UTILITIES.log('Strophe is disconnecting.');
|
225
|
+
return;
|
226
|
+
}
|
227
|
+
|
228
|
+
if(typeof initialTimer != 'undefined'){
|
229
|
+
clearTimeout(initialTimer);
|
230
|
+
}
|
231
|
+
|
232
|
+
if (status == Strophe.Status.CONNFAIL) {
|
233
|
+
PRESENCE.UTILITIES.log('Strophe failed to connect.');
|
234
|
+
reconnectTimer = setTimeout ("PRESENCE.XMPPClient.onReconnect()", 5000);
|
235
|
+
disconnectionFlag = true;
|
236
|
+
} else if (status == Strophe.Status.AUTHFAIL) {
|
237
|
+
PRESENCE.UTILITIES.log('Strophe authentication fail.');
|
238
|
+
if ((window.sessionStorage)&&(sessionStorage.getItem("ss_user_pass") != null)){
|
239
|
+
sessionStorage.setItem("ss_user_pass",null);
|
240
|
+
}
|
241
|
+
disconnectionFlag = true;
|
242
|
+
} else if (status == Strophe.Status.ERROR) {
|
243
|
+
PRESENCE.UTILITIES.log('Strophe error.');
|
244
|
+
disconnectionFlag = true;
|
245
|
+
} else if (status == Strophe.Status.DISCONNECTED) {
|
246
|
+
PRESENCE.UTILITIES.log('Strophe is disconnected.');
|
247
|
+
disconnectionFlag = true;
|
248
|
+
clearTimeout(awayTimer);
|
249
|
+
PRESENCE.UIMANAGER.updateInterfaceAfterUserDisconnect();
|
250
|
+
updateRoomsInfoAfterUserDisconnect();
|
251
|
+
reconnectTimer = setTimeout ("PRESENCE.XMPPClient.onReconnect()", 5000);
|
252
|
+
} else if (status == Strophe.Status.CONNECTED) {
|
253
|
+
//AFTER CONNECT ACTIONS
|
254
|
+
|
255
|
+
PRESENCE.UTILITIES.log('Strophe is connected.');
|
256
|
+
|
257
|
+
clearTimeout(reconnectTimer);
|
258
|
+
|
259
|
+
//addHandler:(callback, namespace to match, stanza name, stanza type, stanza id , stanza from, options)
|
260
|
+
strophe_connection.addHandler(onMessage, null, 'message', 'chat', null, null);
|
261
|
+
strophe_connection.addHandler(onRoomMessage, null, 'message', 'groupchat', null, null);
|
262
|
+
strophe_connection.addHandler(onPresence, null, 'presence', null, null, null);
|
263
|
+
strophe_connection.addHandler(onIQStanza,null, "iq", null, null);
|
264
|
+
|
265
|
+
disconnectionFlag = false;
|
266
|
+
afterNewConnectionFlag = true;
|
267
|
+
|
268
|
+
if(! userStatus){
|
269
|
+
userStatus = PRESENCE.PERSISTENCE.getRestoreUserChatStatus();
|
270
|
+
}
|
271
|
+
if(userStatus=="offline"){
|
272
|
+
userStatus="chat";
|
273
|
+
}
|
274
|
+
sendStatus(userStatus);
|
275
|
+
|
276
|
+
awayTimer = setInterval("PRESENCE.XMPPClient.awayTimerFunction()", awayTimerPeriod);
|
277
|
+
}
|
278
|
+
|
279
|
+
PRESENCE.UIMANAGER.updateChatWindow();
|
280
|
+
}
|
91
281
|
|
92
|
-
|
93
|
-
|
94
|
-
|
282
|
+
var onReconnect = function(){
|
283
|
+
|
284
|
+
return
|
95
285
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
286
|
+
if ((!isStropheConnected())&&(userStatus!="offline")) {
|
287
|
+
|
288
|
+
if (reconnectAttempts>0) {
|
289
|
+
reconnectAttempts--;
|
290
|
+
|
291
|
+
PRESENCE.UIMANAGER.changeChatHeaderTitle(I18n.t('chat.reconnecting'))
|
292
|
+
|
293
|
+
connectToChat(user_jid,cookie,null);
|
294
|
+
|
295
|
+
reconnectTimer = setTimeout ("PRESENCE.XMPPClient.onReconnect()", 9000);
|
296
|
+
|
297
|
+
} else {
|
298
|
+
PRESENCE.UIMANAGER.changeChatHeaderTitle(I18n.t('chat.unableconnect'))
|
299
|
+
//Notify issue to Rails App Server?
|
300
|
+
}
|
301
|
+
|
302
|
+
}
|
303
|
+
}
|
304
|
+
|
305
|
+
var disconnect = function(){
|
306
|
+
userStatus = "offline";
|
307
|
+
PRESENCE.UIMANAGER.setStatusWidgetTitle("offline");
|
308
|
+
|
309
|
+
if(isStropheConnected()){
|
310
|
+
|
311
|
+
//Leave from rooms before disconnect
|
312
|
+
if(roomsInfo){
|
313
|
+
for(var roomName in roomsInfo){
|
314
|
+
if(roomsInfo[roomName].joined){
|
315
|
+
leaveRoom(roomName);
|
316
|
+
}
|
317
|
+
}
|
318
|
+
}
|
319
|
+
|
320
|
+
strophe_connection.send($pres({type: "unavailable"}).tree());
|
321
|
+
strophe_connection.disconnect();
|
322
|
+
}
|
323
|
+
}
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
////////////////////
|
328
|
+
//Away Timer Management
|
329
|
+
////////////////////
|
330
|
+
|
331
|
+
var awayTimerFunction = function(){
|
332
|
+
awayCounter++;
|
333
|
+
if (awayCounter > (awayTime/awayTimerPeriod)){
|
334
|
+
if ((userStatus != "dnd")&&(userStatus != "away")) {
|
335
|
+
userStatus = "autoaway";
|
336
|
+
sendStatus(userStatus);
|
337
|
+
}
|
338
|
+
clearTimeout(awayTimer);
|
339
|
+
}
|
340
|
+
}
|
341
|
+
|
342
|
+
var autochangeStatusIfAutoAway = function(){
|
343
|
+
if (userStatus == "autoaway"){
|
344
|
+
userStatus = "available";
|
345
|
+
sendStatus(userStatus);
|
346
|
+
}
|
347
|
+
}
|
348
|
+
|
349
|
+
var restartAwayTimer = function(){
|
350
|
+
if (awayCounter > (awayTime/awayTimerPeriod)){
|
351
|
+
awayTimer = setInterval("PRESENCE.XMPPClient.awayTimerFunction()", awayTimerPeriod);
|
352
|
+
autochangeStatusIfAutoAway();
|
353
|
+
}
|
354
|
+
awayCounter = 0;
|
355
|
+
}
|
356
|
+
|
357
|
+
|
358
|
+
////////
|
359
|
+
//Manage Message stanzas
|
360
|
+
///////
|
361
|
+
|
362
|
+
//Chat messages handler
|
363
|
+
var onMessage = function(msg) {
|
364
|
+
var from = msg.getAttribute('from');
|
365
|
+
var type = msg.getAttribute('type');
|
366
|
+
var elems = msg.getElementsByTagName('body');
|
367
|
+
|
368
|
+
if (type == "chat" && elems.length > 0) {
|
369
|
+
var body = elems[0];
|
370
|
+
var msg = Strophe.getText(body);
|
371
|
+
var from_slug = getSlugFromJid(from)
|
372
|
+
|
373
|
+
if(isChatRoomJid(from)){
|
374
|
+
return true
|
375
|
+
} else {
|
376
|
+
var from_slug = getSlugFromJid(from)
|
377
|
+
PRESENCE.UIMANAGER.afterReceivedChatMessage(from_slug,msg,null)
|
378
|
+
}
|
379
|
+
}
|
380
|
+
|
381
|
+
// we must return true to keep the handler alive.
|
382
|
+
// returning false would remove it after it finishes.
|
383
|
+
return true;
|
384
|
+
}
|
385
|
+
|
386
|
+
|
387
|
+
////////
|
388
|
+
//Manage Presence stanzas
|
389
|
+
///////
|
390
|
+
var onPresence = function(presence) {
|
391
|
+
if (isChatRoomJid($(presence).attr('from'))){
|
392
|
+
return onRoomPresence(presence);
|
393
|
+
} else {
|
394
|
+
return onBuddyPresence(presence);
|
395
|
+
}
|
396
|
+
}
|
397
|
+
|
398
|
+
var onBuddyPresence = function(presence){
|
399
|
+
var ptype = $(presence).attr('type');
|
400
|
+
|
401
|
+
switch (ptype){
|
402
|
+
case undefined:
|
403
|
+
processAvailablePresenceStanza(presence)
|
404
|
+
break;
|
405
|
+
case "available":
|
406
|
+
processAvailablePresenceStanza(presence)
|
407
|
+
break;
|
408
|
+
case "unavailable":
|
409
|
+
processUnavailablePresenceStanza(presence)
|
410
|
+
break;
|
411
|
+
default :
|
412
|
+
//Stanza type not recognize
|
413
|
+
processAvailablePresenceStanza(presence)
|
414
|
+
}
|
415
|
+
|
416
|
+
return true;
|
417
|
+
}
|
418
|
+
|
419
|
+
var processAvailablePresenceStanza = function(presence){
|
420
|
+
var from = $(presence).attr('from');
|
421
|
+
var slug = from.split("@")[0];
|
422
|
+
|
423
|
+
if (slug != user_slug) {
|
424
|
+
storeContactInformation(presence);
|
425
|
+
if (PRESENCE.UIMANAGER.getConnectionBoxFromSlug(slug)!=null){
|
426
|
+
var status = $(presence).find('show').text();
|
427
|
+
PRESENCE.UIMANAGER.setUserIconStatus(slug,status);
|
428
|
+
PRESENCE.UIMANAGER.updateInterfaceAfterPresenceStanza(slug,true);
|
429
|
+
} else {
|
430
|
+
if(! PRESENCE.UTILITIES.isAdminSlug(slug)){
|
431
|
+
PRESENCE.UIMANAGER.updateChatWindow();
|
432
|
+
}
|
433
|
+
}
|
434
|
+
}
|
435
|
+
}
|
436
|
+
|
437
|
+
var processUnavailablePresenceStanza = function(presence){
|
438
|
+
var from = $(presence).attr('from');
|
439
|
+
var slug = from.split("@")[0];
|
440
|
+
|
441
|
+
if (slug != user_slug) {
|
442
|
+
if (PRESENCE.UIMANAGER.getConnectionBoxFromSlug(slug)!=null){
|
443
|
+
PRESENCE.UIMANAGER.updateInterfaceAfterPresenceStanza(slug,false)
|
444
|
+
PRESENCE.GAME.userDisconnected(slug)
|
445
|
+
}
|
446
|
+
}
|
447
|
+
}
|
448
|
+
|
449
|
+
var storeContactInformation = function(stanza){
|
450
|
+
var from = $(stanza).attr('from');
|
451
|
+
var split = from.split("@");
|
452
|
+
var slug = split[0];
|
453
|
+
var domain = split[1].split("/")[0];
|
454
|
+
var resource = split[1].split("/")[1];
|
455
|
+
|
456
|
+
if (!(slug in contactsInfo)) {
|
457
|
+
var contact = new chatContact(domain,resource,null,null);
|
458
|
+
contactsInfo[slug]=contact;
|
459
|
+
} else {
|
460
|
+
contactsInfo[slug].domain = domain;
|
461
|
+
contactsInfo[slug].resource = resource;
|
462
|
+
}
|
463
|
+
}
|
464
|
+
|
465
|
+
var storeRoomInformation = function(roomName){
|
466
|
+
if (!(roomName in roomsInfo)) {
|
467
|
+
var room = new chatRoom();
|
468
|
+
roomsInfo[roomName]=room;
|
469
|
+
}
|
470
|
+
}
|
471
|
+
|
472
|
+
|
473
|
+
////////
|
474
|
+
//Manage IQ stanzas
|
475
|
+
///////
|
476
|
+
|
477
|
+
///////
|
478
|
+
//RECEIVED STANZAS
|
479
|
+
///////
|
480
|
+
var onIQStanza = function(iq){
|
481
|
+
var type = iq.getAttribute("type");
|
482
|
+
var from = iq.getAttribute("from");
|
483
|
+
var slug = from.split("@")[0];
|
484
|
+
|
485
|
+
if (slug == user_slug) {
|
486
|
+
return true;
|
487
|
+
}
|
488
|
+
|
489
|
+
if(type=="get"){
|
490
|
+
return handleGetIQStanza(iq,from,slug);
|
491
|
+
} else if(type="result"){
|
492
|
+
return handleResultIQStanza(iq,from,slug);
|
493
|
+
}
|
494
|
+
|
495
|
+
return true;
|
496
|
+
}
|
497
|
+
|
498
|
+
///////
|
499
|
+
//RECEIVED STANZAS: GET
|
500
|
+
///////
|
501
|
+
var handleGetIQStanza = function(iq,jid,slug){
|
502
|
+
|
503
|
+
var iqID = iq.getAttribute("id");
|
504
|
+
|
505
|
+
//Case 1: Request client info
|
506
|
+
var queryElements = iq.getElementsByTagName('query');
|
507
|
+
|
508
|
+
if (queryElements.length > 0) {
|
509
|
+
var query = queryElements[0];
|
510
|
+
var xmlns_type = query.getAttribute("xmlns");
|
511
|
+
|
512
|
+
if( xmlns_type == "jabber:iq:version"){
|
513
|
+
sendIQStanzaWithClientInfo(jid,iqID);
|
514
|
+
return true;
|
515
|
+
}
|
516
|
+
|
517
|
+
if (xmlns_type == "jabber:iq:last") {
|
518
|
+
sendIQStanzaLast(jid,iqID);
|
519
|
+
return true;
|
520
|
+
}
|
521
|
+
}
|
522
|
+
|
523
|
+
//Case 2: Request videochat
|
524
|
+
if(iqID==iqStanzaID['videochatRequest']){
|
525
|
+
handleGetVideochatIQStanza(jid,iqID,iq,slug);
|
526
|
+
return true;
|
527
|
+
}
|
528
|
+
|
529
|
+
//Case 3: Request game
|
530
|
+
if(iqID==PRESENCE.GAME.COMUNICATION.getIQStanzaID()['gameRequest']){
|
531
|
+
//Do nothing
|
109
532
|
return true;
|
110
|
-
} else {
|
111
|
-
return false;
|
112
533
|
}
|
113
|
-
}
|
114
|
-
|
115
|
-
function isUserConnected(){
|
116
|
-
return ((isStropheConnected()) && (userStatus!="offline") && (!disconnectionFlag));
|
117
|
-
}
|
118
|
-
|
119
|
-
function connectToServerWithCookie(user_jid, cookie){
|
120
|
-
try {
|
121
|
-
strophe_connection = new Strophe.Connection(BOSH_SERVICE);
|
122
|
-
strophe_connection.connect(user_jid, cookie, onConnect);
|
123
|
-
} catch (err) {
|
124
|
-
//"Handle errors"
|
125
|
-
return false;
|
126
|
-
}
|
127
|
-
return true;
|
128
|
-
}
|
129
|
-
|
130
|
-
//Password: Get from chatPassword param if exists, instead try to get from sessionStorage.
|
131
|
-
function connectToServerWithPassword(user_jid, chatPassword){
|
132
|
-
|
133
|
-
//Get Password
|
134
|
-
if ((chatPassword!=null)&&(chatPassword!="")){
|
135
|
-
var password = chatPassword;
|
136
|
-
} else if ((window.sessionStorage)&&(sessionStorage.getItem("ss_user_pass") != null)) {
|
137
|
-
var password = sessionStorage.getItem("ss_user_pass");
|
138
|
-
} else {
|
139
|
-
return false;
|
140
|
-
}
|
141
|
-
|
142
|
-
try {
|
143
|
-
//Connect actual user to the chat
|
144
|
-
strophe_connection = new Strophe.Connection(BOSH_SERVICE);
|
145
|
-
strophe_connection.connect(user_jid, password, onConnect);
|
146
|
-
} catch (err) {
|
147
|
-
//"Handle errors"
|
148
|
-
return false;
|
149
|
-
}
|
150
|
-
|
151
|
-
return true;
|
152
|
-
}
|
153
|
-
|
154
|
-
|
155
|
-
////////
|
156
|
-
//Auth Methods
|
157
|
-
///////
|
158
|
-
function authByCookie(){
|
159
|
-
var authMethod = '<%= SocialStream::Presence.auth_method %>';
|
160
|
-
return authMethod=="cookie";
|
161
|
-
}
|
162
|
-
|
163
|
-
function authByPassword(){
|
164
|
-
var authMethod = '<%= SocialStream::Presence.auth_method %>';
|
165
|
-
return authMethod=="password";
|
166
|
-
}
|
167
|
-
|
168
|
-
|
169
|
-
////////////////////
|
170
|
-
//Stanza management using Strophe
|
171
|
-
////////////////////
|
172
|
-
|
173
|
-
//Global variables
|
174
|
-
var userStatus;
|
175
|
-
var awayTimerPeriod = 60000;
|
176
|
-
var awayTime = 10*60000; //10 minutes
|
177
|
-
var awayCounter = 0;
|
178
|
-
var strophe_connection = null;
|
179
|
-
var reconnectAttempts = 3;
|
180
|
-
var awayTimer;
|
181
|
-
var reconnectTimer;
|
182
|
-
var disconnectionFlag = false;
|
183
|
-
var afterNewConnectionFlag = false;
|
184
|
-
var afterFirstConnectionFlag = true;
|
185
|
-
|
186
|
-
|
187
|
-
function onConnect(status) {
|
188
|
-
|
189
|
-
//Status.ERROR An error has occurred
|
190
|
-
//Status.CONNECTING The connection is currently being made
|
191
|
-
//Status.CONNFAIL The connection attempt failed
|
192
|
-
//Status.AUTHENTICATING The connection is authenticating
|
193
|
-
//Status.AUTHFAIL The authentication attempt failed
|
194
|
-
//Status.CONNECTED The connection has succeeded
|
195
|
-
//Status.DISCONNECTED The connection has been terminated
|
196
|
-
//Status.DISCONNECTING The connection is currently being terminated
|
197
|
-
//Status.ATTACHED The connection has been attached
|
198
|
-
|
199
|
-
log('Strophe onConnect callback call with status ' + status);
|
200
|
-
|
201
|
-
if (status == Strophe.Status.ERROR){
|
202
|
-
log('Strophe connection error');
|
203
|
-
return;
|
204
|
-
}
|
205
|
-
|
206
|
-
if (status == Strophe.Status.ATTACHED){
|
207
|
-
log('Strophe connection attached');
|
208
|
-
return;
|
209
|
-
}
|
210
|
-
|
211
|
-
if (status == Strophe.Status.AUTHENTICATING ){
|
212
|
-
log('Strophe connection AUTHENTICATING');
|
213
|
-
return;
|
214
|
-
}
|
215
|
-
|
216
|
-
if (status == Strophe.Status.CONNECTING) {
|
217
|
-
log('Strophe is connecting.');
|
218
|
-
return;
|
219
|
-
}
|
220
|
-
|
221
|
-
if (status == Strophe.Status.DISCONNECTING) {
|
222
|
-
log('Strophe is disconnecting.');
|
223
|
-
return;
|
224
|
-
}
|
225
|
-
|
226
|
-
if(typeof initialTimer != 'undefined'){
|
227
|
-
clearTimeout(initialTimer);
|
228
|
-
}
|
229
|
-
|
230
|
-
if (status == Strophe.Status.CONNFAIL) {
|
231
|
-
log('Strophe failed to connect.');
|
232
|
-
reconnectTimer = setTimeout ("onReconnect()", 5000);
|
233
|
-
disconnectionFlag = true;
|
234
|
-
} else if (status == Strophe.Status.AUTHFAIL) {
|
235
|
-
log('Strophe authentication fail.');
|
236
|
-
if ((window.sessionStorage)&&(sessionStorage.getItem("ss_user_pass") != null)){
|
237
|
-
sessionStorage.setItem("ss_user_pass",null);
|
238
|
-
}
|
239
|
-
disconnectionFlag = true;
|
240
|
-
} else if (status == Strophe.Status.ERROR) {
|
241
|
-
log('Strophe error.');
|
242
|
-
disconnectionFlag = true;
|
243
|
-
} else if (status == Strophe.Status.DISCONNECTED) {
|
244
|
-
log('Strophe is disconnected.');
|
245
|
-
disconnectionFlag = true;
|
246
|
-
clearTimeout(awayTimer);
|
247
|
-
updateInterfaceAfterUserDisconnect();
|
248
|
-
updateRoomsInfoAfterUserDisconnect();
|
249
|
-
reconnectTimer = setTimeout ("onReconnect()", 5000);
|
250
|
-
} else if (status == Strophe.Status.CONNECTED) {
|
251
|
-
//AFTER CONNECT ACTIONS
|
252
|
-
|
253
|
-
log('Strophe is connected.');
|
254
|
-
|
255
|
-
clearTimeout(reconnectTimer);
|
256
|
-
|
257
|
-
//addHandler:(callback, namespace to match, stanza name, stanza type, stanza id , stanza from, options)
|
258
|
-
strophe_connection.addHandler(onMessage, null, 'message', 'chat', null, null);
|
259
|
-
strophe_connection.addHandler(onRoomMessage, null, 'message', 'groupchat', null, null);
|
260
|
-
strophe_connection.addHandler(onPresence, null, 'presence', null, null, null);
|
261
|
-
strophe_connection.addHandler(onIQStanza,null, "iq", null, null);
|
262
|
-
|
263
|
-
disconnectionFlag = false;
|
264
|
-
afterNewConnectionFlag = true;
|
265
534
|
|
266
|
-
|
267
|
-
|
268
|
-
}
|
269
|
-
if(userStatus=="offline"){
|
270
|
-
userStatus="chat";
|
271
|
-
}
|
272
|
-
sendStatus(userStatus);
|
273
|
-
|
274
|
-
awayTimer = setInterval("awayTimerFunction()", awayTimerPeriod);
|
275
|
-
}
|
276
|
-
|
277
|
-
updateChatWindow();
|
278
|
-
}
|
279
|
-
|
280
|
-
function onReconnect(){
|
281
|
-
|
282
|
-
if ((!isStropheConnected())&&(userStatus!="offline")) {
|
283
|
-
|
284
|
-
if (reconnectAttempts>0) {
|
285
|
-
reconnectAttempts--;
|
286
|
-
|
287
|
-
changeChatHeaderTitle(I18n.t('chat.reconnecting'))
|
288
|
-
|
289
|
-
connectToChat(user_jid,cookie,null);
|
290
|
-
|
291
|
-
reconnectTimer = setTimeout ("onReconnect()", 9000);
|
292
|
-
|
293
|
-
} else {
|
294
|
-
changeChatHeaderTitle(I18n.t('chat.unableconnect'))
|
295
|
-
//Notify issue to Rails App Server?
|
296
|
-
}
|
297
|
-
|
298
|
-
}
|
299
|
-
}
|
300
|
-
|
301
|
-
function disconnectStrophe(){
|
302
|
-
userStatus = "offline";
|
303
|
-
setStatusWidgetTitle("offline");
|
304
|
-
|
305
|
-
if(isStropheConnected()){
|
306
|
-
strophe_connection.send($pres({type: "unavailable"}).tree());
|
307
|
-
strophe_connection.disconnect();
|
308
|
-
}
|
309
|
-
}
|
310
|
-
|
311
|
-
|
312
|
-
////////
|
313
|
-
//Manage Message stanzas
|
314
|
-
///////
|
315
|
-
|
316
|
-
//Chat messages handler
|
317
|
-
function onMessage(msg) {
|
318
|
-
var from = msg.getAttribute('from');
|
319
|
-
var type = msg.getAttribute('type');
|
320
|
-
var elems = msg.getElementsByTagName('body');
|
321
|
-
|
322
|
-
if (type == "chat" && elems.length > 0) {
|
323
|
-
var body = elems[0];
|
324
|
-
var msg = Strophe.getText(body);
|
325
|
-
var from_slug = getSlugFromJid(from)
|
326
|
-
|
327
|
-
if(isChatRoomJid(from)){
|
328
|
-
return true
|
329
|
-
} else {
|
330
|
-
var from_slug = getSlugFromJid(from)
|
331
|
-
afterReceivedChatMessage(from_slug,msg,null)
|
332
|
-
}
|
333
|
-
}
|
334
|
-
|
335
|
-
// we must return true to keep the handler alive.
|
336
|
-
// returning false would remove it after it finishes.
|
337
|
-
return true;
|
338
|
-
}
|
339
|
-
|
340
|
-
|
341
|
-
////////
|
342
|
-
//Manage Presence stanzas
|
343
|
-
///////
|
344
|
-
function onPresence(presence) {
|
345
|
-
if (isChatRoomJid($(presence).attr('from'))){
|
346
|
-
return onRoomPresence(presence);
|
347
|
-
} else {
|
348
|
-
return onBuddyPresence(presence);
|
349
|
-
}
|
350
|
-
}
|
351
|
-
|
352
|
-
function onBuddyPresence(presence){
|
353
|
-
var ptype = $(presence).attr('type');
|
354
|
-
|
355
|
-
switch (ptype){
|
356
|
-
case undefined:
|
357
|
-
processAvailablePresenceStanza(presence)
|
358
|
-
break;
|
359
|
-
case "available":
|
360
|
-
processAvailablePresenceStanza(presence)
|
361
|
-
break;
|
362
|
-
case "unavailable":
|
363
|
-
processUnavailablePresenceStanza(presence)
|
364
|
-
break;
|
365
|
-
default :
|
366
|
-
//Stanza type not recognize
|
367
|
-
processAvailablePresenceStanza(presence)
|
368
|
-
}
|
535
|
+
//Case 4: Default behaviour
|
536
|
+
sendIQEmpty(jid,iqID);
|
369
537
|
|
370
|
-
|
371
|
-
}
|
372
|
-
|
373
|
-
function processAvailablePresenceStanza(presence){
|
374
|
-
var from = $(presence).attr('from');
|
375
|
-
var slug = from.split("@")[0];
|
376
|
-
|
377
|
-
if (slug != user_slug) {
|
378
|
-
storeContactInformation(presence);
|
379
|
-
if (getConnectionBoxFromSlug(slug)!=null){
|
380
|
-
var status = $(presence).find('show').text();
|
381
|
-
setUserIconStatus(slug,status);
|
382
|
-
updateInterfaceAfterPresenceStanza(slug,true);
|
383
|
-
} else {
|
384
|
-
if(! isAdminSlug(slug)){
|
385
|
-
updateChatWindow();
|
386
|
-
}
|
387
|
-
}
|
388
|
-
}
|
389
|
-
}
|
390
|
-
|
391
|
-
function processUnavailablePresenceStanza(presence){
|
392
|
-
var from = $(presence).attr('from');
|
393
|
-
var slug = from.split("@")[0];
|
394
|
-
|
395
|
-
if (slug != user_slug) {
|
396
|
-
if (getConnectionBoxFromSlug(slug)!=null){
|
397
|
-
updateInterfaceAfterPresenceStanza(slug,false)
|
398
|
-
PRESENCE.GAME.userDisconnected(slug)
|
399
|
-
}
|
400
|
-
}
|
401
|
-
}
|
402
|
-
|
403
|
-
function storeContactInformation(stanza){
|
404
|
-
var from = $(stanza).attr('from');
|
405
|
-
var split = from.split("@");
|
406
|
-
var slug = split[0];
|
407
|
-
var domain = split[1].split("/")[0];
|
408
|
-
var resource = split[1].split("/")[1];
|
409
|
-
|
410
|
-
if (!(slug in contactsInfo)) {
|
411
|
-
var contact = new chatContact(domain,resource,null,null);
|
412
|
-
contactsInfo[slug]=contact;
|
413
|
-
} else {
|
414
|
-
contactsInfo[slug].domain = domain;
|
415
|
-
contactsInfo[slug].resource = resource;
|
416
|
-
}
|
417
|
-
}
|
418
|
-
|
419
|
-
function storeRoomInformation(roomName){
|
420
|
-
if (!(roomName in roomsInfo)) {
|
421
|
-
var room = new chatRoom();
|
422
|
-
roomsInfo[roomName]=room;
|
423
|
-
}
|
424
|
-
}
|
425
|
-
|
426
|
-
|
427
|
-
////////
|
428
|
-
//Manage IQ stanzas
|
429
|
-
///////
|
430
|
-
|
431
|
-
///////
|
432
|
-
//RECEIVED STANZAS
|
433
|
-
///////
|
434
|
-
function onIQStanza(iq){
|
435
|
-
var type = iq.getAttribute("type");
|
436
|
-
var from = iq.getAttribute("from");
|
437
|
-
var slug = from.split("@")[0];
|
438
|
-
|
439
|
-
if (slug == user_slug) {
|
440
|
-
return true;
|
441
|
-
}
|
538
|
+
return true;
|
539
|
+
}
|
442
540
|
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
541
|
+
var handleGetVideochatIQStanza = function(jid,iqID,iq,slug){
|
542
|
+
storeContactInformation(iq);
|
543
|
+
var queryTag = iq.getElementsByTagName('query');
|
544
|
+
|
545
|
+
if (queryTag.length > 0) {
|
546
|
+
var queryElement = queryTag[0];
|
547
|
+
var session_id = queryElement.getElementsByTagName('session_id');
|
548
|
+
var token = queryElement.getElementsByTagName('token');
|
549
|
+
|
550
|
+
if((session_id.length == 1)&&(token.length == 1)){
|
551
|
+
contactsInfo[slug].session_id = $(session_id).text();
|
552
|
+
contactsInfo[slug].user_token = $(token).text();
|
553
|
+
PRESENCE.VIDEOCHAT.updateInterfaceAfterVideoRequestReceived(slug);
|
554
|
+
return;
|
555
|
+
}
|
556
|
+
}
|
557
|
+
|
558
|
+
//Send empty stanza
|
559
|
+
sendIQEmpty(jid,iqID);
|
447
560
|
}
|
448
561
|
|
449
|
-
return true;
|
450
|
-
}
|
451
|
-
|
452
|
-
///////
|
453
|
-
//RECEIVED STANZAS: GET
|
454
|
-
///////
|
455
|
-
function handleGetIQStanza(iq,jid,slug){
|
456
562
|
|
457
|
-
|
563
|
+
///////
|
564
|
+
//RECEIVED STANZAS: RESULT
|
565
|
+
///////
|
566
|
+
var handleResultIQStanza = function(iq,jid,slug){
|
567
|
+
var iqID = iq.getAttribute("id");
|
568
|
+
|
569
|
+
if (iqID==iqStanzaID['cinfo']){
|
570
|
+
return handleIQResultWithClientInfo(iq,slug);
|
571
|
+
}
|
572
|
+
|
573
|
+
if (iqID==iqStanzaID['videochatRequest']){
|
574
|
+
return handleIQResultFromVideochatRequest(iq,slug);
|
575
|
+
}
|
576
|
+
|
577
|
+
if(iqID==iqStanzaID['videochatRequestCancel']){
|
578
|
+
return handleIQResultFromVideochatRequestCancel(iq,slug);
|
579
|
+
}
|
580
|
+
|
581
|
+
//Case: Default behaviour
|
582
|
+
return true;
|
583
|
+
}
|
458
584
|
|
459
|
-
//Case 1: Request client info
|
460
|
-
var queryElements = iq.getElementsByTagName('query');
|
461
|
-
|
462
|
-
if (queryElements.length > 0) {
|
463
|
-
var query = queryElements[0];
|
464
|
-
var xmlns_type = query.getAttribute("xmlns");
|
465
|
-
|
466
|
-
if( xmlns_type == "jabber:iq:version"){
|
467
|
-
sendIQStanzaWithClientInfo(jid,iqID);
|
468
|
-
return true;
|
469
|
-
}
|
470
|
-
|
471
|
-
if (xmlns_type == "jabber:iq:last") {
|
472
|
-
sendIQStanzaLast(jid,iqID);
|
473
|
-
return true;
|
474
|
-
}
|
475
|
-
}
|
476
585
|
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
586
|
+
var handleIQResultWithClientInfo = function(iq,slug){
|
587
|
+
var queryTag = iq.getElementsByTagName('query');
|
588
|
+
|
589
|
+
if (queryTag.length > 0) {
|
590
|
+
var queryElement = queryTag[0];
|
591
|
+
var name = queryElement.getElementsByTagName('name');
|
592
|
+
var version = queryElement.getElementsByTagName('version');
|
593
|
+
|
594
|
+
if((name.length == 1)&&(version.length == 1)){
|
595
|
+
var clientValue = $(name).text();
|
596
|
+
var versionValue = $(version).text();
|
597
|
+
|
598
|
+
if (!(slug in contactsInfo)) {
|
599
|
+
var contact = new chatContact(null,null,clientValue,versionValue);
|
600
|
+
contactsInfo[slug]=contact;
|
601
|
+
} else {
|
602
|
+
contactsInfo[slug].client = clientValue;
|
603
|
+
contactsInfo[slug].version = versionValue;
|
604
|
+
}
|
605
|
+
PRESENCE.VIDEOCHAT.clientInfoReceivedTrigger(slug);
|
606
|
+
}
|
607
|
+
}
|
608
|
+
|
609
|
+
return true;
|
481
610
|
}
|
482
611
|
|
483
|
-
//Case 3: Default behaviour
|
484
|
-
sendIQEmpty(jid,iqID);
|
485
|
-
|
486
|
-
return true;
|
487
|
-
}
|
488
|
-
|
489
|
-
function handleGetVideochatIQStanza(jid,iqID,iq,slug){
|
490
|
-
storeContactInformation(iq);
|
491
|
-
var queryTag = iq.getElementsByTagName('query');
|
492
|
-
|
493
|
-
if (queryTag.length > 0) {
|
494
|
-
var queryElement = queryTag[0];
|
495
|
-
var session_id = queryElement.getElementsByTagName('session_id');
|
496
|
-
var token = queryElement.getElementsByTagName('token');
|
497
|
-
|
498
|
-
if((session_id.length == 1)&&(token.length == 1)){
|
499
|
-
contactsInfo[slug].session_id = $(session_id).text();
|
500
|
-
contactsInfo[slug].user_token = $(token).text();
|
501
|
-
updateInterfaceAfterVideoRequestReceived(slug);
|
502
|
-
return;
|
503
|
-
}
|
504
|
-
}
|
505
612
|
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
613
|
+
var handleIQResultFromVideochatRequest = function(iq,slug){
|
614
|
+
|
615
|
+
var queryTag = iq.getElementsByTagName('query');
|
616
|
+
|
617
|
+
if (queryTag.length > 0) {
|
618
|
+
var queryElement = queryTag[0];
|
619
|
+
var response = queryElement.getElementsByTagName('response');
|
620
|
+
|
621
|
+
if(response.length == 1){
|
622
|
+
PRESENCE.VIDEOCHAT.receiveVideoChatResponseFromUser(slug,$(response).text());
|
623
|
+
return true;
|
624
|
+
}
|
625
|
+
}
|
626
|
+
|
627
|
+
PRESENCE.VIDEOCHAT.receiveVideoChatResponseFromUser(slug,"Bad response");
|
628
|
+
return true;
|
629
|
+
}
|
630
|
+
|
516
631
|
|
517
|
-
|
518
|
-
|
632
|
+
var handleIQResultFromVideochatRequestCancel = function(iq,slug){
|
633
|
+
|
634
|
+
var queryTag = iq.getElementsByTagName('query');
|
635
|
+
|
636
|
+
if (queryTag.length > 0) {
|
637
|
+
var queryElement = queryTag[0];
|
638
|
+
var response = queryElement.getElementsByTagName('response');
|
639
|
+
|
640
|
+
if(response.length == 1){
|
641
|
+
PRESENCE.VIDEOCHAT.receiveVideoChatCancelationFromUser(slug);
|
642
|
+
return true;
|
643
|
+
}
|
644
|
+
}
|
645
|
+
|
646
|
+
return true;
|
519
647
|
}
|
520
648
|
|
521
|
-
if (iqID==iqStanzaID['videochatRequest']){
|
522
|
-
return handleIQResultFromVideochatRequest(iq,slug);
|
523
|
-
}
|
524
649
|
|
525
|
-
|
526
|
-
|
527
|
-
|
650
|
+
///////
|
651
|
+
//SEND STANZAS: GET
|
652
|
+
///////
|
653
|
+
var sendIQStanzaForRequestClientInfo = function(slug){
|
654
|
+
if (slug in contactsInfo) {
|
655
|
+
var domain = contactsInfo[slug].domain;
|
656
|
+
var resource = contactsInfo[slug].resource;
|
657
|
+
var jid=slug+"@"+domain+"/"+resource
|
658
|
+
|
659
|
+
var iq = $iq({to: jid, type: "get", id: iqStanzaID['cinfo'], xmlns: "jabber:iq:version"})
|
660
|
+
.c("query", {xmlns: "jabber:iq:version"});
|
661
|
+
strophe_connection.sendIQ(iq);
|
662
|
+
}
|
663
|
+
}
|
528
664
|
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
var version = queryElement.getElementsByTagName('version');
|
541
|
-
|
542
|
-
if((name.length == 1)&&(version.length == 1)){
|
543
|
-
var clientValue = $(name).text();
|
544
|
-
var versionValue = $(version).text();
|
545
|
-
|
546
|
-
if (!(slug in contactsInfo)) {
|
547
|
-
var contact = new chatContact(null,null,clientValue,versionValue);
|
548
|
-
contactsInfo[slug]=contact;
|
549
|
-
} else {
|
550
|
-
contactsInfo[slug].client = clientValue;
|
551
|
-
contactsInfo[slug].version = versionValue;
|
552
|
-
}
|
553
|
-
clientInfoReceivedTrigger(slug);
|
554
|
-
}
|
555
|
-
}
|
665
|
+
var sendIQStanzaToRequestVideochat = function(slug){
|
666
|
+
if (slug in contactsInfo) {
|
667
|
+
var jid=slug+"@"+contactsInfo[slug].domain+"/"+contactsInfo[slug].resource;
|
668
|
+
|
669
|
+
var iq = $iq({to: jid, type: "get", id: iqStanzaID['videochatRequest']})
|
670
|
+
.c("query", {xmlns: "urn:ietf:params:xml:ns:xmpp-stanzas"})
|
671
|
+
.c("session_id").t(contactsInfo[slug].session_id).up()
|
672
|
+
.c("token").t(contactsInfo[slug].guest_token);
|
673
|
+
strophe_connection.sendIQ(iq);
|
674
|
+
}
|
675
|
+
}
|
556
676
|
|
557
|
-
return true;
|
558
|
-
}
|
559
|
-
|
560
|
-
|
561
|
-
function handleIQResultFromVideochatRequest(iq,slug){
|
562
677
|
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
}
|
678
|
+
///////
|
679
|
+
//SEND STANZAS: RESULT
|
680
|
+
///////
|
681
|
+
var sendIQStanzaWithClientInfo = function(jid,iqID){
|
682
|
+
var client = "Social Stream XMPP Client"
|
683
|
+
var version = getJavascriptXMPPClientName();
|
684
|
+
var iq = $iq({to: jid, type: "result", id: iqID})
|
685
|
+
.c("query", {xmlns: "jabber:iq:version"}).c("name").t(client).up().c("version").t(version);
|
686
|
+
strophe_connection.sendIQ(iq);
|
687
|
+
}
|
574
688
|
|
575
|
-
|
576
|
-
|
577
|
-
}
|
578
|
-
|
579
|
-
|
580
|
-
function handleIQResultFromVideochatRequestCancel(iq,slug){
|
581
|
-
|
582
|
-
var queryTag = iq.getElementsByTagName('query');
|
583
|
-
|
584
|
-
if (queryTag.length > 0) {
|
585
|
-
var queryElement = queryTag[0];
|
586
|
-
var response = queryElement.getElementsByTagName('response');
|
587
|
-
|
588
|
-
if(response.length == 1){
|
589
|
-
receiveVideoChatCancelationFromUser(slug);
|
590
|
-
return true;
|
591
|
-
}
|
592
|
-
}
|
593
|
-
|
594
|
-
return true;
|
595
|
-
}
|
596
|
-
|
597
|
-
|
598
|
-
///////
|
599
|
-
//SEND STANZAS: GET
|
600
|
-
///////
|
601
|
-
function sendIQStanzaForRequestClientInfo(slug){
|
602
|
-
if (slug in contactsInfo) {
|
603
|
-
var domain = contactsInfo[slug].domain;
|
604
|
-
var resource = contactsInfo[slug].resource;
|
605
|
-
var jid=slug+"@"+domain+"/"+resource
|
606
|
-
|
607
|
-
var iq = $iq({to: jid, type: "get", id: iqStanzaID['cinfo'], xmlns: "jabber:iq:version"})
|
608
|
-
.c("query", {xmlns: "jabber:iq:version"});
|
609
|
-
strophe_connection.sendIQ(iq);
|
610
|
-
}
|
611
|
-
}
|
612
|
-
|
613
|
-
function sendIQStanzaToRequestVideochat(slug){
|
614
|
-
if (slug in contactsInfo) {
|
615
|
-
var jid=slug+"@"+contactsInfo[slug].domain+"/"+contactsInfo[slug].resource;
|
616
|
-
|
617
|
-
var iq = $iq({to: jid, type: "get", id: iqStanzaID['videochatRequest']})
|
618
|
-
.c("query", {xmlns: "urn:ietf:params:xml:ns:xmpp-stanzas"})
|
619
|
-
.c("session_id").t(contactsInfo[slug].session_id).up()
|
620
|
-
.c("token").t(contactsInfo[slug].guest_token);
|
621
|
-
strophe_connection.sendIQ(iq);
|
622
|
-
}
|
623
|
-
}
|
624
|
-
|
625
|
-
|
626
|
-
///////
|
627
|
-
//SEND STANZAS: RESULT
|
628
|
-
///////
|
629
|
-
function sendIQStanzaWithClientInfo(jid,iqID){
|
630
|
-
var client = "Social Stream XMPP Client"
|
631
|
-
var version = getJavascriptXMPPClientName();
|
632
|
-
var iq = $iq({to: jid, type: "result", id: iqID})
|
633
|
-
.c("query", {xmlns: "jabber:iq:version"}).c("name").t(client).up().c("version").t(version);
|
634
|
-
strophe_connection.sendIQ(iq);
|
635
|
-
}
|
636
|
-
|
637
|
-
function getJavascriptXMPPClientName(){
|
638
|
-
return '<%=SocialStream::Presence::VERSION%>';
|
639
|
-
}
|
640
|
-
|
641
|
-
function sendIQStanzaLast(jid,iqID){
|
642
|
-
var iq = $iq({to: jid, type: "result", id: iqID})
|
643
|
-
.c("query", {xmlns: "jabber:iq:last", seconds: "0"});
|
644
|
-
strophe_connection.sendIQ(iq);
|
645
|
-
}
|
646
|
-
|
647
|
-
function sendIQEmpty(jid,iqID){
|
648
|
-
var iq = $iq({to: jid, type: "result", id: iqID})
|
649
|
-
strophe_connection.sendIQ(iq);
|
650
|
-
}
|
651
|
-
|
652
|
-
function sendIQStanzaToResponseVideochat(slug,result){
|
653
|
-
if (slug in contactsInfo) {
|
654
|
-
var jid=slug+"@"+contactsInfo[slug].domain+"/"+contactsInfo[slug].resource;
|
655
|
-
var iq = $iq({to: jid, type: "result", id: iqStanzaID['videochatRequest']})
|
656
|
-
.c("query", {xmlns: "urn:ietf:params:xml:ns:xmpp-stanzas"})
|
657
|
-
.c("response").t(result);
|
658
|
-
strophe_connection.sendIQ(iq);
|
659
|
-
}
|
660
|
-
}
|
661
|
-
|
662
|
-
function sendIQStanzaToCancelVideochat(slug){
|
663
|
-
if (slug in contactsInfo) {
|
664
|
-
var jid=slug+"@"+contactsInfo[slug].domain+"/"+contactsInfo[slug].resource;
|
665
|
-
var iq = $iq({to: jid, type: "result", id: iqStanzaID['videochatRequestCancel']})
|
666
|
-
.c("query", {xmlns: "urn:ietf:params:xml:ns:xmpp-stanzas"})
|
667
|
-
.c("response").t("cancel");
|
668
|
-
strophe_connection.sendIQ(iq);
|
669
|
-
}
|
670
|
-
}
|
671
|
-
|
672
|
-
|
673
|
-
////////
|
674
|
-
//Send Message stanzas
|
675
|
-
///////
|
676
|
-
function sendChatMessage(guest_slug,msg){
|
677
|
-
rotatePriority(guest_slug);
|
678
|
-
if (isSlugGroup(guest_slug)){
|
679
|
-
var guest_jid = getRoomJidFromRoomName(guest_slug)
|
680
|
-
return sendGroupMessageToRoom(guest_jid,msg);
|
681
|
-
} else {
|
682
|
-
var headerMessage = getParsedName(user_name,true);
|
683
|
-
getChatBoxForSlug(guest_slug).chatbox("option", "boxManager").addMsg(headerMessage, getParsedContent(msg,true));
|
684
|
-
var guest_jid = getJidFromSlug(guest_slug)
|
685
|
-
return sendChatMessageToBuddy(guest_jid,msg);
|
686
|
-
}
|
687
|
-
}
|
688
|
-
|
689
|
-
function sendChatMessageToBuddy(to,text){
|
690
|
-
var from = user_jid
|
691
|
-
var type = "chat";
|
692
|
-
var body= $build("body");
|
693
|
-
body.t(text);
|
694
|
-
var message = $msg({to: to, from: from, type: 'chat'}).cnode(body.tree());
|
695
|
-
strophe_connection.send(message.tree());
|
696
|
-
restartAwayTimer();
|
697
|
-
return true;
|
698
|
-
}
|
699
|
-
|
700
|
-
|
701
|
-
////////
|
702
|
-
//Send Presence stanzas with status
|
703
|
-
///////
|
704
|
-
function sendStatus(status){
|
689
|
+
var getJavascriptXMPPClientName = function(){
|
690
|
+
return '<%=SocialStream::Presence::VERSION%>';
|
691
|
+
}
|
705
692
|
|
706
|
-
|
707
|
-
|
708
|
-
|
693
|
+
var sendIQStanzaLast = function(jid,iqID){
|
694
|
+
var iq = $iq({to: jid, type: "result", id: iqID})
|
695
|
+
.c("query", {xmlns: "jabber:iq:last", seconds: "0"});
|
696
|
+
strophe_connection.sendIQ(iq);
|
697
|
+
}
|
709
698
|
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
var
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
//List all occupants
|
772
|
-
var nick = $(value).attr("name");
|
773
|
-
if(roomsInfo[room_slug].occupants.indexOf(nick)==-1){
|
774
|
-
roomsInfo[room_slug].occupants.push(nick)
|
775
|
-
addNickToNotificationInGroup(room_slug,nick)
|
699
|
+
var sendIQEmpty = function(jid,iqID){
|
700
|
+
var iq = $iq({to: jid, type: "result", id: iqID})
|
701
|
+
strophe_connection.sendIQ(iq);
|
702
|
+
}
|
703
|
+
|
704
|
+
var sendIQStanzaToResponseVideochat = function(slug,result){
|
705
|
+
if (slug in contactsInfo) {
|
706
|
+
var jid=slug+"@"+contactsInfo[slug].domain+"/"+contactsInfo[slug].resource;
|
707
|
+
var iq = $iq({to: jid, type: "result", id: iqStanzaID['videochatRequest']})
|
708
|
+
.c("query", {xmlns: "urn:ietf:params:xml:ns:xmpp-stanzas"})
|
709
|
+
.c("response").t(result);
|
710
|
+
strophe_connection.sendIQ(iq);
|
711
|
+
}
|
712
|
+
}
|
713
|
+
|
714
|
+
var sendIQStanzaToCancelVideochat = function(slug){
|
715
|
+
if (slug in contactsInfo) {
|
716
|
+
var jid=slug+"@"+contactsInfo[slug].domain+"/"+contactsInfo[slug].resource;
|
717
|
+
var iq = $iq({to: jid, type: "result", id: iqStanzaID['videochatRequestCancel']})
|
718
|
+
.c("query", {xmlns: "urn:ietf:params:xml:ns:xmpp-stanzas"})
|
719
|
+
.c("response").t("cancel");
|
720
|
+
strophe_connection.sendIQ(iq);
|
721
|
+
}
|
722
|
+
}
|
723
|
+
|
724
|
+
|
725
|
+
////////
|
726
|
+
//Send Message stanzas
|
727
|
+
///////
|
728
|
+
var sendChatMessage = function(guest_slug,msg){
|
729
|
+
PRESENCE.WINDOW.rotatePriority(guest_slug);
|
730
|
+
if (PRESENCE.WINDOW.isSlugGroup(guest_slug)){
|
731
|
+
var guest_jid = getRoomJidFromRoomName(guest_slug)
|
732
|
+
return sendGroupMessageToRoom(guest_jid,msg);
|
733
|
+
} else {
|
734
|
+
var headerMessage = PRESENCE.PARSER.getParsedName(user_name,true);
|
735
|
+
PRESENCE.WINDOW.getChatBoxForSlug(guest_slug).chatbox("option", "boxManager").addMsg(headerMessage, PRESENCE.PARSER.getParsedContent(msg,true));
|
736
|
+
var guest_jid = getJidFromSlug(guest_slug)
|
737
|
+
return sendChatMessageToBuddy(guest_jid,msg);
|
738
|
+
}
|
739
|
+
}
|
740
|
+
|
741
|
+
var sendChatMessageToBuddy = function(to,text){
|
742
|
+
var from = user_jid
|
743
|
+
var type = "chat";
|
744
|
+
var body= $build("body");
|
745
|
+
body.t(text);
|
746
|
+
var message = $msg({to: to, from: from, type: 'chat'}).cnode(body.tree());
|
747
|
+
strophe_connection.send(message.tree());
|
748
|
+
restartAwayTimer();
|
749
|
+
return true;
|
750
|
+
}
|
751
|
+
|
752
|
+
|
753
|
+
////////
|
754
|
+
//Send Presence stanzas with status
|
755
|
+
///////
|
756
|
+
var sendStatus = function(status){
|
757
|
+
|
758
|
+
if(! status){
|
759
|
+
status = userStatus;
|
776
760
|
}
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
761
|
+
|
762
|
+
if((status in sstreamChatStatus)){
|
763
|
+
status = sstreamChatStatus[status];
|
764
|
+
}
|
765
|
+
|
766
|
+
if (status in statusMessage){
|
767
|
+
//Send status to the XMPP Server
|
768
|
+
var pres = $pres()
|
769
|
+
.c('status')
|
770
|
+
.t(statusMessage[status]).up() //Status message
|
771
|
+
.c('show')
|
772
|
+
.t(status);
|
773
|
+
strophe_connection.send(pres.tree());
|
774
|
+
PRESENCE.UIMANAGER.setStatusWidgetTitle(status);
|
775
|
+
}
|
786
776
|
}
|
787
|
-
|
788
|
-
|
777
|
+
|
778
|
+
|
779
|
+
////////
|
780
|
+
//MUC management
|
781
|
+
///////
|
782
|
+
|
783
|
+
var muc_host = "conference";
|
784
|
+
|
785
|
+
var joinRoom = function(roomName){
|
786
|
+
return strophe_connection.muc.join(getRoomJidFromRoomName(roomName), getRoomNickForRoom(roomName), null, null, null, null)
|
789
787
|
}
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
function resetRoomConfig(roomName){
|
794
|
-
storeRoomInformation(roomName)
|
795
|
-
var room = new chatRoom()
|
796
|
-
roomsInfo[roomName]=room
|
797
|
-
}
|
798
|
-
|
799
|
-
function updateRoomsInfoAfterUserDisconnect(){
|
800
|
-
$.each(getAllSlugsWithVisibleGroupBoxes(), function(index, value) {
|
801
|
-
resetRoomConfig(value)
|
802
|
-
initialNotificationInGroup(value,I18n.t('chat.muc.offline'))
|
803
|
-
});
|
804
|
-
}
|
805
|
-
|
806
|
-
function getRoomJidFromRoomName(roomName){
|
807
|
-
return roomName + "@" + muc_host + "." + domain;
|
808
|
-
}
|
809
|
-
|
810
|
-
function getRoomNickForRoom(roomName){
|
811
|
-
if(roomName in roomsInfo){
|
812
|
-
return roomsInfo[roomName].nick;
|
813
|
-
} else {
|
814
|
-
return getBaseNickFromUserName();
|
788
|
+
|
789
|
+
var leaveRoom = function(roomName){
|
790
|
+
return strophe_connection.muc.leave(getRoomJidFromRoomName(roomName), getRoomNickForRoom(roomName), null, null)
|
815
791
|
}
|
816
|
-
}
|
817
|
-
|
818
|
-
function getBaseNickFromUserName(){
|
819
|
-
return user_name.split(" ")[0];
|
820
|
-
}
|
821
|
-
|
822
|
-
function changeRoomNickNameAndJoinAgain(roomName){
|
823
|
-
var old_nick = getRoomNickForRoom(roomName)
|
824
792
|
|
825
|
-
|
826
|
-
|
827
|
-
return false;
|
793
|
+
var sendGroupMessageToRoomWithName = function(roomName,msg){
|
794
|
+
return sendMessageToRoom(getRoomJidFromRoomName(roomName),msg)
|
828
795
|
}
|
829
796
|
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
function
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
function
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
797
|
+
var sendGroupMessageToRoom = function(roomJid,msg){
|
798
|
+
return strophe_connection.muc.message(roomJid, null, msg, null, "groupchat")
|
799
|
+
}
|
800
|
+
|
801
|
+
var sendPrivateMessageToRoomUser = function(roomName,userNick,msg){
|
802
|
+
return strophe_connection.muc.message(getRoomJidFromRoomName(roomName), userNick, msg, null, "chat")
|
803
|
+
}
|
804
|
+
|
805
|
+
var queryChatRoomOccupants = function(roomName){
|
806
|
+
return strophe_connection.muc.queryOccupants(getRoomJidFromRoomName(roomName), queryChatRoomOccupantsSuccess, queryChatRoomOccupantsFail)
|
807
|
+
}
|
808
|
+
|
809
|
+
var queryChatRoomOccupantsSuccess = function(iqResponse){
|
810
|
+
handleIQResultFromMucOccupantsRequest(iqResponse);
|
811
|
+
return true;
|
812
|
+
}
|
813
|
+
|
814
|
+
var queryChatRoomOccupantsFail = function(){
|
815
|
+
return true;
|
816
|
+
}
|
817
|
+
|
818
|
+
var handleIQResultFromMucOccupantsRequest = function(iq){
|
819
|
+
var from = $(iq).attr('from');
|
820
|
+
var room_slug = getSlugFromJid(from)
|
821
|
+
var queryTag = iq.getElementsByTagName('query');
|
822
|
+
|
823
|
+
if (queryTag.length > 0) {
|
824
|
+
var queryElement = queryTag[0];
|
825
|
+
var occupants = queryElement.getElementsByTagName('item');
|
826
|
+
$.each(occupants, function(index, value) {
|
827
|
+
//List all occupants
|
828
|
+
var nick = $(value).attr("name");
|
829
|
+
if(roomsInfo[room_slug].occupants.indexOf(nick)==-1){
|
830
|
+
roomsInfo[room_slug].occupants.push(nick)
|
831
|
+
PRESENCE.NOTIFICATIONS.addNickToNotificationInGroup(room_slug,nick)
|
832
|
+
}
|
833
|
+
});
|
834
|
+
}
|
835
|
+
}
|
836
|
+
|
837
|
+
var accessRoom = function(roomName,open){
|
838
|
+
storeRoomInformation(roomName)
|
839
|
+
if(roomsInfo[roomName].joined==false){
|
840
|
+
joinRoom(roomName)
|
841
|
+
queryChatRoomOccupants(roomName)
|
842
|
+
}
|
843
|
+
if(!PRESENCE.UIMANAGER.existsSlugChatBox(roomName)){
|
844
|
+
PRESENCE.WINDOW.createGroupChatBox(roomName,open)
|
845
|
+
}
|
846
|
+
return true
|
847
|
+
}
|
848
|
+
|
849
|
+
var resetRoomConfig = function(roomName){
|
850
|
+
storeRoomInformation(roomName)
|
851
|
+
var room = new chatRoom()
|
852
|
+
roomsInfo[roomName]=room
|
853
|
+
}
|
854
|
+
|
855
|
+
var updateRoomsInfoAfterUserDisconnect = function(){
|
856
|
+
$.each(PRESENCE.WINDOW.getAllSlugsWithVisibleGroupBoxes(), function(index, value) {
|
857
|
+
resetRoomConfig(value)
|
858
|
+
PRESENCE.NOTIFICATIONS.initialNotificationInGroup(value,I18n.t('chat.muc.offline'))
|
859
|
+
});
|
860
|
+
}
|
861
|
+
|
862
|
+
var getRoomJidFromRoomName = function(roomName){
|
863
|
+
return roomName + "@" + muc_host + "." + domain;
|
864
|
+
}
|
865
|
+
|
866
|
+
var getRoomNickForRoom = function(roomName){
|
867
|
+
if(roomName in roomsInfo){
|
868
|
+
return roomsInfo[roomName].nick;
|
869
|
+
} else {
|
870
|
+
return getBaseNickFromUserName();
|
871
|
+
}
|
872
|
+
}
|
873
|
+
|
874
|
+
var getBaseNickFromUserName = function(){
|
875
|
+
return user_name.split(" ")[0];
|
876
|
+
}
|
877
|
+
|
878
|
+
var changeRoomNickNameAndJoinAgain = function(roomName){
|
879
|
+
var old_nick = getRoomNickForRoom(roomName)
|
880
|
+
|
881
|
+
if(old_nick.split("_").length > 4){
|
882
|
+
//Bucle prevention...
|
883
|
+
return false;
|
884
|
+
}
|
885
|
+
|
886
|
+
storeRoomInformation(roomName)
|
887
|
+
roomsInfo[roomName].nick = old_nick + "_"
|
888
|
+
joinRoom(roomName)
|
889
|
+
return true;
|
890
|
+
}
|
891
|
+
|
892
|
+
|
893
|
+
////////
|
894
|
+
//MUC Stanzas
|
895
|
+
///////
|
896
|
+
|
897
|
+
//MUC Messages
|
898
|
+
var onRoomMessage = function(roomMsg) {
|
865
899
|
|
866
|
-
|
867
|
-
|
900
|
+
//from=roomSlug@conference.domain/from_slug
|
901
|
+
var from = roomMsg.getAttribute('from');
|
902
|
+
var type = roomMsg.getAttribute('type');
|
903
|
+
var elems = roomMsg.getElementsByTagName('body');
|
904
|
+
|
905
|
+
if (type == "groupchat" && elems.length > 0) {
|
906
|
+
var body = elems[0];
|
907
|
+
var user_nick = getNickFromChatRoomJid(from)
|
908
|
+
var msg = Strophe.getText(body);
|
909
|
+
|
910
|
+
//Prevent repeated messages
|
911
|
+
var roomSlug = getSlugFromJid(from);
|
912
|
+
var id = roomMsg.getAttribute('id');
|
913
|
+
if((roomSlug in roomsInfo)&&(roomsInfo[roomSlug].lastMessageId != null)&&(roomsInfo[roomSlug].lastMessageId == id)){
|
914
|
+
return true;
|
915
|
+
}
|
916
|
+
roomsInfo[roomSlug].lastMessageId = id;
|
917
|
+
|
918
|
+
PRESENCE.UIMANAGER.afterReceivedGroupChatMessage(from,msg)
|
919
|
+
}
|
920
|
+
return true;
|
921
|
+
}
|
922
|
+
|
923
|
+
|
924
|
+
//MUC Presence stanzas
|
925
|
+
var onRoomPresence = function(presence) {
|
926
|
+
var from = $(presence).attr('from');
|
927
|
+
var to = $(presence).attr('to')
|
928
|
+
var room_slug = getSlugFromJid(from);
|
929
|
+
var nick = getNickFromChatRoomJid(from)
|
930
|
+
var ptype = $(presence).attr('type')
|
931
|
+
|
932
|
+
//Join or Leave room stanzas of self user
|
933
|
+
if((nick == getRoomNickForRoom(room_slug))&&(getSlugFromJid(to) == user_slug)){
|
934
|
+
switch (ptype){
|
935
|
+
case undefined:
|
936
|
+
processJoinRoomPresenceStanza(presence);
|
937
|
+
break;
|
938
|
+
case "available":
|
939
|
+
processJoinRoomPresenceStanza(presence);
|
940
|
+
break;
|
941
|
+
case "unavailable":
|
942
|
+
processLeaveRoomPresenceStanza(presence);
|
943
|
+
break;
|
944
|
+
case "error":
|
945
|
+
processJoinErrorRoomPresenceStanza(presence);
|
946
|
+
break;
|
947
|
+
}
|
948
|
+
return true;
|
949
|
+
}
|
950
|
+
|
951
|
+
|
952
|
+
//Rest of stanzas
|
868
953
|
switch (ptype){
|
869
954
|
case undefined:
|
870
|
-
|
955
|
+
processAvailableRoomPresenceStanza(presence)
|
871
956
|
break;
|
872
957
|
case "available":
|
873
|
-
|
958
|
+
processAvailableRoomPresenceStanza(presence)
|
874
959
|
break;
|
875
960
|
case "unavailable":
|
876
|
-
|
961
|
+
processUnavailableRoomPresenceStanza(presence)
|
877
962
|
break;
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
963
|
+
default :
|
964
|
+
//Stanza type not recognize
|
965
|
+
return true
|
966
|
+
}
|
967
|
+
|
968
|
+
return true
|
969
|
+
}
|
884
970
|
|
885
971
|
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
processAvailableRoomPresenceStanza(presence)
|
893
|
-
break;
|
894
|
-
case "unavailable":
|
895
|
-
processUnavailableRoomPresenceStanza(presence)
|
896
|
-
break;
|
897
|
-
default :
|
898
|
-
//Stanza type not recognize
|
899
|
-
return true
|
900
|
-
}
|
972
|
+
var processJoinRoomPresenceStanza = function(presence){
|
973
|
+
var from = $(presence).attr('from');
|
974
|
+
var room_slug = getSlugFromJid(from);
|
975
|
+
storeRoomInformation(room_slug);
|
976
|
+
|
977
|
+
var xElements = presence.getElementsByTagName('x');
|
901
978
|
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
function
|
907
|
-
|
908
|
-
|
909
|
-
|
979
|
+
if (xElements.length == 1) {
|
980
|
+
var xElement = xElements[0];
|
981
|
+
var items = xElement.getElementsByTagName('item');
|
982
|
+
|
983
|
+
$.each(items, function(index, value) {
|
984
|
+
var role = $(value).attr("role")
|
985
|
+
var affiliation = $(value).attr("affiliation")
|
986
|
+
|
987
|
+
roomsInfo[room_slug].affiliation = affiliation
|
988
|
+
roomsInfo[room_slug].role = role
|
989
|
+
if(roomsInfo[room_slug].joined == false){
|
990
|
+
roomsInfo[room_slug].joined = true
|
991
|
+
PRESENCE.NOTIFICATIONS.changeInitialNotificationInGroup(room_slug,I18n.t('chat.muc.occupants'))
|
992
|
+
}
|
993
|
+
});
|
994
|
+
}
|
995
|
+
}
|
910
996
|
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
errorMsg = errorMsg + " with code:" + code + " and type:" + type
|
949
|
-
var textElements = error.getElementsByTagName('text')
|
950
|
-
if (textElements.length == 1) {
|
951
|
-
var text = $(textElements[0]).text()
|
952
|
-
errorMsg = errorMsg + "\n" + text
|
997
|
+
var processLeaveRoomPresenceStanza = function(presence){
|
998
|
+
var from = $(presence).attr('from');
|
999
|
+
var room_slug = getSlugFromJid(from);
|
1000
|
+
resetRoomConfig(room_slug)
|
1001
|
+
PRESENCE.NOTIFICATIONS.changeInitialNotificationInGroup(room_slug,"")
|
1002
|
+
}
|
1003
|
+
|
1004
|
+
var processJoinErrorRoomPresenceStanza = function(presence){
|
1005
|
+
var from = $(presence).attr('from')
|
1006
|
+
var room_slug = getSlugFromJid(from)
|
1007
|
+
var errorMsg = "Error";
|
1008
|
+
|
1009
|
+
var eElements = presence.getElementsByTagName('error')
|
1010
|
+
if (eElements.length == 1) {
|
1011
|
+
var error = eElements[0];
|
1012
|
+
var code = $(error).attr("code")
|
1013
|
+
var type = $(error).attr("type")
|
1014
|
+
errorMsg = errorMsg + " with code:" + code + " and type:" + type
|
1015
|
+
var textElements = error.getElementsByTagName('text')
|
1016
|
+
if (textElements.length == 1) {
|
1017
|
+
var text = $(textElements[0]).text()
|
1018
|
+
errorMsg = errorMsg + "\n" + text
|
1019
|
+
}
|
1020
|
+
|
1021
|
+
//Try to fix errors!
|
1022
|
+
if(code==409){
|
1023
|
+
//Case: Nickname already in use
|
1024
|
+
if (changeRoomNickNameAndJoinAgain(room_slug)){
|
1025
|
+
return;
|
1026
|
+
}
|
1027
|
+
}
|
1028
|
+
//if(code==403){
|
1029
|
+
//Case: Auth Denied
|
1030
|
+
//}
|
1031
|
+
|
1032
|
+
//[...]
|
1033
|
+
|
953
1034
|
}
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
1035
|
+
|
1036
|
+
resetRoomConfig(room_slug)
|
1037
|
+
PRESENCE.NOTIFICATIONS.initialNotificationInGroup(room_slug,I18n.t("chat.muc.joinError", {errorMsg: errorMsg}))
|
1038
|
+
}
|
1039
|
+
|
1040
|
+
var processAvailableRoomPresenceStanza = function(presence){
|
1041
|
+
var from = $(presence).attr('from');
|
1042
|
+
var nick = getNickFromChatRoomJid(from)
|
1043
|
+
var room_slug = getSlugFromJid(from)
|
1044
|
+
storeRoomInformation(room_slug);
|
1045
|
+
|
1046
|
+
if (roomsInfo[room_slug].occupants.indexOf(nick)==-1){
|
1047
|
+
roomsInfo[room_slug].occupants.push(nick)
|
1048
|
+
PRESENCE.NOTIFICATIONS.addNickToNotificationInGroup(room_slug,nick)
|
1049
|
+
PRESENCE.UIMANAGER.writeReceivedMessageOnChatWindow("",room_slug, I18n.t("chat.muc.join", {nick: nick}))
|
1050
|
+
}
|
1051
|
+
}
|
1052
|
+
|
1053
|
+
var processUnavailableRoomPresenceStanza = function(presence){
|
1054
|
+
var from = $(presence).attr('from');
|
1055
|
+
var nick = getNickFromChatRoomJid(from)
|
1056
|
+
var room_slug = getSlugFromJid(from)
|
1057
|
+
storeRoomInformation(room_slug);
|
1058
|
+
|
1059
|
+
if (roomsInfo[room_slug].occupants.indexOf(nick)!=-1){
|
1060
|
+
roomsInfo[room_slug].occupants.splice(roomsInfo[room_slug].occupants.indexOf(nick),1)
|
1061
|
+
PRESENCE.NOTIFICATIONS.removeNickFromNotificationInGroup(room_slug,nick)
|
1062
|
+
PRESENCE.UIMANAGER.writeReceivedMessageOnChatWindow("",room_slug,I18n.t("chat.muc.leave", {nick: nick}))
|
1063
|
+
}
|
1064
|
+
}
|
1065
|
+
|
1066
|
+
|
1067
|
+
|
1068
|
+
//////////////////
|
1069
|
+
// Getters
|
1070
|
+
//////////////////
|
1071
|
+
var getSlugFromJid = function(jid){
|
1072
|
+
return jid.split("@")[0];
|
1073
|
+
}
|
1074
|
+
|
1075
|
+
var getDomainFromJid = function(jid){
|
1076
|
+
return jid.split("@")[1].split("/")[0];
|
1077
|
+
}
|
1078
|
+
|
1079
|
+
var isChatRoomJid = function(jid){
|
1080
|
+
if ((getDomainFromJid(jid).split(".")[0])==muc_host){
|
1081
|
+
return true;
|
1082
|
+
}
|
1083
|
+
return false;
|
1084
|
+
}
|
1085
|
+
|
1086
|
+
var getNameFromSlug = function(slug){
|
1087
|
+
var connectionBox = PRESENCE.UIMANAGER.getConnectionBoxFromSlug(slug);
|
1088
|
+
|
1089
|
+
if(connectionBox!=null){
|
1090
|
+
return $(connectionBox).attr("name");
|
1091
|
+
}
|
1092
|
+
|
1093
|
+
var chatBox = PRESENCE.WINDOW.getChatBoxForSlug(slug)
|
1094
|
+
if(chatBox!=null){
|
1095
|
+
return chatBox.attr("name");
|
1096
|
+
}
|
1097
|
+
|
1098
|
+
//return rebuildNameFromSlug(slug)
|
1099
|
+
return slug;
|
1100
|
+
}
|
1101
|
+
|
1102
|
+
var rebuildNameFromSlug = function(slug){
|
1103
|
+
var cname = slug.split("-");
|
1104
|
+
var name = "";
|
1105
|
+
for(i=0; i<cname.length; i++){
|
1106
|
+
if (i!=0){
|
1107
|
+
name = name + " ";
|
1108
|
+
}
|
1109
|
+
name = name + cname[i][0].toUpperCase() + cname[i].substring(1,cname[i].length);
|
1110
|
+
}
|
1111
|
+
return name;
|
1112
|
+
}
|
1113
|
+
|
1114
|
+
var getNameFromJid = function(){
|
1115
|
+
return getNameFromSlug(getSlugFromJid(jid));
|
1116
|
+
}
|
1117
|
+
|
1118
|
+
var getJidFromSlug = function(slug){
|
1119
|
+
return slug + "@" + domain;
|
1120
|
+
}
|
1121
|
+
|
1122
|
+
var getNickFromChatRoomJid = function(jid){
|
1123
|
+
return jid.split("/")[1];
|
1124
|
+
}
|
1125
|
+
|
1126
|
+
var purgeNickFromChatRoomJid = function(jid){
|
1127
|
+
return jid.split("/")[0];
|
1128
|
+
}
|
1129
|
+
|
1130
|
+
var getSStreamChatStatus = function(){
|
1131
|
+
return sstreamChatStatus;
|
1132
|
+
}
|
1133
|
+
|
1134
|
+
var getConnection = function(){
|
1135
|
+
if(! strophe_connection){
|
1136
|
+
strophe_connection = new Strophe.Connection(BOSH_SERVICE);
|
961
1137
|
}
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
1138
|
+
return strophe_connection;
|
1139
|
+
}
|
1140
|
+
|
1141
|
+
var isNewConnection = function(){
|
1142
|
+
return afterNewConnectionFlag
|
1143
|
+
}
|
1144
|
+
|
1145
|
+
var setNewConnection = function(bol){
|
1146
|
+
afterNewConnectionFlag = bol;
|
968
1147
|
}
|
969
1148
|
|
970
|
-
|
971
|
-
|
972
|
-
}
|
973
|
-
|
974
|
-
function processAvailableRoomPresenceStanza(presence){
|
975
|
-
var from = $(presence).attr('from');
|
976
|
-
var nick = getNickFromChatRoomJid(from)
|
977
|
-
var room_slug = getSlugFromJid(from)
|
978
|
-
storeRoomInformation(room_slug);
|
979
|
-
|
980
|
-
if (roomsInfo[room_slug].occupants.indexOf(nick)==-1){
|
981
|
-
roomsInfo[room_slug].occupants.push(nick)
|
982
|
-
addNickToNotificationInGroup(room_slug,nick)
|
983
|
-
writeReceivedMessageOnChatWindow("",room_slug, I18n.t("chat.muc.join", {nick: nick}))
|
984
|
-
}
|
985
|
-
}
|
986
|
-
|
987
|
-
function processUnavailableRoomPresenceStanza(presence){
|
988
|
-
var from = $(presence).attr('from');
|
989
|
-
var nick = getNickFromChatRoomJid(from)
|
990
|
-
var room_slug = getSlugFromJid(from)
|
991
|
-
storeRoomInformation(room_slug);
|
992
|
-
|
993
|
-
if (roomsInfo[room_slug].occupants.indexOf(nick)!=-1){
|
994
|
-
roomsInfo[room_slug].occupants.splice(roomsInfo[room_slug].occupants.indexOf(nick),1)
|
995
|
-
removeNickFromNotificationInGroup(room_slug,nick)
|
996
|
-
writeReceivedMessageOnChatWindow("",room_slug,I18n.t("chat.muc.leave", {nick: nick}))
|
1149
|
+
var isFirstConnection = function(){
|
1150
|
+
return afterFirstConnectionFlag;
|
997
1151
|
}
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
//////////////////
|
1003
|
-
// Getters
|
1004
|
-
//////////////////
|
1005
|
-
function getSlugFromJid(jid){
|
1006
|
-
return jid.split("@")[0];
|
1007
|
-
}
|
1008
|
-
|
1009
|
-
function getDomainFromJid(jid){
|
1010
|
-
return jid.split("@")[1].split("/")[0];
|
1011
|
-
}
|
1012
|
-
|
1013
|
-
function isChatRoomJid(jid){
|
1014
|
-
if ((getDomainFromJid(jid).split(".")[0])==muc_host){
|
1015
|
-
return true;
|
1152
|
+
|
1153
|
+
var setFirstConnection = function(bol){
|
1154
|
+
afterFirstConnectionFlag = bol;
|
1016
1155
|
}
|
1017
|
-
return false;
|
1018
|
-
}
|
1019
|
-
|
1020
|
-
function getNameFromSlug(slug){
|
1021
|
-
var connectionBox = getConnectionBoxFromSlug(slug);
|
1022
1156
|
|
1023
|
-
|
1024
|
-
return
|
1157
|
+
var getUserStatus = function(){
|
1158
|
+
return userStatus;
|
1025
1159
|
}
|
1026
1160
|
|
1027
|
-
var
|
1028
|
-
|
1029
|
-
|
1030
|
-
}
|
1161
|
+
var setUserStatus = function(status){
|
1162
|
+
userStatus = status;
|
1163
|
+
}
|
1031
1164
|
|
1032
|
-
|
1033
|
-
|
1034
|
-
}
|
1035
|
-
|
1036
|
-
function
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1165
|
+
var getDisconnectionFlag = function(){
|
1166
|
+
return disconnectionFlag;
|
1167
|
+
}
|
1168
|
+
|
1169
|
+
var getRoomsInfo = function(){
|
1170
|
+
return roomsInfo;
|
1171
|
+
}
|
1172
|
+
|
1173
|
+
return {
|
1174
|
+
init: init,
|
1175
|
+
connectToChat : connectToChat,
|
1176
|
+
onReconnect : onReconnect,
|
1177
|
+
isStropheConnected : isStropheConnected,
|
1178
|
+
isUserConnected : isUserConnected,
|
1179
|
+
authByCookie : authByCookie,
|
1180
|
+
authByPassword : authByPassword,
|
1181
|
+
disconnect : disconnect,
|
1182
|
+
awayTimerFunction : awayTimerFunction,
|
1183
|
+
restartAwayTimer : restartAwayTimer,
|
1184
|
+
sendIQStanzaForRequestClientInfo : sendIQStanzaForRequestClientInfo,
|
1185
|
+
sendIQStanzaToRequestVideochat : sendIQStanzaToRequestVideochat,
|
1186
|
+
sendIQStanzaToResponseVideochat : sendIQStanzaToResponseVideochat,
|
1187
|
+
sendIQStanzaToCancelVideochat : sendIQStanzaToCancelVideochat,
|
1188
|
+
getJavascriptXMPPClientName : getJavascriptXMPPClientName,
|
1189
|
+
sendChatMessage : sendChatMessage,
|
1190
|
+
sendStatus : sendStatus,
|
1191
|
+
accessRoom : accessRoom,
|
1192
|
+
joinRoom : joinRoom,
|
1193
|
+
leaveRoom : leaveRoom,
|
1194
|
+
getSlugFromJid : getSlugFromJid,
|
1195
|
+
getJidFromSlug : getJidFromSlug,
|
1196
|
+
getNameFromSlug : getNameFromSlug,
|
1197
|
+
getNickFromChatRoomJid : getNickFromChatRoomJid,
|
1198
|
+
getConnection : getConnection,
|
1199
|
+
isNewConnection : isNewConnection,
|
1200
|
+
setNewConnection : setNewConnection,
|
1201
|
+
isFirstConnection : isFirstConnection,
|
1202
|
+
setFirstConnection : setFirstConnection,
|
1203
|
+
getUserStatus : getUserStatus,
|
1204
|
+
setUserStatus : setUserStatus,
|
1205
|
+
getDisconnectionFlag : getDisconnectionFlag,
|
1206
|
+
getRoomsInfo : getRoomsInfo,
|
1207
|
+
getSStreamChatStatus: getSStreamChatStatus
|
1208
|
+
};
|
1209
|
+
|
1210
|
+
}) (PRESENCE, jQuery);
|
1055
1211
|
|
1056
|
-
function getNickFromChatRoomJid(jid){
|
1057
|
-
return jid.split("/")[1];
|
1058
|
-
}
|
1059
1212
|
|
1060
|
-
function purgeNickFromChatRoomJid(jid){
|
1061
|
-
return jid.split("/")[0];
|
1062
|
-
}
|