sockjs-stream
Version:
A streaming API for sockjs
21 lines (15 loc) • 433 B
JavaScript
/*global WebSocket:true*/
var DataChannel = require("data-channel")
, WebSocket = require("ws")
, protocolLess = /^\/\/[^\/]+\//
, hasProtocol = /^wss?:\/\//
module.exports = Stream
function Stream(uri) {
if (protocolLess.test(uri)) {
uri = "ws:" + uri
} else if (!hasProtocol.test(uri)) {
uri = "ws://" + uri
}
var ws = new WebSocket(uri + "/websocket")
return DataChannel(ws)
}