- Oct 2023
- Sep 2023
- Aug 2023
-
stackblitz.com stackblitz.com
Tags
Annotators
URL
-
- Jul 2023
-
github.com github.com
-
That is because React.StrictMode renders the component twice (as it is intentional), that causes 2 connections get created. Create a ws connection inside useEffect and close on the effect cleanup would help or remove StrictMode from index file.
It's not a bug, it's a feature - they say.
React DX is so special...
-
-
www.kianmusser.com www.kianmusser.com
-
demo.mqtt.dev demo.mqtt.dev
Tags
Annotators
URL
-
-
developers.cloudflare.com developers.cloudflare.com
-
WebSocket support in Pub/Sub works by encapsulating MQTT packets (Pub/Sub’s underlying native protocol) within WebSocket framesExternal link icon
```js // Ensure MQTT.js is installed first // > npm install mqtt import * as mqtt from "mqtt"
// Where 'url' is "mqtts://BROKER.NAMESPACE.cloudflarepubsub.com:8884" function example(url) { let client = mqtt.connect(url, { protocolVersion: 5, reconnectPeriod: 0, username: 'anything', password: jwt, // pass this from a form field in your app clientId: '', })
client.on('connect', function () { client.subscribe(topic, function (err) { if (err) { client.end(); } else { console.log(
subscribed to ${topic}
) } })client.on('message', function (topic, message) { let line = (new Date()).toLocaleString('en-US') + ": " + message.toString() + "\n"; console.log(line) }) } ```
-
-
-
-
www.mnot.net www.mnot.net
Tags
Annotators
URL
-
-
-
```js exports.handler = async (event) => { if (event.headers != undefined) { const headers = toLowerCaseProperties(event.headers);
if (headers['sec-websocket-protocol'] != undefined) { const subprotocolHeader = headers['sec-websocket-protocol']; const subprotocols = subprotocolHeader.split(','); if (subprotocols.indexOf('myprotocol') >= 0) { const response = { statusCode: 200, headers: { "Sec-WebSocket-Protocol" : "myprotocol" } }; return response; } } } const response = { statusCode: 400 }; return response;
};function toLowerCaseProperties(obj) { var wrapper = {}; for (var key in obj) { wrapper[key.toLowerCase()] = obj[key]; } return wrapper; } ```
-
-
developers.cloudflare.com developers.cloudflare.com
-
github.com github.com
-
github.com github.com
-
developers.cloudflare.com developers.cloudflare.com
-
The Hibernation API allows a Durable Object that is not currently running an event handler, such as handling a WebSocket message, HTTP request, or alarm, to be removed from memory while keeping its WebSockets connected (“hibernation”).
-
- Apr 2023
-
www.oreilly.com www.oreilly.com
-
jmesnil.net jmesnil.net
-
jmesnil.net jmesnil.net
Tags
Annotators
URL
-
-
javascript.info javascript.info
-
-
developer.mozilla.org developer.mozilla.org
-
developer.mozilla.org developer.mozilla.org
Tags
- http:header=sec-websocket-extensions
- cito:cites=urn:ietf:rfc:6455
- cito:cites=urn:ietf:rfc:7540
- http
- cito:cites=urn:ietf:rfc:7230
- http:header=sec-websocket-version
- http:header=sec-websocket-key
- http:header=sec-websocket-accept
- websocket
- http:header=sec-websocket-protocol
- http:header=connection:upgrade
- http:header=upgrade:websocket
Annotators
URL
-
- Mar 2023
-
anchor.fm anchor.fm
-
Tags
Annotators
URL
-
-
deno.com deno.com
Tags
Annotators
URL
-
- Feb 2023
-
github.com github.com
-
js const wss = new WebSocketStream(url); const { readable } = await wss.connection; const reader = readable.getReader(); while (true) { const { value, done } = await reader.read(); if (done) break; await process(value); } done();
js const wss = new WebSocketStream(url); const { writable } = await wss.connection; const writer = writable.getWriter(); for await (const message of messages) { await writer.write(message); }
js const controller = new AbortController(); const wss = new WebSocketStream(url, { signal: controller.signal }); setTimeout(() => controller.abort(), 1000);
-
-
docs.google.com docs.google.com
- Jan 2023
-
www.bortzmeyer.org www.bortzmeyer.org
Tags
Annotators
URL
-
-
datatracker.ietf.org datatracker.ietf.orgrfc64551
-
solidproject.org solidproject.org
- Dec 2022
-
h3poteto.github.io h3poteto.github.io
Tags
Annotators
URL
-
-
docs.joinmastodon.org docs.joinmastodon.org
Tags
Annotators
URL
-
-
datatracker.ietf.org datatracker.ietf.org
Tags
Annotators
URL
-
-
datatracker.ietf.org datatracker.ietf.org
Tags
Annotators
URL
-
-
www.bortzmeyer.org www.bortzmeyer.org
Tags
Annotators
URL
-
-
www.zhihu.com www.zhihu.com
-
WebSocket 能否完全承担后端 Controller 的角色呢?
Tags
Annotators
URL
-
- Jun 2022
-
www.rabbitmq.com www.rabbitmq.com
Tags
Annotators
URL
-
-
activemq.apache.org activemq.apache.orgActiveMQ1
Tags
Annotators
URL
-
- Apr 2022
-
thenable.io thenable.io
Tags
Annotators
URL
-
- Mar 2022
-
blog.cloudflare.com blog.cloudflare.com
- Dec 2021
-
tkdodo.eu tkdodo.eu
-
Increasing StaleTime
React Query comes with a default staleTime of zero. This means that every query will be immediately considered as stale, which means it will refetch when a new subscriber mounts or when the user refocuses the window. It is aimed to keep your data as up-to-date as necessary.
This goal overlaps a lot with WebSockets, which update your data in real-time. Why would I need to refetch at all if I just manually invalidated because the server just told me to do so via a dedicated message?
So if you update all your data via websockets anyways, consider setting a high
staleTime
. In my example, I just usedInfinity
. This means the data will be fetched initially via useQuery, and then always come from the cache. Refetching only happens via the explicit query invalidation.You can best achieve this by setting global query defaults when creating the QueryClient:
const queryClient = new QueryClient({ defaultOptions: { queries: { staleTime: Infinity, }, }, })
-
-
codesandbox.io codesandbox.io
Tags
Annotators
URL
-
- Jul 2021
-
datatracker.ietf.org datatracker.ietf.orgrfc64551
-
Relationship to TCP and HTTP _This section is non-normative._ The WebSocket Protocol is an independent TCP-based protocol. Its only relationship to HTTP is that its handshake is interpreted by HTTP servers as an Upgrade request. By default, the WebSocket Protocol uses port 80 for regular WebSocket connections and port 443 for WebSocket connections tunneled over Transport Layer Security (TLS) [RFC2818].
-
- Jul 2020
-
marketplace.digitalocean.com marketplace.digitalocean.com
-
Listens to changes in a PostgreSQL Database and broadcasts them over WebSocket. It works like this:the Phoenix server listens to PostgreSQL's replication functionality (using Postgres' logical decoding).it converts the byte stream into JSON.it then broadcasts over WebSocket.
-