saasufy-components 3.20.0 → 3.21.0
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.
- package/README.md +1 -0
- package/package.json +1 -1
- package/socket.js +15 -0
package/README.md
CHANGED
|
@@ -207,6 +207,7 @@ A Saasufy component which integrates with data from Saasufy is known as a `socke
|
|
|
207
207
|
|
|
208
208
|
- `url` (required): Specifies the URL for the Saasufy service to use as the data store for all components which are placed inside it.
|
|
209
209
|
- `auth-token-name`: Allows you to specify a custom key for your token - This will be used as the key in localStorage. You generally do not need to set this attribute. It is intended for situations were an app has multiple `socket-provider` elements connecting different services with different/separate authentication flows.
|
|
210
|
+
- `disable-tab-sync`: By default, the socket provider synchronizes socket auth state across multiple tabs via localStorage. If this attribute is set, then the socket auth state will not sync automatically and a manual page refresh may be necessary to update to the latest auth state.
|
|
210
211
|
|
|
211
212
|
### collection-browser
|
|
212
213
|
|
package/package.json
CHANGED
package/socket.js
CHANGED
|
@@ -26,9 +26,24 @@ export class SocketProvider extends HTMLElement {
|
|
|
26
26
|
connectedCallback() {
|
|
27
27
|
this.isReady = true;
|
|
28
28
|
this.getSocket();
|
|
29
|
+
let disableTabSync = this.hasAttribute('disable-tab-sync');
|
|
30
|
+
if (!disableTabSync) {
|
|
31
|
+
if (this.storageChangeWatcher) {
|
|
32
|
+
window.removeEventListener('storage', this.storageChangeWatcher);
|
|
33
|
+
}
|
|
34
|
+
this.storageChangeWatcher = (event) => {
|
|
35
|
+
if (event.storageArea === window.localStorage && event.key === this.saasufySocket.options.authTokenName) {
|
|
36
|
+
this.saasufySocket.reconnect();
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
window.addEventListener('storage', this.storageChangeWatcher);
|
|
29
41
|
}
|
|
30
42
|
|
|
31
43
|
disconnectedCallback() {
|
|
44
|
+
if (this.storageChangeWatcher) {
|
|
45
|
+
window.removeEventListener('storage', this.storageChangeWatcher);
|
|
46
|
+
}
|
|
32
47
|
this.destroySocket();
|
|
33
48
|
}
|
|
34
49
|
|