social_stream 0.23.2 → 0.23.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/base/app/assets/javascripts/layouts.js +0 -1
  2. data/base/app/assets/javascripts/social_stream.comments.js +10 -3
  3. data/base/app/assets/javascripts/social_stream.search.js.erb +3 -1
  4. data/base/app/assets/javascripts/social_stream.wall.js.erb +8 -1
  5. data/base/app/assets/stylesheets/{activities.css.scss → activities.css.scss.erb} +1 -1
  6. data/base/app/models/relation.rb +4 -0
  7. data/base/app/models/tie.rb +5 -0
  8. data/base/app/views/cheesecake/_index.html.erb +2 -2
  9. data/base/app/views/layouts/_search.html.erb +2 -2
  10. data/base/app/views/posts/_new_activity_fields.erb +0 -6
  11. data/base/lib/generators/social_stream/base/templates/relations.yml +4 -4
  12. data/base/lib/social_stream/base/version.rb +1 -1
  13. data/base/lib/tasks/db/populate.rake +2 -2
  14. data/base/spec/dummy/config/relations.yml +4 -4
  15. data/base/vendor/assets/javascripts/jquery.watermark.js +563 -0
  16. data/documents/app/assets/javascripts/social_stream.audio.js.erb +25 -0
  17. data/documents/app/assets/javascripts/social_stream.repository.js.erb +27 -0
  18. data/documents/app/assets/javascripts/social_stream.video.js.erb +38 -0
  19. data/documents/app/assets/stylesheets/documents.css.scss +11 -14
  20. data/documents/app/views/audios/_audio.html.erb +0 -18
  21. data/documents/app/views/audios/_audio_processed.html.erb +35 -39
  22. data/documents/app/views/common_documents/_document_info.html.erb +2 -2
  23. data/documents/app/views/common_documents/_edit_form.html.erb +1 -1
  24. data/documents/app/views/common_documents/_headers.html.erb +1 -1
  25. data/documents/app/views/common_documents/_index.html.erb +3 -0
  26. data/documents/app/views/pictures/_picture.html.erb +3 -1
  27. data/documents/app/views/videos/_video.html.erb +0 -20
  28. data/documents/app/views/videos/_video_processed.html.erb +56 -43
  29. data/documents/config/locales/en.yml +1 -1
  30. data/documents/config/locales/es.yml +1 -1
  31. data/documents/lib/social_stream/documents/version.rb +1 -1
  32. data/documents/social_stream-documents.gemspec +1 -1
  33. data/documents/vendor/assets/javascripts/jquery.jplayer.js +87 -68
  34. data/documents/vendor/assets/swf/Jplayer.swf +0 -0
  35. data/events/app/assets/javascripts/social_stream-events.js +2 -0
  36. data/events/app/assets/javascripts/social_stream.calendar.js.erb +98 -0
  37. data/events/app/assets/javascripts/social_stream.event.js +17 -0
  38. data/events/app/assets/javascripts/social_stream.events.poster.js +1 -0
  39. data/events/app/assets/javascripts/{events.js.coffee → social_stream.events.tools.js.coffee} +0 -16
  40. data/events/app/assets/stylesheets/events.css.scss +33 -0
  41. data/events/app/controllers/events_controller.rb +19 -9
  42. data/events/app/views/events/_event.html.erb +5 -0
  43. data/events/app/views/events/_sidebar_calendar.html.erb +6 -28
  44. data/events/app/views/events/index.js.erb +3 -0
  45. data/events/app/views/rooms/_form.html.erb +1 -1
  46. data/events/app/views/rooms/create.js.erb +1 -1
  47. data/events/lib/social_stream/events/version.rb +1 -1
  48. data/events/social_stream-events.gemspec +1 -1
  49. data/lib/social_stream/version.rb +1 -1
  50. data/presence/app/assets/javascripts/jquery.ui.chatbox.sstreampresence.js +1 -1
  51. data/presence/app/assets/javascripts/presence.js.erb +16 -1
  52. data/presence/app/assets/javascripts/presence_XmppClient.js.erb +10 -3
  53. data/presence/app/assets/javascripts/presence_game.js.erb +284 -49
  54. data/presence/app/assets/javascripts/presence_game_comunication.js.erb +313 -0
  55. data/presence/app/assets/javascripts/presence_game_interface.js.erb +134 -0
  56. data/presence/app/assets/javascripts/presence_game_ter.js.erb +237 -188
  57. data/presence/app/assets/javascripts/presence_persistence.js +1 -1
  58. data/presence/app/assets/javascripts/presence_uiManager.js.erb +4 -2
  59. data/presence/app/assets/javascripts/presence_utilities.js +1 -1
  60. data/presence/app/assets/javascripts/presence_videochat.js.erb +2 -3
  61. data/presence/app/assets/javascripts/presence_windowManager.js +8 -1
  62. data/presence/app/assets/stylesheets/TresEnRaya.css +57 -0
  63. data/presence/app/assets/stylesheets/chat.css.scss +22 -1
  64. data/presence/app/views/chat/_index.html.erb +15 -18
  65. data/presence/config/locales/en.yml +14 -1
  66. data/presence/config/locales/es.yml +14 -1
  67. data/presence/lib/social_stream/presence/version.rb +1 -1
  68. data/presence/lib/tasks/presence/installer.rake +2 -2
  69. data/presence/social_stream-presence.gemspec +1 -1
  70. data/presence/vendor/assets/javascripts/jquery.gamequery-0.5.1.js +1164 -0
  71. data/social_stream.gemspec +4 -4
  72. data/spec/dummy/config/relations.yml +4 -4
  73. metadata +44 -34
  74. data/base/vendor/assets/javascripts/jquery.watermarkinput.js +0 -81
  75. data/documents/app/assets/javascripts/documents.js.erb +0 -71
