saasufy-components 3.25.0 → 3.26.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 +2 -2
- package/socket.js +32 -17
package/README.md
CHANGED
|
@@ -250,6 +250,7 @@ A Saasufy component which integrates with data from Saasufy is known as a `socke
|
|
|
250
250
|
- `url` (required): Specifies the URL for the Saasufy service to use as the data store for all components which are placed inside it.
|
|
251
251
|
- `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.
|
|
252
252
|
- `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.
|
|
253
|
+
- `socket-options`: Can be used to set options on the inner `socket`. Must be in the format `option1:type1=value1,option2:type2=value2`; the type of each option can be string, boolean or number. If not specified, the default type is string.
|
|
253
254
|
|
|
254
255
|
### collection-browser
|
|
255
256
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "saasufy-components",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.26.0",
|
|
4
4
|
"description": "Components for Saasufy.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"ag-collection": "^5.1.0",
|
|
21
21
|
"ag-model": "^3.1.0",
|
|
22
22
|
"capitalisk-auth-client": "^1.5.1",
|
|
23
|
-
"socketcluster-client": "^19.1.
|
|
23
|
+
"socketcluster-client": "^19.1.1",
|
|
24
24
|
"uuid": "^8.3.2"
|
|
25
25
|
},
|
|
26
26
|
"bugs": {
|
package/socket.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { create } from '/node_modules/socketcluster-client/socketcluster-client.min.js';
|
|
2
|
+
import { convertStringToFieldParams } from './utils.js';
|
|
2
3
|
|
|
3
4
|
let globalSocket;
|
|
4
5
|
|
|
@@ -21,23 +22,12 @@ export class SocketProvider extends HTMLElement {
|
|
|
21
22
|
super();
|
|
22
23
|
this.saasufySocket = null;
|
|
23
24
|
this.isReady = false;
|
|
25
|
+
this.lastExtraSocketOptionsString = '';
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
connectedCallback() {
|
|
27
29
|
this.isReady = true;
|
|
28
30
|
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);
|
|
41
31
|
}
|
|
42
32
|
|
|
43
33
|
disconnectedCallback() {
|
|
@@ -50,7 +40,9 @@ export class SocketProvider extends HTMLElement {
|
|
|
50
40
|
static get observedAttributes() {
|
|
51
41
|
return [
|
|
52
42
|
'url',
|
|
53
|
-
'auth-token-name'
|
|
43
|
+
'auth-token-name',
|
|
44
|
+
'disable-tab-sync',
|
|
45
|
+
'socket-options'
|
|
54
46
|
];
|
|
55
47
|
}
|
|
56
48
|
|
|
@@ -72,6 +64,7 @@ export class SocketProvider extends HTMLElement {
|
|
|
72
64
|
|
|
73
65
|
getSocketOptions() {
|
|
74
66
|
let authTokenName = this.getAttribute('auth-token-name') || null;
|
|
67
|
+
let socketOptionsString = this.getAttribute('socket-options') || '';
|
|
75
68
|
let url = this.getSanitizedURL();
|
|
76
69
|
let urlOptions;
|
|
77
70
|
let matchedList = url.match(urlPartsRegExp);
|
|
@@ -92,18 +85,24 @@ export class SocketProvider extends HTMLElement {
|
|
|
92
85
|
}
|
|
93
86
|
urlOptions = {};
|
|
94
87
|
}
|
|
88
|
+
let {
|
|
89
|
+
fieldValues: extraSocketOptions
|
|
90
|
+
} = convertStringToFieldParams(socketOptionsString);
|
|
95
91
|
let socketOptions = {
|
|
96
92
|
authTokenName,
|
|
93
|
+
autoConnect: !!url,
|
|
94
|
+
...extraSocketOptions,
|
|
97
95
|
...urlOptions
|
|
98
96
|
};
|
|
99
|
-
socketOptions.autoConnect = !!url;
|
|
100
97
|
return socketOptions;
|
|
101
98
|
}
|
|
102
99
|
|
|
103
100
|
getSocket() {
|
|
101
|
+
let socket;
|
|
102
|
+
let socketOptionsString = this.getAttribute('socket-options') || '';
|
|
104
103
|
if (this.saasufySocket) {
|
|
105
104
|
let sanitizedURL = this.getSanitizedURL();
|
|
106
|
-
if (this.lastSaasufySocketURL !== sanitizedURL) {
|
|
105
|
+
if (this.lastSaasufySocketURL !== sanitizedURL || this.lastExtraSocketOptionsString !== socketOptionsString) {
|
|
107
106
|
this.saasufySocket.connect(
|
|
108
107
|
this.getSocketOptions()
|
|
109
108
|
);
|
|
@@ -111,15 +110,31 @@ export class SocketProvider extends HTMLElement {
|
|
|
111
110
|
this.saasufySocket.connect();
|
|
112
111
|
}
|
|
113
112
|
this.lastSaasufySocketURL = sanitizedURL;
|
|
114
|
-
|
|
113
|
+
this.lastExtraSocketOptionsString = socketOptionsString;
|
|
114
|
+
socket = this.saasufySocket;
|
|
115
|
+
} else {
|
|
116
|
+
socket = this.createSocket();
|
|
117
|
+
}
|
|
118
|
+
if (this.storageChangeWatcher) {
|
|
119
|
+
window.removeEventListener('storage', this.storageChangeWatcher);
|
|
115
120
|
}
|
|
116
|
-
|
|
121
|
+
let disableTabSync = this.hasAttribute('disable-tab-sync');
|
|
122
|
+
if (!disableTabSync) {
|
|
123
|
+
this.storageChangeWatcher = (event) => {
|
|
124
|
+
if (event.storageArea === window.localStorage && event.key === this.saasufySocket.options.authTokenName) {
|
|
125
|
+
this.saasufySocket.reconnect();
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
window.addEventListener('storage', this.storageChangeWatcher);
|
|
129
|
+
}
|
|
130
|
+
return socket;
|
|
117
131
|
}
|
|
118
132
|
|
|
119
133
|
createSocket() {
|
|
120
134
|
let socketOptions = this.getSocketOptions();
|
|
121
135
|
this.saasufySocket = create(socketOptions);
|
|
122
136
|
this.lastSaasufySocketURL = this.getSanitizedURL();
|
|
137
|
+
this.lastExtraSocketOptionsString = this.getAttribute('socket-options') || '';
|
|
123
138
|
|
|
124
139
|
return this.saasufySocket;
|
|
125
140
|
}
|