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