Read about STOMP protocol here.
It seems STOMP is under-appreciated for realtime apps. It's text-based so it can work over WebSocket connections. My hope is to provide enough structure to make STOMP servers as simple as express HTTP servers.
The motivation for using STOMP instead of
ActionCable is that STOMP is an open protocol which can run on any client or server the supports TCP connections. Things change, perhaps in the future you'll want to use
golang on the server and native
Each package module is explained below, from lowest to highest abstraction.
Each message between client and server is a "frame", which looks like:
var frame =command: "string"headers: "string": "string"body: "string"var text = Frameframe = Frame
The STOMP protocol defines available commands and headers.
webstomp checks if the command is valid.
webstomp Socket encodes and decodes frames. Otherwise, you'd have to call
fromString on each send and receive.
var WebSocket =var Socket =var ws = ""var socket = wssocketsocket
webstomp Server emits Socket connections. Otherwise, you'd have to wrap each new WebSocket connection yourself.
var Server =var server = port: 8000server
You're bored. Here's the useful bits coming up.
var Session =// `socket` is a webstomp Socketvar session = socket// Send connected framesession// Send json message to a channelvar data = key: "value"var headers = "channel": "/notifications"session// Send errors to clientsession
For realtime apps, it's practical to model channels as lazy observables. Sessions can pipe observable events to the client as message frames. Examples include
baconjs stream, readable
// When client subscribesvar unhook = session// When client unsubscribes
webstomp Router is designed to look like express. Instead of HTTP actions, you have STOMP actions. Instead of
(req, res, next) you have
var Router =var router =routerrouterrouterrouterrouter
webstomp App ties it all together. It creates a WebSocket server, wraps it with a
webstomp Server, acts like a
webstomp Router, and dispatches request Frames to the current Session.
var App =var app =// Or you can be fancy// var app = require("stomp")()appappapp
You can mount a
webstomp App onto an HTTP server, which allows you to use the HTTP server too. For example, with express:
var http =var stomp =var api =var server = stompserver
So that's it. For realtime apps, on-demand PUB/SUB channels provide structure. The pattern maps well to server-side services that return an observable, and also client-side components that subscribe when added into view, and unsubscribe when removed.
Please contribute ideas, bugs, etc.