@arsedizioni/ars-utils 20.3.45 → 20.3.47

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.
@@ -2028,9 +2028,93 @@ class SelectableModel {
2028
2028
  }
2029
2029
  }
2030
2030
 
2031
+ /**
2032
+ * Standard Broadcast Messages Manager
2033
+ * https://developer.mozilla.org/en-US/docs/Web/API/BroadcastChannel
2034
+ */
2035
+ /**
2036
+ * Web Standard Broadcast Messages Manager
2037
+ * https://developer.mozilla.org/en-US/docs/Web/API/BroadcastChannel
2038
+ */
2039
+ class BroadcastChannelManager {
2040
+ /**
2041
+ * Get the current channel registration
2042
+ */
2043
+ get currentBus() {
2044
+ return this.channel?.name;
2045
+ }
2046
+ constructor(bus) {
2047
+ this.subscriptions = [];
2048
+ this.channel = new BroadcastChannel(bus);
2049
+ this.channel.onmessageerror = (e) => {
2050
+ console.error('[BroadcastChannelManager] Errore di ricezione del messaggio', e);
2051
+ };
2052
+ this.channel.onmessage = (e) => {
2053
+ const bag = e.data;
2054
+ if (bag) {
2055
+ const bagInfo = this.subscriptions.find(m => m.messageId === bag.messageId);
2056
+ bagInfo?.action(bag);
2057
+ }
2058
+ };
2059
+ }
2060
+ dispose() {
2061
+ setTimeout(() => {
2062
+ this.subscriptions = [];
2063
+ this.channel?.close();
2064
+ this.channel = undefined;
2065
+ }, 1000);
2066
+ }
2067
+ /**
2068
+ * overloads
2069
+ */
2070
+ sendMessage(messageIdorBag, dataOrDelay, delay) {
2071
+ setTimeout(() => {
2072
+ if (typeof messageIdorBag === 'string') {
2073
+ this.channel?.postMessage({ messageId: messageIdorBag, data: dataOrDelay });
2074
+ }
2075
+ else {
2076
+ this.channel?.postMessage(messageIdorBag);
2077
+ }
2078
+ }, (typeof dataOrDelay === 'number' ? dataOrDelay : delay) ?? 0);
2079
+ }
2080
+ /**
2081
+ * Subscribe to a message
2082
+ * @param args The subscription info, see also {@link BroadcastChannelSubscriberInfo}
2083
+ */
2084
+ subscribe(args) {
2085
+ const i = this.subscriptions.findIndex(m => m.messageId === args.messageId);
2086
+ if (i === -1) {
2087
+ this.subscriptions.push(args);
2088
+ }
2089
+ else {
2090
+ this.subscriptions[i].action = args.action;
2091
+ }
2092
+ }
2093
+ /**
2094
+ * Remove a message subscription
2095
+ * @param messageId The message id
2096
+ */
2097
+ unsubscribe(messageId) {
2098
+ const i = this.subscriptions.findIndex(m => m.messageId === messageId);
2099
+ if (i !== -1) {
2100
+ this.subscriptions.splice(i, 1);
2101
+ }
2102
+ }
2103
+ /**
2104
+ * Remove all the current subscriptions
2105
+ */
2106
+ unsubscribeAll() {
2107
+ this.subscriptions = [];
2108
+ }
2109
+ }
2110
+
2031
2111
  class BroadcastService {
2032
2112
  constructor() {
2033
2113
  this.subject = new Subject();
2114
+ this.channel = new BroadcastChannelManager("ARS-CHANNEL");
2115
+ }
2116
+ ngOnDestroy() {
2117
+ this.channel?.dispose();
2034
2118
  }
2035
2119
  /**
2036
2120
  * Send a message
@@ -2038,11 +2122,29 @@ class BroadcastService {
2038
2122
  * @param data : the data to send
2039
2123
  * @param delay : the number of milliseconds to wait before sending the message
2040
2124
  */
2041
- sendMessage(id, data = null, delay = 0) {
2125
+ sendMessage(id, data = undefined, delay = 0) {
2042
2126
  setTimeout(() => {
2043
2127
  this.subject.next({ id: id, data: data });
2044
2128
  }, delay);
2045
2129
  }
2130
+ /**
2131
+ * Send a channel message
2132
+ * @param bag : the message bag
2133
+ * @param delay : the number of milliseconds to wait before sending the message
2134
+ */
2135
+ sendChannelMessage(bag, delay) {
2136
+ setTimeout(() => {
2137
+ this.channel.sendMessage(bag, delay);
2138
+ }, delay);
2139
+ }
2140
+ /**
2141
+ * Subscribe channel message
2142
+ * @param messageId : the message id
2143
+ * @param action : the actionto perform
2144
+ */
2145
+ subscribeChannelMessage(messageId, action) {
2146
+ this.channel.subscribe({ messageId: messageId, action: action });
2147
+ }
2046
2148
  /**
2047
2149
  * Get the next message as observable
2048
2150
  * @returns : the observable object
@@ -2121,84 +2223,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.1", ngImpor
2121
2223
  }]
2122
2224
  }] });
2123
2225
 
2124
- /**
2125
- * Standard Broadcast Messages Manager
2126
- * https://developer.mozilla.org/en-US/docs/Web/API/BroadcastChannel
2127
- */
2128
- /**
2129
- * Web Standard Broadcast Messages Manager
2130
- * https://developer.mozilla.org/en-US/docs/Web/API/BroadcastChannel
2131
- */
2132
- class BroadcastChannelManager {
2133
- /**
2134
- * Get the current channel registration
2135
- */
2136
- get currentBus() {
2137
- return this.channel?.name;
2138
- }
2139
- constructor(bus) {
2140
- this.subscriptions = [];
2141
- this.channel = new BroadcastChannel(bus);
2142
- this.channel.onmessageerror = (e) => {
2143
- console.error('[BroadcastChannelManager] Errore di ricezione del messaggio', e);
2144
- };
2145
- this.channel.onmessage = (e) => {
2146
- const bag = e.data;
2147
- if (bag) {
2148
- const bagInfo = this.subscriptions.find(m => m.messageId === bag.messageId);
2149
- bagInfo?.action(bag);
2150
- }
2151
- };
2152
- }
2153
- dispose() {
2154
- this.subscriptions = [];
2155
- this.channel?.close();
2156
- this.channel = undefined;
2157
- }
2158
- /**
2159
- * overloads
2160
- */
2161
- sendMessage(messageIdorBag, dataOrDelay, delay) {
2162
- setTimeout(() => {
2163
- if (typeof messageIdorBag === 'string') {
2164
- this.channel?.postMessage({ messageId: messageIdorBag, data: dataOrDelay });
2165
- }
2166
- else {
2167
- this.channel?.postMessage(messageIdorBag);
2168
- }
2169
- }, (typeof dataOrDelay === 'number' ? dataOrDelay : delay) ?? 0);
2170
- }
2171
- /**
2172
- * Subscribe to a message
2173
- * @param args The subscription info, see also {@link BroadcastChannelSubscriberInfo}
2174
- */
2175
- subscribe(args) {
2176
- const i = this.subscriptions.findIndex(m => m.messageId === args.messageId);
2177
- if (i === -1) {
2178
- this.subscriptions.push(args);
2179
- }
2180
- else {
2181
- this.subscriptions[i].action = args.action;
2182
- }
2183
- }
2184
- /**
2185
- * Remove a message subscription
2186
- * @param messageId The message id
2187
- */
2188
- unsubscribe(messageId) {
2189
- const i = this.subscriptions.findIndex(m => m.messageId === messageId);
2190
- if (i !== -1) {
2191
- this.subscriptions.splice(i, 1);
2192
- }
2193
- }
2194
- /**
2195
- * Remove all the current subscriptions
2196
- */
2197
- unsubscribeAll() {
2198
- this.subscriptions = [];
2199
- }
2200
- }
2201
-
2202
2226
  class ThemeService {
2203
2227
  constructor() {
2204
2228
  // messaggi broadcast