@@ -40,6 +40,11 @@
40
40
  <div class="title">
41
41
  <%= link_to event.title, event %>
42
42
  </div>
43
+
44
+ <div class="description">
45
+ <%= simple_format auto_link(event.description) %>
46
+ </div>
47
+
43
48
  </div>
44
49
  <% end %>
45
50
 
@@ -26,34 +26,12 @@
26
26
  </table>
27
27
 
28
28
  <%= javascript_tag do %>
29
- var now = new Date();
30
- $('#sidebar_day_' + now.getDate() + '_' + (now.getMonth()+1) + '_' + now.getFullYear()).addClass('today');
31
- var re = new RegExp('sidebar_day_(..?)_(..?)_(..?.?.?)');
32
- $('#sidebar_calendar td').each(function(index, domEl){
33
- var m = re.exec(domEl.id);
34
- if(m == null) return;
35
- var d = new Date(m[3], (m[2]-1), m[1], 23, 59, 59);
36
- if(d < now) $(domEl).addClass('past');
37
- if(m[2] != (now.getMonth()+1) && d > now) $(domEl).addClass('next_month');
38
- });
39
- $.ajax({
40
- dataType: 'json',
41
- cache: false,
42
- url: "<%= escape_javascript polymorphic_path([@current_subject, Event.new]) %>",
43
- data: {
44
- start: <%= bow.to_i %>,
45
- end: <%= (bow + 28.days).to_i %>
46
- },
47
- success: function(events) {
48
- $.map(events, function(event) {
49
- var start = new Date(event.start); // This applies TZ
50
- var end = new Date(event.end);
51
- for(loopTime=start.getTime(); loopTime <= end.getTime(); loopTime+=86400000) {
52
- var d = new Date(loopTime);
53
- $('#sidebar_day_'+ d.getDate() + '_' + (d.getMonth()+1) + '_' + d.getFullYear()).addClass("busy");
54
- }
55
- })
56
- }
29
+ $(function(){
30
+ SocialStream.Calendar.init({
31
+ eventsPath: "<%= escape_javascript polymorphic_path([@current_subject, Event.new]) %>",
32
+ start: "<%= bow.to_i %>",
33
+ end: "<%= (bow + 28.days).to_i %>"
34
+ });
57
35
  });
58
36
  <% end %>
59
37
 
@@ -0,0 +1,3 @@
1
+ $("#tipsy-<%= params[:tipsy] %>").html("<%= escape_javascript render(@events) %>");
2
+
3
+ SocialStream.Event.index();
@@ -26,6 +26,6 @@
26
26
 
27
27
  <%= javascript_tag do %>
28
28
  $(function(){
29
- $('#room_name').Watermark("<%= escape_javascript t('room.watermark.name') %>");
29
+ $('#room_name').watermark("<%= escape_javascript t('room.watermark.name') %>");
30
30
  });
31
31
  <% end %>
@@ -1,7 +1,7 @@
1
1
  <% if @room.valid? %>
2
2
  $('#rooms').replaceWith("<%= escape_javascript render(:partial => 'index') %>");
3
3
  $('#room_name').val("");
4
- $('#room_name').Watermark("<%= escape_javascript t('room.watermark.name') %>");
4
+ $('#room_name').watermark("<%= escape_javascript t('room.watermark.name') %>");
5
5
  <% else %>
6
6
  $('#new_room').replaceWith("<%= escape_javascript render(:partial => 'form') %>");
7
7
  <% end %>
@@ -1,5 +1,5 @@
1
1
  module SocialStream
2
2
  module Events
3
- VERSION = "0.9.1".freeze
3
+ VERSION = "0.9.2".freeze
4
4
  end
5
5
  end
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.files = `git ls-files`.split("\n")
13
13
 
14
14
  # Gem dependencies
15
- s.add_runtime_dependency('social_stream-base', '~> 0.17.1')
15
+ s.add_runtime_dependency('social_stream-base', '~> 0.17.2')
16
16
  s.add_runtime_dependency('rails-scheduler', '~> 0.0.6')
17
17
  s.add_runtime_dependency('coffee-rails', '>= 3.1.0')
18
18
 
@@ -1,3 +1,3 @@
1
1
  module SocialStream
2
- VERSION = "0.23.2".freeze
2
+ VERSION = "0.23.3".freeze
3
3
  end
@@ -223,7 +223,7 @@
223
223
  .hover(function() {uiChatboxTitlebarGames.addClass('ui-state-hover');},
224
224
  function() {uiChatboxTitlebarGames.removeClass('ui-state-hover');})
225
225
  .click(function(event) {
226
- pickGamesButton(self)
226
+ PRESENCE.GAME.INTERFACE.pickGamesButton(self)
227
227
  return false;
228
228
  })
229
229
  .appendTo(uiChatboxTitlebar),
@@ -1,4 +1,19 @@
1
1
  var PRESENCE = PRESENCE || {};
2
2
 
3
3
  PRESENCE.VERSION = '<%=SocialStream::Presence::VERSION%>';
4
- PRESENCE.AUTHORS = 'Aldo Gordillo';
4
+ PRESENCE.AUTHORS = 'Aldo Gordillo';
5
+
6
+
7
+ PRESENCE.CORE = (function(P,$,undefined){
8
+
9
+ var init = function(){
10
+ initFocusListeners();
11
+ checkVideocallFeature();
12
+ PRESENCE.GAME.init(strophe_connection);
13
+ initAudio();
14
+ };
15
+
16
+ return {
17
+ init: init
18
+ };
19
+ }) (PRESENCE, jQuery);
@@ -53,6 +53,12 @@ function chatContact(domain,resource,client,version) {
53
53
  this.guest_token=null;
54
54
  this.session=null;
55
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;
56
62
  }
57
63
 
58
64
  //Rooms information
@@ -387,6 +393,7 @@ function processUnavailablePresenceStanza(presence){
387
393
  if (slug != user_slug) {
388
394
  if (getConnectionBoxFromSlug(slug)!=null){
389
395
  updateInterfaceAfterPresenceStanza(slug,false)
396
+ PRESENCE.GAME.userDisconnected(slug)
390
397
  }
391
398
  }
392
399
  }
@@ -426,7 +433,7 @@ function onIQStanza(iq){
426
433
  var type = iq.getAttribute("type");
427
434
  var from = iq.getAttribute("from");
428
435
  var slug = from.split("@")[0];
429
-
436
+
430
437
  if (slug == user_slug) {
431
438
  return true;
432
439
  }
@@ -577,12 +584,11 @@ function handleIQResultFromVideochatRequestCancel(iq,slug){
577
584
  var response = queryElement.getElementsByTagName('response');
578
585
 
579
586
  if(response.length == 1){
580
- receiveVideoChatCancelationFromUser(slug,$(response).text());
587
+ receiveVideoChatCancelationFromUser(slug);
581
588
  return true;
582
589
  }
583
590
  }
584
591
 
585
- receiveVideoChatCancelationFromUser(slug,"Bad response");
586
592
  return true;
587
593
  }
588
594
 
@@ -764,6 +770,7 @@ function handleIQResultFromMucOccupantsRequest(iq){
764
770
  var nick = $(value).attr("name");
765
771
  if(roomsInfo[room_slug].occupants.indexOf(nick)==-1){
766
772
  roomsInfo[room_slug].occupants.push(nick)
773
+ addNickToNotificationInGroup(room_slug,nick)
767
774
  }
768
775
  });
769
776
  }
