Show More
@@ -1,18 +1,18 b'' | |||||
1 | <link rel="import" href="../../../../../../bower_components/polymer/polymer.html"> |
|
1 | <link rel="import" href="../../../../../../bower_components/polymer/polymer.html"> | |
2 | <link rel="import" href="../channelstream-connection/channelstream-connection.html"> |
|
2 | <link rel="import" href="../channelstream-connection/channelstream-connection.html"> | |
3 | <link rel="import" href="../rhodecode-toast/rhodecode-toast.html"> |
|
3 | <link rel="import" href="../rhodecode-toast/rhodecode-toast.html"> | |
4 | <link rel="import" href="../rhodecode-favicon/rhodecode-favicon.html"> |
|
4 | <link rel="import" href="../rhodecode-favicon/rhodecode-favicon.html"> | |
5 |
|
5 | |||
6 | <dom-module id="rhodecode-app"> |
|
6 | <dom-module id="rhodecode-app"> | |
7 | <template> |
|
7 | <template> | |
8 | <rhodecode-favicon></rhodecode-favicon> |
|
|||
9 | <rhodecode-toast id="notifications"></rhodecode-toast> |
|
|||
10 | <channelstream-connection |
|
8 | <channelstream-connection | |
11 | id="channelstream-connection" |
|
9 | id="channelstream-connection" | |
12 | on-channelstream-listen-message="receivedMessage" |
|
10 | on-channelstream-listen-message="receivedMessage" | |
13 | on-channelstream-connected="handleConnected" |
|
11 | on-channelstream-connected="handleConnected" | |
14 | on-channelstream-subscribed="handleSubscribed"> |
|
12 | on-channelstream-subscribed="handleSubscribed"> | |
15 | </channelstream-connection> |
|
13 | </channelstream-connection> | |
|
14 | <rhodecode-favicon></rhodecode-favicon> | |||
|
15 | <rhodecode-toast id="notifications"></rhodecode-toast> | |||
16 | </template> |
|
16 | </template> | |
17 | <script src="rhodecode-app.js"></script> |
|
17 | <script src="rhodecode-app.js"></script> | |
18 | </dom-module> |
|
18 | </dom-module> |
@@ -1,137 +1,137 b'' | |||||
1 | ccLog = Logger.get('RhodeCodeApp'); |
|
1 | ccLog = Logger.get('RhodeCodeApp'); | |
2 | ccLog.setLevel(Logger.OFF); |
|
2 | ccLog.setLevel(Logger.OFF); | |
3 |
|
3 | |||
4 | var rhodeCodeApp = Polymer({ |
|
4 | var rhodeCodeApp = Polymer({ | |
5 | is: 'rhodecode-app', |
|
5 | is: 'rhodecode-app', | |
6 | attached: function () { |
|
6 | attached: function () { | |
7 | ccLog.debug('rhodeCodeApp created'); |
|
7 | ccLog.debug('rhodeCodeApp created'); | |
8 | $.Topic('/notifications').subscribe(this.handleNotifications.bind(this)); |
|
8 | $.Topic('/notifications').subscribe(this.handleNotifications.bind(this)); | |
9 | $.Topic('/favicon/update').subscribe(this.faviconUpdate.bind(this)); |
|
9 | $.Topic('/favicon/update').subscribe(this.faviconUpdate.bind(this)); | |
10 | $.Topic('/connection_controller/subscribe').subscribe( |
|
10 | $.Topic('/connection_controller/subscribe').subscribe( | |
11 | this.subscribeToChannelTopic.bind(this)); |
|
11 | this.subscribeToChannelTopic.bind(this)); | |
12 | // this event can be used to coordinate plugins to do their |
|
12 | // this event can be used to coordinate plugins to do their | |
13 | // initialization before channelstream is kicked off |
|
13 | // initialization before channelstream is kicked off | |
14 | $.Topic('/__MAIN_APP__').publish({}); |
|
14 | $.Topic('/__MAIN_APP__').publish({}); | |
15 |
|
15 | |||
16 | for (var i = 0; i < alertMessagePayloads.length; i++) { |
|
16 | for (var i = 0; i < alertMessagePayloads.length; i++) { | |
17 | $.Topic('/notifications').publish(alertMessagePayloads[i]); |
|
17 | $.Topic('/notifications').publish(alertMessagePayloads[i]); | |
18 | } |
|
18 | } | |
19 | this.kickoffChannelstreamPlugin(); |
|
19 | this.kickoffChannelstreamPlugin(); | |
20 | }, |
|
20 | }, | |
21 |
|
21 | |||
22 | /** proxy to channelstream connection */ |
|
22 | /** proxy to channelstream connection */ | |
23 | getChannelStreamConnection: function () { |
|
23 | getChannelStreamConnection: function () { | |
24 | return this.$['channelstream-connection']; |
|
24 | return this.$['channelstream-connection']; | |
25 | }, |
|
25 | }, | |
26 |
|
26 | |||
27 | handleNotifications: function (data) { |
|
27 | handleNotifications: function (data) { | |
28 | this.$['notifications'].handleNotification(data); |
|
28 | this.$['notifications'].handleNotification(data); | |
29 | }, |
|
29 | }, | |
30 |
|
30 | |||
31 | faviconUpdate: function (data) { |
|
31 | faviconUpdate: function (data) { | |
32 | this.$$('rhodecode-favicon').counter = data.count; |
|
32 | this.$$('rhodecode-favicon').counter = data.count; | |
33 | }, |
|
33 | }, | |
34 |
|
34 | |||
35 | /** opens connection to ws server */ |
|
35 | /** opens connection to ws server */ | |
36 | kickoffChannelstreamPlugin: function (data) { |
|
36 | kickoffChannelstreamPlugin: function (data) { | |
37 | ccLog.debug('kickoffChannelstreamPlugin'); |
|
37 | ccLog.debug('kickoffChannelstreamPlugin'); | |
38 | var channels = ['broadcast']; |
|
38 | var channels = ['broadcast']; | |
39 | var addChannels = this.checkViewChannels(); |
|
39 | var addChannels = this.checkViewChannels(); | |
40 | for (var i = 0; i < addChannels.length; i++) { |
|
40 | for (var i = 0; i < addChannels.length; i++) { | |
41 | channels.push(addChannels[i]); |
|
41 | channels.push(addChannels[i]); | |
42 | } |
|
42 | } | |
43 | if (window.CHANNELSTREAM_SETTINGS && CHANNELSTREAM_SETTINGS.enabled){ |
|
43 | if (window.CHANNELSTREAM_SETTINGS && CHANNELSTREAM_SETTINGS.enabled){ | |
44 | var channelstreamConnection = this.getChannelStreamConnection(); |
|
44 | var channelstreamConnection = this.getChannelStreamConnection(); | |
45 | channelstreamConnection.connectUrl = CHANNELSTREAM_URLS.connect; |
|
45 | channelstreamConnection.connectUrl = CHANNELSTREAM_URLS.connect; | |
46 | channelstreamConnection.subscribeUrl = CHANNELSTREAM_URLS.subscribe; |
|
46 | channelstreamConnection.subscribeUrl = CHANNELSTREAM_URLS.subscribe; | |
47 | channelstreamConnection.websocketUrl = CHANNELSTREAM_URLS.ws + '/ws'; |
|
47 | channelstreamConnection.websocketUrl = CHANNELSTREAM_URLS.ws + '/ws'; | |
48 | channelstreamConnection.longPollUrl = CHANNELSTREAM_URLS.longpoll + '/listen'; |
|
48 | channelstreamConnection.longPollUrl = CHANNELSTREAM_URLS.longpoll + '/listen'; | |
49 | // some channels might already be registered by topic |
|
49 | // some channels might already be registered by topic | |
50 | for (var i = 0; i < channels.length; i++) { |
|
50 | for (var i = 0; i < channels.length; i++) { | |
51 | channelstreamConnection.push('channels', channels[i]); |
|
51 | channelstreamConnection.push('channels', channels[i]); | |
52 | } |
|
52 | } | |
53 | // append any additional channels registered in other plugins |
|
53 | // append any additional channels registered in other plugins | |
54 | $.Topic('/connection_controller/subscribe').processPrepared(); |
|
54 | $.Topic('/connection_controller/subscribe').processPrepared(); | |
55 | channelstreamConnection.connect(); |
|
55 | channelstreamConnection.connect(); | |
56 | } |
|
56 | } | |
57 | }, |
|
57 | }, | |
58 |
|
58 | |||
59 | checkViewChannels: function () { |
|
59 | checkViewChannels: function () { | |
60 | var channels = [] |
|
60 | var channels = [] | |
61 | // subscribe to PR repo channel for PR's' |
|
61 | // subscribe to PR repo channel for PR's' | |
62 | if (templateContext.pull_request_data.pull_request_id) { |
|
62 | if (templateContext.pull_request_data.pull_request_id) { | |
63 | var channelName = '/repo$' + templateContext.repo_name + '$/pr/' + |
|
63 | var channelName = '/repo$' + templateContext.repo_name + '$/pr/' + | |
64 | String(templateContext.pull_request_data.pull_request_id); |
|
64 | String(templateContext.pull_request_data.pull_request_id); | |
65 | channels.push(channelName); |
|
65 | channels.push(channelName); | |
66 | } |
|
66 | } | |
67 | return channels; |
|
67 | return channels; | |
68 | }, |
|
68 | }, | |
69 |
|
69 | |||
70 | /** subscribes users from channels in channelstream */ |
|
70 | /** subscribes users from channels in channelstream */ | |
71 | subscribeToChannelTopic: function (channels) { |
|
71 | subscribeToChannelTopic: function (channels) { | |
72 |
var channelstreamConnection = this. |
|
72 | var channelstreamConnection = this.getChannelStreamConnection(); | |
73 | var toSubscribe = channelstreamConnection.calculateSubscribe(channels); |
|
73 | var toSubscribe = channelstreamConnection.calculateSubscribe(channels); | |
74 | ccLog.debug('subscribeToChannelTopic', toSubscribe); |
|
74 | ccLog.debug('subscribeToChannelTopic', toSubscribe); | |
75 | if (toSubscribe.length > 0) { |
|
75 | if (toSubscribe.length > 0) { | |
76 | // if we are connected then subscribe |
|
76 | // if we are connected then subscribe | |
77 | if (channelstreamConnection.connected) { |
|
77 | if (channelstreamConnection.connected) { | |
78 | channelstreamConnection.subscribe(toSubscribe); |
|
78 | channelstreamConnection.subscribe(toSubscribe); | |
79 | } |
|
79 | } | |
80 | // not connected? just push channels onto the stack |
|
80 | // not connected? just push channels onto the stack | |
81 | else { |
|
81 | else { | |
82 | for (var i = 0; i < toSubscribe.length; i++) { |
|
82 | for (var i = 0; i < toSubscribe.length; i++) { | |
83 | channelstreamConnection.push('channels', toSubscribe[i]); |
|
83 | channelstreamConnection.push('channels', toSubscribe[i]); | |
84 | } |
|
84 | } | |
85 | } |
|
85 | } | |
86 | } |
|
86 | } | |
87 | }, |
|
87 | }, | |
88 |
|
88 | |||
89 | /** publish received messages into correct topic */ |
|
89 | /** publish received messages into correct topic */ | |
90 | receivedMessage: function (event) { |
|
90 | receivedMessage: function (event) { | |
91 | for (var i = 0; i < event.detail.length; i++) { |
|
91 | for (var i = 0; i < event.detail.length; i++) { | |
92 | var message = event.detail[i]; |
|
92 | var message = event.detail[i]; | |
93 | if (message.message.topic) { |
|
93 | if (message.message.topic) { | |
94 | ccLog.debug('publishing', message.message.topic); |
|
94 | ccLog.debug('publishing', message.message.topic); | |
95 | $.Topic(message.message.topic).publish(message); |
|
95 | $.Topic(message.message.topic).publish(message); | |
96 | } |
|
96 | } | |
97 | else if (message.type === 'presence'){ |
|
97 | else if (message.type === 'presence'){ | |
98 | $.Topic('/connection_controller/presence').publish(message); |
|
98 | $.Topic('/connection_controller/presence').publish(message); | |
99 | } |
|
99 | } | |
100 | else { |
|
100 | else { | |
101 | ccLog.warn('unhandled message', message); |
|
101 | ccLog.warn('unhandled message', message); | |
102 | } |
|
102 | } | |
103 | } |
|
103 | } | |
104 | }, |
|
104 | }, | |
105 |
|
105 | |||
106 | handleConnected: function (event) { |
|
106 | handleConnected: function (event) { | |
107 |
var channelstreamConnection = this. |
|
107 | var channelstreamConnection = this.getChannelStreamConnection(); | |
108 | channelstreamConnection.set('channelsState', |
|
108 | channelstreamConnection.set('channelsState', | |
109 | event.detail.channels_info); |
|
109 | event.detail.channels_info); | |
110 | channelstreamConnection.set('userState', event.detail.state); |
|
110 | channelstreamConnection.set('userState', event.detail.state); | |
111 | channelstreamConnection.set('channels', event.detail.channels); |
|
111 | channelstreamConnection.set('channels', event.detail.channels); | |
112 | this.propagageChannelsState(); |
|
112 | this.propagageChannelsState(); | |
113 | }, |
|
113 | }, | |
114 | handleSubscribed: function (event) { |
|
114 | handleSubscribed: function (event) { | |
115 |
var channelstreamConnection = this. |
|
115 | var channelstreamConnection = this.getChannelStreamConnection(); | |
116 | var channelInfo = event.detail.channels_info; |
|
116 | var channelInfo = event.detail.channels_info; | |
117 | var channelKeys = Object.keys(event.detail.channels_info); |
|
117 | var channelKeys = Object.keys(event.detail.channels_info); | |
118 | for (var i = 0; i < channelKeys.length; i++) { |
|
118 | for (var i = 0; i < channelKeys.length; i++) { | |
119 | var key = channelKeys[i]; |
|
119 | var key = channelKeys[i]; | |
120 | channelstreamConnection.set(['channelsState', key], channelInfo[key]); |
|
120 | channelstreamConnection.set(['channelsState', key], channelInfo[key]); | |
121 | } |
|
121 | } | |
122 | channelstreamConnection.set('channels', event.detail.channels); |
|
122 | channelstreamConnection.set('channels', event.detail.channels); | |
123 | this.propagageChannelsState(); |
|
123 | this.propagageChannelsState(); | |
124 | }, |
|
124 | }, | |
125 | /** propagates channel states on topics */ |
|
125 | /** propagates channel states on topics */ | |
126 | propagageChannelsState: function (event) { |
|
126 | propagageChannelsState: function (event) { | |
127 |
var channelstreamConnection = this. |
|
127 | var channelstreamConnection = this.getChannelStreamConnection(); | |
128 | var channel_data = channelstreamConnection.channelsState; |
|
128 | var channel_data = channelstreamConnection.channelsState; | |
129 | var channels = channelstreamConnection.channels; |
|
129 | var channels = channelstreamConnection.channels; | |
130 | for (var i = 0; i < channels.length; i++) { |
|
130 | for (var i = 0; i < channels.length; i++) { | |
131 | var key = channels[i]; |
|
131 | var key = channels[i]; | |
132 | $.Topic('/connection_controller/channel_update').publish( |
|
132 | $.Topic('/connection_controller/channel_update').publish( | |
133 | {channel: key, state: channel_data[key]} |
|
133 | {channel: key, state: channel_data[key]} | |
134 | ); |
|
134 | ); | |
135 | } |
|
135 | } | |
136 | } |
|
136 | } | |
137 | }); |
|
137 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now