redmineup 1.1.10 → 1.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/assets/javascripts/consumer.js +37 -60
- data/app/assets/javascripts/consumer_worker.js +199 -0
- data/config/routes.rb +2 -0
- data/doc/CHANGELOG +4 -0
- data/lib/action_cable/connection/rup_connection.rb +17 -0
- data/lib/action_cable/server/rup_server.rb +4 -0
- data/lib/redmineup/helpers/external_assets_helper.rb +4 -3
- data/lib/redmineup/patches/action_cable_base_patch.rb +9 -2
- data/lib/redmineup/patches/action_cable_patch.rb +2 -4
- data/lib/redmineup/version.rb +1 -1
- data/lib/redmineup.rb +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ecb516fc8ae25a65558bec625b9603e7aacd7188d473e80b23eb27223050d2ac
|
|
4
|
+
data.tar.gz: 66e4cecc1aa21ab23211e51774fbd262840f5df3efdbb9bb355d20870d142909
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 43bddd0b96c58e00fc4645476801b1792022bce7c13588dc99f00486f77f47031e0fce58a4b5fe41d11b3dfca899527d003f294e1030957662141042e96e6a71
|
|
7
|
+
data.tar.gz: 4164a606ad2a264bb4501d3ec773215b5396b7da7dcdbc58bb09adadae630875d14dc9bdf4d669749b391ce19ff620df38c204d6474f2785f465d1e7b461a0b7
|
|
@@ -1,76 +1,53 @@
|
|
|
1
1
|
class activeCableConsumer {
|
|
2
|
-
OPEN = 1;
|
|
3
|
-
|
|
4
2
|
constructor(consumer) {
|
|
5
3
|
this.consumer = consumer;
|
|
6
|
-
this.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
this.
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
this.uuid = crypto.randomUUID();
|
|
5
|
+
this._connected = false;
|
|
6
|
+
|
|
7
|
+
const worker = new SharedWorker(
|
|
8
|
+
consumer.workerUrl || window.redmineupWorkerUrl,
|
|
9
|
+
);
|
|
10
|
+
this._port = worker.port;
|
|
11
|
+
|
|
12
|
+
this._port.onmessage = (e) => {
|
|
13
|
+
const { type, data } = e.data;
|
|
14
|
+
if (type === "connected") {
|
|
15
|
+
this._connected = true;
|
|
16
|
+
} else if (type === "disconnected") {
|
|
17
|
+
this._connected = false;
|
|
18
|
+
} else if (type === "message") {
|
|
19
|
+
this.processMessage(data);
|
|
20
|
+
}
|
|
21
|
+
this._port.postMessage({ type: "ack" });
|
|
22
|
+
};
|
|
15
23
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
24
|
+
this._port.start();
|
|
25
|
+
|
|
26
|
+
this._port.postMessage({
|
|
27
|
+
type: "connect",
|
|
28
|
+
uuid: this.uuid,
|
|
29
|
+
data: {
|
|
30
|
+
url: consumer.url,
|
|
31
|
+
channel: consumer.channel,
|
|
32
|
+
chatId: consumer.chatId,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
21
35
|
}
|
|
22
36
|
|
|
23
37
|
processMessage(message) {
|
|
24
38
|
this.consumer.process(message);
|
|
25
39
|
}
|
|
26
40
|
|
|
27
|
-
send(data) {
|
|
28
|
-
if (this.isOpen()) {
|
|
29
|
-
this.socket.send(JSON.stringify(data));
|
|
30
|
-
return true;
|
|
31
|
-
} else {
|
|
32
|
-
console.warn("WebSocket is not open");
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
41
|
isOpen() {
|
|
38
|
-
return this.
|
|
42
|
+
return this._connected;
|
|
39
43
|
}
|
|
40
44
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const message = {
|
|
46
|
-
command: "subscribe",
|
|
47
|
-
identifier: JSON.stringify({
|
|
48
|
-
channel: consumer.channel,
|
|
49
|
-
chat_id: consumer.chatId,
|
|
50
|
-
}),
|
|
51
|
-
};
|
|
52
|
-
socket.send(JSON.stringify(message));
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
socket.onclose = function () {
|
|
56
|
-
self.reconnect();
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
socket.onmessage = function (event) {
|
|
60
|
-
const messageData = (event.data && JSON.parse(event.data)) || {};
|
|
61
|
-
if (messageData.type === "ping" || !messageData.message) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
const message = messageData.message;
|
|
65
|
-
|
|
66
|
-
self.processMessage(message);
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
socket.onerror = function (error) {
|
|
70
|
-
console.log(error);
|
|
71
|
-
self.reconnect();
|
|
72
|
-
};
|
|
45
|
+
send(data) {
|
|
46
|
+
this._port.postMessage({ type: "send", data });
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
73
49
|
|
|
74
|
-
|
|
50
|
+
disconnect() {
|
|
51
|
+
this._port.postMessage({ type: "disconnect" });
|
|
75
52
|
}
|
|
76
53
|
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
const connections = new Map();
|
|
2
|
+
const MAX_PENDING_ACK = 3;
|
|
3
|
+
|
|
4
|
+
self.onconnect = function (event) {
|
|
5
|
+
const clientPort = event.ports[0];
|
|
6
|
+
let clientUrl = null;
|
|
7
|
+
let clientUuid = null;
|
|
8
|
+
let channelIdentifier = null;
|
|
9
|
+
|
|
10
|
+
clientPort.onmessage = function (e) {
|
|
11
|
+
const { type, uuid, data } = e.data;
|
|
12
|
+
|
|
13
|
+
switch (type) {
|
|
14
|
+
case "connect": {
|
|
15
|
+
clientUuid = uuid;
|
|
16
|
+
clientUrl = data.url;
|
|
17
|
+
channelIdentifier = JSON.stringify({
|
|
18
|
+
channel: data.channel,
|
|
19
|
+
...(data.chatId !== undefined && { chat_id: data.chatId }),
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
if (!connections.has(clientUrl)) {
|
|
23
|
+
connections.set(clientUrl, initSocketStruct());
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const conn = connections.get(clientUrl);
|
|
27
|
+
const alreadySubscribed = hasChannelSubscribers(
|
|
28
|
+
conn,
|
|
29
|
+
channelIdentifier,
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
conn.clients.set(clientUuid, {
|
|
33
|
+
port: clientPort,
|
|
34
|
+
channelIdentifier,
|
|
35
|
+
pendingAck: 0,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
if (!conn.socket || conn.socket.readyState > WebSocket.OPEN) {
|
|
39
|
+
initWebSocket(clientUrl);
|
|
40
|
+
} else if (
|
|
41
|
+
conn.socket.readyState === WebSocket.OPEN &&
|
|
42
|
+
!alreadySubscribed
|
|
43
|
+
) {
|
|
44
|
+
sendSubscribe(conn.socket, channelIdentifier);
|
|
45
|
+
}
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
case "send": {
|
|
50
|
+
if (clientUrl) {
|
|
51
|
+
const conn = connections.get(clientUrl);
|
|
52
|
+
if (
|
|
53
|
+
conn &&
|
|
54
|
+
conn.socket &&
|
|
55
|
+
conn.socket.readyState === WebSocket.OPEN
|
|
56
|
+
) {
|
|
57
|
+
conn.socket.send(JSON.stringify(data));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
case "ack": {
|
|
64
|
+
if (clientUuid && clientUrl) {
|
|
65
|
+
const conn = connections.get(clientUrl);
|
|
66
|
+
if (conn) {
|
|
67
|
+
const client = conn.clients.get(clientUuid);
|
|
68
|
+
if (client) client.pendingAck = 0;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
case "disconnect": {
|
|
75
|
+
if (clientUuid && clientUrl) {
|
|
76
|
+
const conn = connections.get(clientUrl);
|
|
77
|
+
if (conn) {
|
|
78
|
+
conn.clients.delete(clientUuid);
|
|
79
|
+
const stillSubscribed = hasChannelSubscribers(
|
|
80
|
+
conn,
|
|
81
|
+
channelIdentifier,
|
|
82
|
+
);
|
|
83
|
+
if (
|
|
84
|
+
!stillSubscribed &&
|
|
85
|
+
conn.socket &&
|
|
86
|
+
conn.socket.readyState === WebSocket.OPEN
|
|
87
|
+
) {
|
|
88
|
+
conn.socket.send(
|
|
89
|
+
JSON.stringify({
|
|
90
|
+
command: "unsubscribe",
|
|
91
|
+
identifier: channelIdentifier,
|
|
92
|
+
}),
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
if (conn.clients.size === 0) {
|
|
96
|
+
if (conn.socket) conn.socket.close();
|
|
97
|
+
connections.delete(clientUrl);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
clientUuid = null;
|
|
101
|
+
clientUrl = null;
|
|
102
|
+
channelIdentifier = null;
|
|
103
|
+
}
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
clientPort.start();
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
function sendSubscribe(socket, identifier) {
|
|
113
|
+
socket.send(JSON.stringify({ command: "subscribe", identifier }));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function initSocketStruct() {
|
|
117
|
+
return { socket: null, clients: new Map() };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function initWebSocket(url) {
|
|
121
|
+
const conn = connections.get(url);
|
|
122
|
+
if (!conn) return;
|
|
123
|
+
|
|
124
|
+
conn.socket = new WebSocket(url);
|
|
125
|
+
|
|
126
|
+
conn.socket.onopen = function () {
|
|
127
|
+
const seen = new Set();
|
|
128
|
+
for (const { channelIdentifier } of conn.clients.values()) {
|
|
129
|
+
if (!seen.has(channelIdentifier)) {
|
|
130
|
+
seen.add(channelIdentifier);
|
|
131
|
+
sendSubscribe(conn.socket, channelIdentifier);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
conn.socket.onmessage = function (event) {
|
|
137
|
+
const messageData = (event.data && JSON.parse(event.data)) || {};
|
|
138
|
+
|
|
139
|
+
if (messageData.type === "confirm_subscription") {
|
|
140
|
+
routeToIdentifier(conn, messageData.identifier, { type: "connected" });
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (messageData.type === "reject_subscription") {
|
|
145
|
+
routeToIdentifier(conn, messageData.identifier, { type: "rejected" });
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (messageData.type === "ping" || !messageData.message) return;
|
|
150
|
+
|
|
151
|
+
routeToIdentifier(conn, messageData.identifier, {
|
|
152
|
+
type: "message",
|
|
153
|
+
data: messageData.message,
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
conn.socket.onclose = function () {
|
|
158
|
+
broadcastTo(conn, { type: "disconnected" });
|
|
159
|
+
setTimeout(function () {
|
|
160
|
+
if (connections.has(url)) initWebSocket(url);
|
|
161
|
+
}, 5000);
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
conn.socket.onerror = function (error) {
|
|
165
|
+
conn.socket.close();
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function hasChannelSubscribers(conn, channelIdentifier) {
|
|
170
|
+
for (const client of conn.clients.values()) {
|
|
171
|
+
if (client.channelIdentifier === channelIdentifier) return true;
|
|
172
|
+
}
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function routeToIdentifier(conn, identifier, message) {
|
|
177
|
+
console.log("routeToIdentifier:", identifier, message);
|
|
178
|
+
for (const [key, client] of conn.clients) {
|
|
179
|
+
if (client.channelIdentifier === identifier) {
|
|
180
|
+
if (client.pendingAck >= MAX_PENDING_ACK) {
|
|
181
|
+
conn.clients.delete(key);
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
client.pendingAck++;
|
|
185
|
+
client.port.postMessage(message);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function broadcastTo(conn, message) {
|
|
191
|
+
for (const [key, client] of conn.clients) {
|
|
192
|
+
if (client.pendingAck >= MAX_PENDING_ACK) {
|
|
193
|
+
conn.clients.delete(key);
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
client.pendingAck++;
|
|
197
|
+
client.port.postMessage(message);
|
|
198
|
+
}
|
|
199
|
+
}
|
data/config/routes.rb
CHANGED
|
@@ -4,4 +4,6 @@ Rails.application.routes.draw do
|
|
|
4
4
|
match 'redmineup/settings/:id', to: 'redmineup#settings', as: 'redmineup_settings', via: [:get, :post]
|
|
5
5
|
match 'auto_completes/taggable_tags' => 'auto_completes#taggable_tags',
|
|
6
6
|
via: :get, as: 'auto_complete_taggable_tags'
|
|
7
|
+
|
|
8
|
+
mount ActionCable.rup_server => '/rup_cable', as: 'rup_cable' if Redmineup.cable_available?
|
|
7
9
|
end
|
data/doc/CHANGELOG
CHANGED
|
@@ -4,6 +4,10 @@ Redmine UP gem - general functions for plugins (tags, vote, viewing, currency)
|
|
|
4
4
|
Copyright (C) 2011-2026 Kirill Bezrukov (RedmineUP)
|
|
5
5
|
https://www.redmineup.com/
|
|
6
6
|
|
|
7
|
+
== 2026-06-26 v1.1.11
|
|
8
|
+
|
|
9
|
+
* Added shared workers for websocket connection
|
|
10
|
+
|
|
7
11
|
== 2026-06-04 v1.1.10
|
|
8
12
|
|
|
9
13
|
* Added colorpicker JS component to shared gem assets, loaded globally via `redmineup_assets`
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module ActionCable
|
|
2
|
+
module Connection
|
|
3
|
+
class RupConnection < ActionCable::Connection::Base
|
|
4
|
+
identified_by :current_user
|
|
5
|
+
|
|
6
|
+
def connect
|
|
7
|
+
self.current_user = find_verified_user
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
private
|
|
11
|
+
|
|
12
|
+
def find_verified_user
|
|
13
|
+
User.find_by(id: @request.session[:user_id]) || User.anonymous
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -4,13 +4,14 @@ module Redmineup
|
|
|
4
4
|
|
|
5
5
|
def redmineup_assets
|
|
6
6
|
return if @redmineup_assets_included
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
@redmineup_assets_included = true
|
|
9
9
|
javascript_include_tag('consumer', plugin: GEM_NAME) +
|
|
10
10
|
javascript_include_tag('select2', plugin: GEM_NAME) +
|
|
11
11
|
javascript_include_tag('select2_helpers', plugin: GEM_NAME) +
|
|
12
12
|
javascript_include_tag('jquery.colorPicker.min', plugin: GEM_NAME) +
|
|
13
|
-
stylesheet_link_tag('redmineup', plugin: GEM_NAME)
|
|
13
|
+
stylesheet_link_tag('redmineup', plugin: GEM_NAME) +
|
|
14
|
+
javascript_tag("window.redmineupWorkerUrl = #{asset_path('consumer_worker.js', plugin: GEM_NAME).to_json};")
|
|
14
15
|
end
|
|
15
16
|
|
|
16
17
|
def select2_assets
|
|
@@ -19,9 +20,9 @@ module Redmineup
|
|
|
19
20
|
|
|
20
21
|
def chartjs_assets
|
|
21
22
|
return if @chartjs_tag_included
|
|
23
|
+
|
|
22
24
|
@chartjs_tag_included = true
|
|
23
25
|
javascript_include_tag('chart.min', plugin: GEM_NAME)
|
|
24
26
|
end
|
|
25
|
-
|
|
26
27
|
end
|
|
27
28
|
end
|
|
@@ -7,8 +7,15 @@ module Redmineup
|
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
module ClassMethods
|
|
10
|
-
def rup_broadcast_to(
|
|
11
|
-
|
|
10
|
+
def rup_broadcast_to(*args)
|
|
11
|
+
# TODO: Remove to 2 args after plugins update
|
|
12
|
+
if args.length == 3
|
|
13
|
+
klass, model, message = args
|
|
14
|
+
ActionCable.rup_server(klass).broadcast(broadcasting_for(model), message)
|
|
15
|
+
else
|
|
16
|
+
model, message = args
|
|
17
|
+
ActionCable.rup_server.broadcast(broadcasting_for(model), message)
|
|
18
|
+
end
|
|
12
19
|
end
|
|
13
20
|
end
|
|
14
21
|
end
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
module Redmineup
|
|
2
2
|
module Patches
|
|
3
3
|
module ActionCablePatch
|
|
4
|
-
|
|
5
4
|
def self.included(base)
|
|
6
5
|
base.class_eval do
|
|
7
|
-
module_function def rup_server(klass =
|
|
6
|
+
module_function def rup_server(klass = 'ActionCable::Connection::RupConnection')
|
|
8
7
|
@rup_servers ||= {}
|
|
9
8
|
return @rup_servers[klass] if @rup_servers[klass]
|
|
10
9
|
|
|
@@ -14,10 +13,9 @@ module Redmineup
|
|
|
14
13
|
end
|
|
15
14
|
end
|
|
16
15
|
end
|
|
17
|
-
|
|
18
16
|
end
|
|
19
17
|
end
|
|
20
18
|
|
|
21
19
|
unless ActionCable.included_modules.include?(Redmineup::Patches::ActionCablePatch)
|
|
22
|
-
ActionCable.
|
|
20
|
+
ActionCable.include Redmineup::Patches::ActionCablePatch
|
|
23
21
|
end
|
data/lib/redmineup/version.rb
CHANGED
data/lib/redmineup.rb
CHANGED
|
@@ -66,6 +66,7 @@ require 'application_record' if !defined?(ApplicationRecord) && Rails.version <
|
|
|
66
66
|
if Redmineup.cable_available?
|
|
67
67
|
require 'action_cable/server/rup_configuration'
|
|
68
68
|
require 'action_cable/server/rup_server'
|
|
69
|
+
require 'action_cable/connection/rup_connection'
|
|
69
70
|
require 'redmineup/patches/action_cable_base_patch'
|
|
70
71
|
require 'redmineup/patches/action_cable_patch'
|
|
71
72
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: redmineup
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.1.
|
|
4
|
+
version: 1.1.11
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- RedmineUP
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-06-
|
|
11
|
+
date: 2026-06-29 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|
|
@@ -119,6 +119,7 @@ files:
|
|
|
119
119
|
- app/assets/javascripts/Chart.bundle.min.js.bak
|
|
120
120
|
- app/assets/javascripts/chart.min.js
|
|
121
121
|
- app/assets/javascripts/consumer.js
|
|
122
|
+
- app/assets/javascripts/consumer_worker.js
|
|
122
123
|
- app/assets/javascripts/jquery.colorPicker.min.js
|
|
123
124
|
- app/assets/javascripts/select2.js
|
|
124
125
|
- app/assets/javascripts/select2_helpers.js
|
|
@@ -142,6 +143,7 @@ files:
|
|
|
142
143
|
- doc/active-record-mixins.md
|
|
143
144
|
- doc/assets-money-and-utilities.md
|
|
144
145
|
- doc/tagging-and-select2.md
|
|
146
|
+
- lib/action_cable/connection/rup_connection.rb
|
|
145
147
|
- lib/action_cable/server/rup_configuration.rb
|
|
146
148
|
- lib/action_cable/server/rup_server.rb
|
|
147
149
|
- lib/application_record.rb
|