All Projects → kudos → Koa Websocket

kudos / Koa Websocket

Licence: mit
Light wrapper around Koa providing a websocket middleware handler that is koa-route compatible.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Koa Websocket

Red5 Websocket
Websocket plug-in for Red5
Stars: ✭ 60 (-73.21%)
Mutual labels:  websockets, ws
soketi
Just another simple, fast, and resilient open-source WebSockets server. 📣
Stars: ✭ 2,202 (+883.04%)
Mutual labels:  websockets, ws
docs
The official soketi documentation. 📡
Stars: ✭ 55 (-75.45%)
Mutual labels:  websockets, ws
echo-server
Echo Server is a container-ready, multi-scalable Node.js application used to host your own Socket.IO server for Laravel Broadcasting.
Stars: ✭ 36 (-83.93%)
Mutual labels:  websockets, ws
Isomorphic Ws
Isomorphic implementation of WebSocket (https://www.npmjs.com/package/ws)
Stars: ✭ 215 (-4.02%)
Mutual labels:  websockets, ws
Lionshare Api
Realtime cryptocurrency API
Stars: ✭ 266 (+18.75%)
Mutual labels:  koa, websockets
webfuse
websocket filesystem based on libfuse
Stars: ✭ 23 (-89.73%)
Mutual labels:  websockets, ws
Hapi Plugin Websocket
HAPI plugin for seamless WebSocket integration
Stars: ✭ 47 (-79.02%)
Mutual labels:  websockets, ws
Arduinowebsockets
arduinoWebSockets
Stars: ✭ 1,265 (+464.73%)
Mutual labels:  websockets, ws
Nuxt Juejin Project
仿掘金web网站,使用服务端渲染。主要技术:nuxt + koa + vuex + axios + element-ui 。
Stars: ✭ 209 (-6.7%)
Mutual labels:  koa
Openapi Backend
Build, Validate, Route, Authenticate and Mock using OpenAPI
Stars: ✭ 216 (-3.57%)
Mutual labels:  koa
Nobibi
一款基于Next.js+mongo的轻量级开源社区(open community by Next.js & mongo)
Stars: ✭ 209 (-6.7%)
Mutual labels:  koa
Lgwebosremote
Command line webOS remote for LGTVs
Stars: ✭ 211 (-5.8%)
Mutual labels:  websockets
Node Red Contrib Uibuilder
Easily create data-driven web UI's for Node-RED using any (or no) front-end library. VueJS and bootstrap-vue included but change as desired.
Stars: ✭ 215 (-4.02%)
Mutual labels:  websockets
Aleph
Asynchronous communication for Clojure
Stars: ✭ 2,389 (+966.52%)
Mutual labels:  websockets
Koa Proxy
Proxy middleware for koa
Stars: ✭ 221 (-1.34%)
Mutual labels:  koa
Async Tungstenite
Async binding for Tungstenite, the Lightweight stream-based WebSocket implementation
Stars: ✭ 207 (-7.59%)
Mutual labels:  websockets
Umajs
Umajs,easy-to-use framework base on Typescript
Stars: ✭ 209 (-6.7%)
Mutual labels:  koa
Web Socket
Laravel library for asynchronously serving WebSockets.
Stars: ✭ 225 (+0.45%)
Mutual labels:  websockets
Roa
async web framework inspired by koajs, lightweight but powerful.
Stars: ✭ 221 (-1.34%)
Mutual labels:  koa

koa-websocket

Circle CI

Koa v2 is now the default. For Koa v1 support install with [email protected] and see the legacy branch.

Supports ws:// and wss://

Installation

npm install koa-websocket

Usage

const Koa = require('koa'),
  route = require('koa-route'),
  websockify = require('koa-websocket');

const app = websockify(new Koa());

// Regular middleware
// Note it's app.ws.use and not app.use
app.ws.use(function(ctx, next) {
  // return `next` to pass the context (ctx) on to the next ws middleware
  return next(ctx);
});

// Using routes
app.ws.use(route.all('/test/:id', function (ctx) {
  // `ctx` is the regular koa context created from the `ws` onConnection `socket.upgradeReq` object.
  // the websocket is added to the context on `ctx.websocket`.
  ctx.websocket.send('Hello World');
  ctx.websocket.on('message', function(message) {
    // do something with the message from client
        console.log(message);
  });
}));

app.listen(3000);

Example with Let's Encrypt (the Greenlock package):

const Koa = require('koa');
const greenlock = require('greenlock-express');
const websockify = require('koa-websocket');
 
const le = greenlock.create({
  // all your sweet Let's Encrypt options here
});
 
// the magic happens right here
const app = websockify(new Koa(), wsOptions, le.httpsOptions);
 
app.ws.use((ctx) => {
   // the websocket is added to the context as `ctx.websocket`.
  ctx.websocket.on('message', function(message) {
    // do something
  });
});
 
app.listen(3000);

With custom websocket options.

const Koa = require('koa'),
  route = require('koa-route'),
  websockify = require('koa-websocket');

const wsOptions = {};
const app = websockify(new Koa(), wsOptions);

app.ws.use(route.all('/', (ctx) => {
   // the websocket is added to the context as `ctx.websocket`.
  ctx.websocket.on('message', function(message) {
    // print message from the client
    console.log(message);
  });
}));

app.listen(3000);

API

websockify(KoaApp, [WebSocketOptions], [httpsOptions])

The WebSocket options object just get passed right through to the new WebSocketServer(options) call.

The optional HTTPS options object gets passed right into https.createServer(options). If the HTTPS options are passed in, koa-websocket will use the built-in Node HTTPS server to provide support for the wss:// protocol.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].