-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (31 loc) · 1.12 KB
/
index.js
File metadata and controls
39 lines (31 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var partial = require("ap").partial
, StreamRouter = require("stream-router")
, handleServer = require("./lib/handleServer")
, handleClient = require("./lib/handleClient")
, redirectServerToClient = require("./lib/redirectServerToClient")
, EventEmitter = require("events").EventEmitter.prototype
, extend = require("xtend")
, through = require("through")
module.exports = StreamServerProxy
function StreamServerProxy(prefix) {
var proxy = StreamRouter()
, stores = {}
extend(proxy, EventEmitter)
prefix = prefix || "/stream-server"
proxy.addRoute(prefix + "/server/:serverName/client/:clientName/*"
, partial(redirectServerToClient, stores))
proxy.addRoute(prefix + "/server/:serverName"
, partial(handleServer, stores, proxy))
proxy.addRoute(prefix + "/client/:serverName/*"
, partial(handleClient, stores))
// probably buggy
proxy.connect = connect
return proxy
function connect(serverName) {
var stream = through()
handleClient(stores, stream, {
serverName: serverName
})
return stream
}
}