Browse code

Uprava prihlasovanie sa na jabber konto

Cinan Rakosnik authored on 06/05/2013 at 15:12:59
Showing 4 changed files
... ...
@@ -16,8 +16,7 @@ this.App =
16 16
       App._dispatcher = new WebSocketRails('www.xmpp.dev:3000/websocket')
17 17
       App._dispatcher.on_open = =>
18 18
         @_setupBackboneComponents()
19
-        @_bindListeners()
20
-        callback?()
19
+        @_bindListeners(callback)
21 20
 
22 21
     trigger: (options) ->
23 22
       _.defaults(options, {data: {} })
... ...
@@ -109,7 +108,15 @@ this.App =
109 109
 
110 110
       App.Views.tabbar = new Xmpp.Views.Tabbar.TabbarView()
111 111
 
112
-    _bindListeners: ->
112
+    _bindListeners: (callback) ->
113
+      App._dispatcher.bind('app.client.connected', (jid) ->
114
+        callback?(jid)
115
+      )
116
+
117
+      App._dispatcher.bind('app.client.cannot_connect', (jid) ->
118
+        alert('cannot connect to ' + jid)
119
+      )
120
+
113 121
       App._dispatcher.bind('app.roster.statusChanged', (result) ->
114 122
         App.debug 'change contact state'
115 123
         App.Collections.contacts.updateStatus(result)
... ...
@@ -10,7 +10,7 @@
10 10
 #= require _main
11 11
 #= require chat
12 12
 
13
-App.Com.connect(->
13
+App.Com.connect( (connected_jid) ->
14 14
   App.Com.initRoster(->
15 15
     App.Com.startFetchingVcards()
16 16
     App.Com.startPollingRoster()
... ...
@@ -38,11 +38,16 @@ class WsRosterController < WsController
38 38
         end
39 39
 
40 40
         clients.each do |client|
41
-            begin
42
-                client = Signin.try_login(client[:jid], client[:pass])
43
-                connection_store[:clients] << client
44
-            rescue Signin::LoginError
45
-                send_message 'app.client.cannot_connect', true
41
+            Thread.new do
42
+                begin
43
+                    client = Signin.try_login(client[:jid], client[:pass])
44
+                    connection_store[:clients] << client
45
+                    send_message 'app.client.connected', client.jid.strip.to_s
46
+                    #Rails.logger.debug '!!!!! finished for ' + client_id.to_s
47
+                rescue Signin::LoginError
48
+                    #Rails.logger.debug '!!!!! finished FAILED for ' + client_id.to_s
49
+                    send_message 'app.client.cannot_connect', client.jid.strip.to_s
50
+                end
46 51
             end
47 52
         end
48 53
     end
... ...
@@ -1,4 +1,3 @@
1
-#require 'json/pure'
2 1
 require 'xmpp4r'
3 2
 require 'xmpp4r/roster'
4 3
 require 'cgi'
... ...
@@ -12,8 +11,8 @@ module Signin
12 12
         begin
13 13
             connect(pass)
14 14
             @client
15
-        rescue
16
-            raise LoginError
15
+        rescue Exception => e
16
+            raise LoginError, e.message
17 17
         end
18 18
     end
19 19