Repository
Current version released
4 years ago
Dependencies
std
Sockets
A WebSocket library for Deno.
Although Sockets has working code, it is still very much under development. APIs will change without notice. Sorry for any inconvenience!
Table of Contents
- Getting Started
- Integrating
- Documentation (in progress)
- Features
- Roadmap
- Contributing
- License
Getting Started
To get you started as quickly as possible with a simple client and server, check out the following example app:
We also have a more advanced example app:
All example apps in the example_apps
directory have their own README.md
file. The README.md
files have all the instructions you need to get started.
Integrating
Sockets is composed of two parts:
A
SocketServer
class that is used to instantiate a socket server on the back-endimport { SocketServer } from "https://deno.land/x/sockets@master/mod.ts"; // Create the server const socketServer = new SocketServer(); socketServer.run({ hostname: "localhost", port: 3000 }); console.log(`Socket server started on ws://${socketServer.hostname}:${socketServer.port}`); // Create Channel 1 and listen to messages sent to Channel 1 by clients socketServer.createChannel("Channel 1") .onMessage((packet: any) => { console.log(packet); });
A client library that loads on the front-end
<script src="https://cdn.jsdelivr.net/gh/drashland/sockets@master/client.js"></script> <script> // Create the client const socketClient = new SocketClient({ hostname: "localhost", port: 3000 }); // Listen to messages sent to Channel 1 by the server socketClient.on("Channel 1", (packet) => { console.log(packet); }); // Send a message to Channel 1 socketClient.send("Channel 1", "Deno + Sockets is cool!"); </script>
Features
- Binary-support
Roadmap
- Auto-reconnection support
Contributing
Contributors are welcomed!
License
By contributing your code, you agree to license your contribution under the MIT License.