@@ -3,74 +3,309 @@
3
3
  ////////////////////
4
4
 
5
5
  PRESENCE.GAME = (function(P,$,undefined){
6
-
7
- //Gamecore variables
8
- var connection = null;
9
- iqStanzaID['gameRequest'] = "gameRequestID";
10
6
 
11
- var init = function(myConnection){
12
- connection = myconnection;
13
- };
7
+ /////////////////////////////////
8
+ // GAME CORE VARS //
9
+ /////////////////////////////////
10
+
11
+ //Manage Game information
12
+ //gameID == Game to play
13
+ //Players == List of players
14
+ //Options == Game options
15
+ function game(gameId,gameName,players,options){
16
+ this.id = gameId;
17
+ this.name = gameName;
18
+ this.players = players;
19
+ this.options = options;
20
+ this.handler = null;
21
+ }
14
22
 
23
+ function player(id,name){
24
+ this.id = id;
25
+ this.name = name;
26
+ }
27
+
28
+ function validationResult(pass,reason){
29
+ this.pass = pass;
30
+ this.reason = reason;
31
+ }
32
+
33
+ var createValidationResult = function (pass,reason){
34
+ return new validationResult(pass,reason);
35
+ }
15
36
 
16
- var sendIQStanzaToRequestGame = function (slug,players,options){
17
-
18
- if (slug in contactsInfo) {
19
- var jid=slug+"@"+contactsInfo[slug].domain+"/"+contactsInfo[slug].resource;
20
-
21
- var iq = $iq({to: jid, type: "get", id: iqStanzaID['gameRequest']})
22
- .c("query", {xmlns: "urn:ietf:params:xml:ns:xmpp-stanzas"})
23
- .c("game", {name: "gameName"})
24
- .c("players", {})
25
- .c("player1").t("player1value").up()
26
- .c("player2").t("player2value").up()
27
- .c("options", {})
28
- .c("options1").t("options1value").up()
29
- .c("options2").t("options2value").up()
30
- strophe_connection.sendIQ(iq);
31
- }
32
- };
33
-
34
- //Getters
35
- var getDummy = function(){
36
- return param;
37
- };
38
-
39
37
 
40
- return {
41
- init: init,
42
- sendIQStanzaToRequestGame: sendIQStanzaToRequestGame,
43
- getDummy: getDummy
38
+ /////////////////////////////////
39
+ // CORE METHODS //
40
+ /////////////////////////////////
41
+
42
+ var init = function(myConnection){
43
+ P.GAME.COMUNICATION.init(myConnection);
44
44
  };
45
+
45
46
 
46
- }) (PRESENCE, jQuery);
47
-
48
-
47
+ var requestUserToPlay = function (slug,game){
48
+ if (slug in contactsInfo) {
49
+ var gameStatus = contactsInfo[slug].gameStatus;
50
+ } else {
51
+ var gameStatus = null;
52
+ }
53
+
54
+ if(! isUserConnected()){
55
+ P.GAME.INTERFACE.updateInterfaceOnInformationMessage(slug, I18n.t("chat.game.offline"));
56
+ if(gameStatus!=null){
57
+ contactsInfo[slug].gameStatus = "disconnected";
58
+ }
59
+ return;
60
+ }
49
61
 
62
+ if(! isSlugChatConnected(slug)){
63
+ P.GAME.INTERFACE.updateInterfaceOnInformationMessage(slug, I18n.t("chat.game.guestOffline", {name: getNameFromSlug(slug)}));
64
+ if(gameStatus!=null){
65
+ contactsInfo[slug].gameStatus = "disconnected";
66
+ }
67
+ return;
68
+ }
69
+
70
+ if(gameStatus==null){
71
+ P.GAME.INTERFACE.updateInterfaceOnInformationMessage(slug,I18n.t('chat.game.unable'));
72
+ return;
73
+ }
74
+
75
+ if(gameStatus!="disconnected"){
76
+ P.GAME.INTERFACE.updateInterfaceOnInformationMessage(slug,"Esta ocupado en otro estado!=desconectado...")
77
+ return;
78
+ }
50
79
 
80
+ //gameStatus=="disconnected"
81
+ //Start connection
82
+ contactsInfo[slug].gameStatus="waiting";
83
+ P.GAME.INTERFACE.updateInterfaceOnInformationMessage(slug,I18n.t('chat.game.waiting'));
51
84
 
85
+ contactsInfo[slug].game = game
86
+ var jid=slug+"@"+contactsInfo[slug].domain+"/"+contactsInfo[slug].resource;
87
+ return P.GAME.COMUNICATION.sendIQStanzaToRequestGame(jid,game);
88
+ }
89
+
90
+ var responseUserToPlay = function (slug,result){
91
+ if (! slug in contactsInfo) {
92
+ return;
93
+ }
94
+ var jid=slug+"@"+contactsInfo[slug].domain+"/"+contactsInfo[slug].resource;
95
+ P.GAME.COMUNICATION.sendIQStanzaToResponseGameRequest(jid,result)
96
+ if(result=="yes"){
97
+ contactsInfo[slug].gameStatus="playing";
98
+ PRESENCE.GAME.INTERFACE.updateInterfaceBeforeStartGame(slug);
99
+ } else {
100
+ contactsInfo[slug].gameStatus="disconnected";
101
+ PRESENCE.GAME.INTERFACE.updateInterfaceAfterFinishGame(slug);
102
+ }
103
+ }
52
104
 
105
+ var sendAction = function(gameId,players,action){
106
+ $.each(players, function(index, value) {
107
+ var slug = value.id;
108
+ if(slug!=user_slug){
109
+ if(slug in contactsInfo){
110
+ var jid=slug+"@"+contactsInfo[slug].domain+"/"+contactsInfo[slug].resource;
111
+ P.GAME.COMUNICATION.sendIQStanzaWithAction(jid,gameId,action);
112
+ }
113
+ }
114
+ });
115
+ }
53
116
 
54
117
 
118
+ var updateLogicAfterReceivedGameRequest = function(slug,gameId,gameName,players,options){
119
+ if(! slug in contactsInfo){
120
+ return;
121
+ }
122
+ contactsInfo[slug].game = new game(gameId,gameName,players,options)
123
+ if (contactsInfo[slug].gameStatus!="disconnected"){
124
+ P.GAME.COMUNICATION.sendIQStanzaToResponseGameRequest(slug,"busy");
125
+ return true;
126
+ } else {
127
+ contactsInfo[slug].gameStatus="pending";
128
+ }
129
+ P.GAME.INTERFACE.updateInterfaceAfterGameRequestReceived(slug)
130
+ }
55
131
 
132
+ var updateLogicAfterReceivedGameRequestResponse = function(slug,response){
133
+ if(contactsInfo[slug].gameStatus!="waiting"){
134
+ return true;
135
+ }
136
+ if(response=="yes"){
137
+ contactsInfo[slug].gameStatus = "playing";
138
+ P.GAME.INTERFACE.updateInterfaceBeforeStartGame(slug)
139
+ } else if (response=="no"){
140
+ P.GAME.INTERFACE.updateInterfaceOnInformationMessage(slug,I18n.t("chat.game.rejected", {name: getNameFromSlug(slug)}));
141
+ contactsInfo[slug].gameStatus="disconnected";
142
+ } else if (response=="busy"){
143
+ P.GAME.INTERFACE.updateInterfaceOnInformationMessage(slug,I18n.t("chat.game.rejectedBusy", {name: getNameFromSlug(slug)}));
144
+ contactsInfo[slug].gameStatus="disconnected";
145
+ } else {
146
+ P.GAME.INTERFACE.updateInterfaceOnInformationMessage(slug,I18n.t("chat.game.unknown", {name: getNameFromSlug(slug)}));
147
+ contactsInfo[slug].gameStatus="disconnected";
148
+ }
149
+ }
150
+
151
+ var updateLogicAfterReceivedGameRequestCancelation = function(slug,status){
152
+ if(slug in contactsInfo){
153
+ if (status == "finish") {
154
+ if (contactsInfo[slug].gameStatus == "pending") {
155
+ P.GAME.INTERFACE.updateInterfaceOnInformationMessage(slug, I18n.t("chat.game.cancel", {name: getNameFromSlug(slug)}));
156
+ contactsInfo[slug].gameStatus = "disconnected";
157
+ } else if (contactsInfo[slug].gameStatus == "playing") {
158
+ P.GAME.INTERFACE.updateInterfaceOnInformationMessage(slug, I18n.t("chat.game.finish", {name: getNameFromSlug(slug)}));
159
+ contactsInfo[slug].gameStatus = "disconnected";
160
+ }
161
+ }
162
+ } else {
163
+ finishGame(slug);
164
+ }
165
+ }
56
166
 
167
+ var getPlayerNameWithId = function(slug){
168
+ if(! slug in contactsInfo){
169
+ var game = contactsInfo[slug].game
170
+ if((game!=null)&&(game.players!=null)){
171
+ $.each(game.players, function(index, value) {
172
+ if(value[0]==slug){
173
+ return value[1]
174
+ }
175
+ });
176
+ }
177
+ }
178
+ return null
179
+ }
57
180
 
181
+ //Validation functions
182
+ var validateParams = function(myPlayer,game,myDivID){
183
+ var result;
184
+
185
+ result = checkGameObject(game);
186
+ if(! result[0] ){
187
+ return result;
188
+ }
189
+
190
+ if ((typeof myPlayer=="undefined")||(typeof myDivID=="undefined")){
191
+ return new validationResult(false,"myPlayer or myDivID undefined");
192
+ }
58
193
 
194
+ //Check if myPlayers is an Array
195
+ if (game.players.constructor.toString().indexOf("Array") == -1){
196
+ return new validationResult(false,"Game.Players is not an array");
197
+ }
59
198
 
199
+ //Check if myOptions is an Array
200
+ if (game.options.constructor.toString().indexOf("Array") == -1){
201
+ return new validationResult(false,"Game.options is not an array");
202
+ }
203
+
204
+ //Check that myPlayer is contained on myPlayers
205
+ if(game.players.indexOf(myPlayer)==-1){
206
+ return new validationResult(false,"myPlayer is not contained in players array");
207
+ }
60
208
 
209
+ return new validationResult(true,"Ok");
210
+ }
211
+
61
212
 
62
- ////////////////////
63
- //Interface Events
64
- ////////////////////
65
- var global;
213
+ var checkGameObject = function(game){
214
+ if((typeof game=="undefined")||(typeof game.id=="undefined")||(typeof game.name=="undefined")
215
+ ||(typeof game.players=="undefined")||(typeof game.options=="undefined")){
216
+ return new validationResult(false,"Some game field (game/game.id/game.name/game.players/game.options) is undefined");
217
+ }
218
+
219
+ if((game.id=="")||(game.name=="")){
220
+ return new validationResult(false,"game.id or game.name is empty");
221
+ }
222
+
223
+ if(game.id.split(" ").length > 2){
224
+ return new validationResult(false,"Invalid game.id. No whitespaces allowd in this field");
225
+ }
226
+
227
+ return new validationResult(true,"Ok");
228
+ }
229
+
230
+ var startGame = function (slug,divID){
231
+ var game = contactsInfo[slug].game;
232
+ var myplayer = new player(user_slug,getPlayerNameWithId(user_slug))
233
+ var validationResult = validateParams(myplayer,game,divID)
234
+
235
+ if(! validationResult.pass){
236
+ var msg = "StartPlay error with reason: " + validationResult.reason;
237
+ P.GAME.INTERFACE.updateInterfaceOnInformationMessage(slug,msg);
238
+ return;
239
+ }
240
+
241
+ if(typeof PRESENCE.GAME[game.id].validateParams == "function"){
242
+ validationResult = PRESENCE.GAME[game.id].validateParams(myplayer,game,divID)
243
+ if(! validationResult.pass){
244
+ var msg = "StartPlay error with reason: " + validationResult.reason;
245
+ P.GAME.INTERFACE.updateInterfaceOnInformationMessage(slug,msg);
246
+ return;
247
+ }
248
+ } else {
249
+ log("Warning: Missed " + game.name + " validateParams method")
250
+ }
251
+
252
+ if(typeof PRESENCE.GAME[game.id].minimumRequirements == "function"){
253
+ //Check requirements
254
+ } else {
255
+ log("Warning: Missed " + game.name + " minRequirements method")
256
+ }
257
+
258
+ //Add handler and remove previous if exits
259
+ if(game.handler!=null){
260
+ PRESENCE.GAME.COMUNICATION.removeHandler(game.handler)
261
+ }
262
+ game.handler = PRESENCE.GAME.COMUNICATION.addHandler(game.id)
263
+
264
+ //Call PRESENCE.GAME.gameId
265
+ var myplayer = new player(user_slug,user_name)
266
+ PRESENCE.GAME[game.id].init(myplayer,game,divID)
267
+ }
268
+
269
+ var finishGame = function (slug){
270
+ if(slug in contactsInfo){
271
+ var gameStatus = contactsInfo[slug].gameStatus;
272
+ if(gameStatus=="playing"){
273
+ var jid=slug+"@"+contactsInfo[slug].domain+"/"+contactsInfo[slug].resource;
274
+ P.GAME.COMUNICATION.sendIQStanzaToFinishGame(jid);
275
+ if(contactsInfo[slug].game.handler!=null){
276
+ P.GAME.COMUNICATION.removeHandler(contactsInfo[slug].game.handler);
277
+ contactsInfo[slug].game.handler==null;
278
+ }
279
+ } else if(gameStatus=="waiting"){
280
+ var jid=slug+"@"+contactsInfo[slug].domain+"/"+contactsInfo[slug].resource;
281
+ P.GAME.COMUNICATION.sendIQStanzaToFinishGame(jid);
282
+ } else if(gameStatus=="pending"){
283
+ P.GAME.COMUNICATION.sendIQStanzaToResponseGameRequest(slug,"no");
284
+ }
285
+ contactsInfo[slug].gameStatus="disconnected";
286
+ }
287
+
288
+ PRESENCE.GAME.INTERFACE.updateInterfaceAfterFinishGame(slug)
289
+ }
66
290
 
67
- function play(){
68
- $(".chat-gamesthick").css("display","block");
69
- }
291
+ var userDisconnected = function(slug){
292
+ finishGame(slug)
293
+ }
70
294
 
71
- function pickGamesButton(uiElement){
72
- var slug = $(uiElement.element).attr("id");
73
- //clickGamesButton(slug);
74
- log("clickGamesButton(slug)" + slug)
75
- }
295
+ return {
296
+ init: init,
297
+ game: game,
298
+ player: player,
299
+ startGame: startGame,
300
+ finishGame: finishGame,
301
+ createValidationResult: createValidationResult,
302
+ requestUserToPlay: requestUserToPlay,
303
+ responseUserToPlay: responseUserToPlay,
304
+ updateLogicAfterReceivedGameRequest: updateLogicAfterReceivedGameRequest,
305
+ updateLogicAfterReceivedGameRequestCancelation: updateLogicAfterReceivedGameRequestCancelation,
306
+ updateLogicAfterReceivedGameRequestResponse: updateLogicAfterReceivedGameRequestResponse,
307
+ sendAction: sendAction,
308
+ userDisconnected: userDisconnected
309
+ };
76
310
 
311
+ }) (PRESENCE, jQuery);