svelte-websocket-store 1.2.15 → 1.2.17
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/package.json +6 -6
- package/src/index.mjs +14 -5
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-websocket-store",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.17",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"provenance": true
|
|
7
7
|
},
|
|
8
|
-
"packageManager": "npm@11.
|
|
8
|
+
"packageManager": "npm@11.16.0",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
11
|
"default": "./src/index.mjs"
|
|
@@ -52,12 +52,12 @@
|
|
|
52
52
|
"c8": "^11.0.0",
|
|
53
53
|
"documentation": "^14.0.3",
|
|
54
54
|
"mf-styling": "^3.3.20",
|
|
55
|
-
"npm-pkgbuild": "^20.
|
|
55
|
+
"npm-pkgbuild": "^20.7.3",
|
|
56
56
|
"playwright": "^1.60.0",
|
|
57
|
-
"semantic-release": "^25.0.
|
|
58
|
-
"svelte": "^5.
|
|
57
|
+
"semantic-release": "^25.0.5",
|
|
58
|
+
"svelte": "^5.56.3",
|
|
59
59
|
"svelte-common": "^6.19.80",
|
|
60
|
-
"vite": "^8.0.
|
|
60
|
+
"vite": "^8.0.16",
|
|
61
61
|
"vite-plugin-compression2": "^2.5.3",
|
|
62
62
|
"ws": "^8.21.0"
|
|
63
63
|
},
|
package/src/index.mjs
CHANGED
|
@@ -28,6 +28,8 @@ export function websocketStore(url, initialValue, socketOptions) {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
if (socket) {
|
|
31
|
+
socket.onclose = null;
|
|
32
|
+
socket.onerror = null;
|
|
31
33
|
socket.close();
|
|
32
34
|
socket = undefined;
|
|
33
35
|
}
|
|
@@ -51,7 +53,7 @@ export function websocketStore(url, initialValue, socketOptions) {
|
|
|
51
53
|
return openPromise;
|
|
52
54
|
}
|
|
53
55
|
if (socket) {
|
|
54
|
-
return
|
|
56
|
+
return;
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
socket = new WebSocket(url, socketOptions);
|
|
@@ -79,9 +81,16 @@ export function websocketStore(url, initialValue, socketOptions) {
|
|
|
79
81
|
|
|
80
82
|
return {
|
|
81
83
|
set(value) {
|
|
82
|
-
const send = () =>
|
|
83
|
-
|
|
84
|
-
|
|
84
|
+
const send = () => {
|
|
85
|
+
if (socket && socket.readyState === WebSocket.OPEN) {
|
|
86
|
+
socket.send(JSON.stringify(value));
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
if (!socket || socket.readyState !== WebSocket.OPEN) {
|
|
90
|
+
open().then(send).catch(() => {});
|
|
91
|
+
} else {
|
|
92
|
+
send();
|
|
93
|
+
}
|
|
85
94
|
},
|
|
86
95
|
subscribe(subscription) {
|
|
87
96
|
open();
|
|
@@ -97,4 +106,4 @@ export function websocketStore(url, initialValue, socketOptions) {
|
|
|
97
106
|
};
|
|
98
107
|
}
|
|
99
108
|
|
|
100
|
-
export default websocketStore;
|
|
109
|
+
export default websocketStore;
|