Changelog
v0.3.3
.response
prop in upgrade
(#113)Changelog
v0.3.2
upgrade
hook (#91)context
(#110)upgrade
hook and peer
(#111)peer.request
always has .headers
if defined (e915f8d)peer.request
as always defined (8fbb59b)Changelog
v0.3.0
Crossws 0.3.x includes an overhaul of refactors, stability improvements, and new features. A new codebase and testing matrix had been implemented (#55) to make sure all supported adapters and runtimes work as expected and are consistent with each other.
The peer object allows easy interaction with connected WebSocket clients from server route hooks (peer docs).
To improve Web standards compatibility, accessing upgrade URL and headers is now possible with peer.request.url
and peer.request.headers
(breaking change), and peer.addr
is also renamed to peer.remoteAddress
to improve readability (breaking change) and support is increased across providers. You can also use new lazy-generated and secure peer.id
(UUID v4) for various purposes including temporary sessions or persistent state.
Two new methods are now supported to close connected peers using peer.close(code, reason)
and peer.terminate()
. With this new version, you can access a standard WebSocket
interface using peer.websocket
.
[!NOTE] Today many of the server runtimes don't provide a spec-compliant
WebSocket
API. Crossws uses an internal proxy to polyfill consistent access toextensions
,protocol
, andreadyState
. See compatibility table for more details.
On message
hook, you receive a message object containing data from the client (message docs).
Parsing incoming messages can be tricky across runtimes. Message object now has stable methods .text()
, .json()
, .uint8Array()
, .arrayBuffer()
, .blob()
to safely read message as desired format. If you need, you can also access .rawData
, .peer
, .event
(if available), and lazy generated secure UUID v4 .id
upgrade
hookWhen you need to authenticate and validate WebSocket clients before they can upgrade, you can now easily use the upgrade
hook to check incoming URLs and headers/cookies and return a Web Standard Response in case you need to abort the upgrade.
One of the common use cases of WebSockets is pubsub. This release adds pub-sub support to Deno provider and also you can globally broadcast messages using ws.publish
for advanced use cases.
Normally with cloudflare workers, it is not possible to connect multiple peers with each other. Cloudflare Durable Objects (available on paid plans) allows building collaborative editing tools, interactive chat, multiplayer games, and applications that need coordination among multiple clients.
Crossws provides a new composable method to easily integrate WebSocket handlers with Durable Objects. Hibernation is supported out of the box to reduce billing costs when connected clients are inactive. (durable object peer docs)
peer.close()
and peer.terminate()
support (#36)ws.publish
(#61)peer.ctx
to peer._internal
(#59)#22, 76fc105, 7dacb00, #46, #45, #44, a96dca3, 898ab49, 2e49cc3
WebSocket
and EventSource
(#67)Changelog
v0.2.4