Svelte store with a websocket backend
import websocketStore from "svelte-websocket-store";
const initialValue = { };
export const myStore = websocketStore("wss://mydomain.com/ws1", initialValue, ['option 1', 'option 2']);
// send JSON to websocket server
$myStore = { content: "to be saved", other_values: "all" };
// receive JSON from server (push)
let response = $myStore;Create a writable store based on a web-socket. Data is transferred as JSON. Keeps socket open (reopens if closed) as long as there are subscriptions.
urlstring the WebSocket urlinitialValueany store value used before 1st. response from server is presentsocketOptionsArray<string> transparently passed to the WebSocket constructor
Returns Store
With npm do:
npm install svelte-websocket-storeWith yarn do:
yarn add svelte-websocket-storeexport BROWSER=safari|chrome|...
npm|yarn testBSD-2-Clause