Skip to content

Commit

Permalink
Use Action Cable with MessagePack encoding to deliver video stream fr…
Browse files Browse the repository at this point in the history
…ames (#153)

* Fix typo for setting data-turbo-track on script bundle

* Temporarily remove turbo-data-track attr for preloaded CSS stylesheets

* Make Turbo ignore noscript elements on page restore

* Enable instantiation of JPEGFrames

* Move mjpeg.JPEGFrame to videostreams.JPEGFrame

* Add Base64Frame so we can send JPEG data over JSON for Action Cable

* Send MJPEG frames over Action Cable instead of HTTP when possible

* Use a separate websocket connection for every video stream

* Use MessagePack encoding for Action Cable messages

* Upgrade godest, stimulated, and some other dependencies

* Make MJPEG receiver handle boundary Content-Type param with "--" prefix

* Resolve lint errors

* Upgrade more dependencies
  • Loading branch information
ethanjli authored Nov 29, 2022
1 parent 343f8d6 commit b165b97
Show file tree
Hide file tree
Showing 36 changed files with 812 additions and 431 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ jobs:
with:
go-version: 1.19

- uses: open-policy-agent/setup-opa@v1
- uses: open-policy-agent/setup-opa@v2
with:
version: 0.45
version: 0.46

- name: Build
run: make ci
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ You'll need to set some environment variables to tell pslive how to assign names
- SESSIONS_ENCRYPTION_KEY, which should be set to a session encryption key generated by running pslive without the SESSION_ENCRYPTION_KEY set.
- ORY_KRATOS_SERVER, which should be set to the URL of your Ory Kratos public API (either self-hosted or hosted on Ory Cloud), including the protocol scheme (e.g. `https://project-id.projects.oryapis.com`).
- ORY_ACCESS_TOKEN, which should be set to a personal access token from Ory Cloud for the URL of your Ory Kratos administrative API.
- TURBOSTREAMS_HASH_KEY, which should be set to an HMAC key generated by running Fluitans without the TURBOSTREAMS_HASH_KEY set.
- ACTIONCABLE_HASH_KEY, which should be set to an HMAC key generated by running Fluitans without the ACTIONCABLE_HASH_KEY set.

For example, you could generate the session and Turbo Streams hash key using:
```
Expand All @@ -42,7 +42,7 @@ which will print a message like:
```
Record this key for future use as SESSIONS_AUTH_KEY: QVG4y5EPPoDZjAzYc6j7I09iJum3w+hXNrB3O4HQvSc=
Record this key for future use as SESSIONS_ENCRYPTION_KEY: Z/47Z2Uf6J68VFf7uAjiTfmum3yKWRuR2KoLVhwVdYA=
Record this key for future use as TURBOSTREAMS_HASH_KEY: S+daMZsQxsqjmINunGWJhXvvxcgJtqnACba+sFuC4Tc=
Record this key for future use as ACTIONCABLE_HASH_KEY: S+daMZsQxsqjmINunGWJhXvvxcgJtqnACba+sFuC4Tc=
```

And then you could run the server in development mode using:
Expand All @@ -52,7 +52,7 @@ SESSION_AUTH_KEY='QVG4y5EPPoDZjAzYc6j7I09iJum3w+hXNrB3O4HQvSc=' \
SESSIONS_ENCRYPTION_KEY='Z/47Z2Uf6J68VFf7uAjiTfmum3yKWRuR2KoLVhwVdYA=' \
ORY_KRATOS_SERVER='https://project-1234.projects.oryapis.com' \
ORY_ACCESS_TOKEN='ory_pat_12345' \
TURBOSTREAMS_HASH_KEY='S+daMZsQxsqjmINunGWJhXvvxcgJtqnACba+sFuC4Tc=' \
ACTIONCABLE_HASH_KEY='S+daMZsQxsqjmINunGWJhXvvxcgJtqnACba+sFuC4Tc=' \
make run
```

Expand All @@ -62,7 +62,7 @@ DATABASE_URI='file:db.sqlite3' \
SESSION_AUTH_KEY='QVG4y5EPPoDZjAzYc6j7I09iJum3w+hXNrB3O4HQvSc=' \
ORY_KRATOS_SERVER='https://project-1234.projects.oryapis.com' \
ORY_ACCESS_TOKEN='ory_pat_12345' \
TURBOSTREAMS_HASH_KEY='S+daMZsQxsqjmINunGWJhXvvxcgJtqnACba+sFuC4Tc=' \
ACTIONCABLE_HASH_KEY='S+daMZsQxsqjmINunGWJhXvvxcgJtqnACba+sFuC4Tc=' \
./pslive
```

Expand Down
10 changes: 6 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/ory/client-go v0.2.0-alpha.60
github.com/paulbellamy/ratecounter v0.2.0
github.com/pkg/errors v0.9.1
github.com/sargassum-world/godest v0.4.3
github.com/sargassum-world/godest v0.5.0
github.com/unrolled/secure v1.13.0
golang.org/x/image v0.1.0
golang.org/x/sync v0.1.0
Expand All @@ -37,6 +37,7 @@ require (
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang/glog v1.0.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/flatbuffers v22.11.23+incompatible // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/securecookie v1.1.1 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
Expand All @@ -45,6 +46,7 @@ require (
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
github.com/rogpeppe/go-internal v1.8.0 // indirect
Expand All @@ -59,12 +61,12 @@ require (
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/yashtewari/glob-intersection v0.1.0 // indirect
golang.org/x/crypto v0.1.0 // indirect
golang.org/x/crypto v0.3.0 // indirect
golang.org/x/net v0.2.0 // indirect
golang.org/x/oauth2 v0.1.0 // indirect
golang.org/x/oauth2 v0.2.0 // indirect
golang.org/x/sys v0.2.0 // indirect
golang.org/x/text v0.4.0 // indirect
golang.org/x/time v0.1.0 // indirect
golang.org/x/time v0.2.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
22 changes: 12 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiu
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/flatbuffers v22.10.26+incompatible h1:z1QiaMyPu1x3Z6xf2u1dsLj1ZxicdGSeaLpCuIsQNZM=
github.com/google/flatbuffers v22.11.23+incompatible h1:334TygA7iuxt0hoamawsM36xoui01YiouEZnr0qeFMI=
github.com/google/flatbuffers v22.11.23+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
Expand Down Expand Up @@ -213,7 +214,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v1.13.1 h1:3gMjIY2+/hzmqhtUC/aQNYldJA6DtH3CgQvwS+02K1c=
github.com/prometheus/client_golang v1.14.0 h1:nJdhIvne2eSX/XRAFV9PcvFFRbrjbcTUj0VP62TMhnw=
github.com/prometheus/client_golang v1.14.0/go.mod h1:8vpkKitgIVNcqrRBWh1C4TIUQgYNtG/XQE4E/Zae36Y=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.3.0 h1:UBgGFHqYdG/TPFD1B1ogZywDqEkwp3fBMvqdiQ7Xew4=
github.com/prometheus/common v0.37.0 h1:ccBbHCgIiT9uSoFY0vX8H3zsNR5eLt17/RQLUvn8pXE=
Expand All @@ -225,8 +227,8 @@ github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qq
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
github.com/sargassum-world/godest v0.4.3 h1:xPY1hHGm6Z7CxgknBRtlKeoUADNkqln4ISl8p4S6j3Q=
github.com/sargassum-world/godest v0.4.3/go.mod h1:WP4bplxzGfnRjwhlcfR21FvO/rZDrWA7Kf4pqmHYuS4=
github.com/sargassum-world/godest v0.5.0 h1:ggwHqedyqRL16p/qZiCrDTDPZbaggIi9Yia70SPBSZE=
github.com/sargassum-world/godest v0.5.0/go.mod h1:WP4bplxzGfnRjwhlcfR21FvO/rZDrWA7Kf4pqmHYuS4=
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
Expand Down Expand Up @@ -280,8 +282,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20200414173820-0848c9571904/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU=
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
golang.org/x/crypto v0.3.0 h1:a06MkbcxBrEFc0w0QIZWXrH/9cCX6KJyWbBOIwAn+7A=
golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down Expand Up @@ -353,8 +355,8 @@ golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4Iltr
golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20210323180902-22b0adad7558/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
golang.org/x/oauth2 v0.1.0 h1:isLCZuhj4v+tYv7eskaN4v/TM+A1begWWgyVJDdl1+Y=
golang.org/x/oauth2 v0.1.0/go.mod h1:G9FE4dLTsbXUu90h/Pf85g4w1D+SSAgR+q46nJZ8M4A=
golang.org/x/oauth2 v0.2.0 h1:GtQkldQ9m7yvzCL1V+LrYow3Khe0eJH0w7RbX/VbaIU=
golang.org/x/oauth2 v0.2.0/go.mod h1:Cwn6afJ8jrQwYMxQDTpISoXmXW9I6qF6vDeuuoX3Ibs=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down Expand Up @@ -420,8 +422,8 @@ golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.1.0 h1:xYY+Bajn2a7VBmTM5GikTmnK8ZuX8YgnQCqZpbBNtmA=
golang.org/x/time v0.1.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.2.0 h1:52I/1L54xyEQAYdtcSuxtiT84KGYTBGXwayxmIpNJhE=
golang.org/x/time v0.2.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
Expand Down
8 changes: 4 additions & 4 deletions internal/app/pslive/client/globals.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type Globals struct {
AuthzChecker *auth.AuthzChecker

ACCancellers *actioncable.Cancellers
TSSigner turbostreams.Signer
ACSigner actioncable.Signer
TSBroker *turbostreams.Broker

Instruments *instruments.Store
Expand Down Expand Up @@ -85,11 +85,11 @@ func NewGlobals(
g.AuthzChecker = auth.NewAuthzChecker(g.DB, opc)

g.ACCancellers = actioncable.NewCancellers()
tssConfig, err := turbostreams.GetSignerConfig()
acsConfig, err := actioncable.GetSignerConfig()
if err != nil {
return nil, errors.Wrap(err, "couldn't set up turbo streams signer config")
return nil, errors.Wrap(err, "couldn't set up action cable signer config")
}
g.TSSigner = turbostreams.NewSigner(tssConfig)
g.ACSigner = actioncable.NewSigner(acsConfig)
g.TSBroker = turbostreams.NewBroker(l)

g.Instruments = instruments.NewStore(g.DB)
Expand Down
91 changes: 73 additions & 18 deletions internal/app/pslive/routes/cable/cable.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,99 @@ package cable

import (
"context"
"net/http"

"github.com/gorilla/sessions"
"github.com/gorilla/websocket"
"github.com/labstack/echo/v4"
"github.com/pkg/errors"
"github.com/sargassum-world/godest"
"github.com/sargassum-world/godest/actioncable"
"github.com/sargassum-world/godest/handling"
"github.com/sargassum-world/godest/session"
"github.com/sargassum-world/godest/turbostreams"

"github.com/sargassum-world/pslive/internal/app/pslive/auth"
"github.com/sargassum-world/pslive/internal/clients/videostreams"
)

func serveWSConn(
r *http.Request, wsc *websocket.Conn, sess *sessions.Session,
channelFactories map[string]actioncable.ChannelFactory,
cc *session.CSRFTokenChecker, acc *actioncable.Cancellers, wsu websocket.Upgrader,
l godest.Logger,
) {
conn, err := actioncable.Upgrade(wsc, actioncable.NewChannelDispatcher(
channelFactories, make(map[string]actioncable.Channel),
actioncable.WithCSRFTokenChecker(func(token string) error {
return cc.Check(r, token)
}),
))
// We can't return errors after the HTTP request is upgraded to a websocket, so we just log them
if err != nil {
l.Error(errors.Wrapf(
err,
"couldn't upgrade websocket connection to action cable connection "+
"(client requested subprotocols %v, upgrader supports subprotocols %v)",
websocket.Subprotocols(r),
wsu.Subprotocols,
))
if cerr := wsc.Close(); cerr != nil {
l.Error(errors.Wrapf(cerr, "couldn't close websocket"))
}
return
}

ctx, cancel := context.WithCancel(r.Context())
acc.Add(sess.ID, cancel)
serr := handling.Except(conn.Serve(ctx), context.Canceled)
if serr != nil {
// We can't return errors after the HTTP request is upgraded to a websocket, so we just log them
l.Error(serr)
}
if cerr := conn.Close(serr); err != nil {
// We can't return errors after the HTTP request is upgraded to a websocket, so we just log them
l.Error(cerr)
}
}

func (h *Handlers) HandleCableGet() auth.HTTPHandlerFuncWithSession {
return func(c echo.Context, _ auth.Auth, sess *sessions.Session) error {
wsc, err := h.wsu.Upgrade(c.Response(), c.Request(), nil)
if err != nil {
return err
return errors.Wrap(err, "couldn't upgrade http request to websocket connection")
}

const wsMaxMessageSize = 512
wsc.SetReadLimit(wsMaxMessageSize)

acc := actioncable.Upgrade(wsc, actioncable.WithChannels(
serveWSConn(
c.Request(), wsc, sess,
map[string]actioncable.ChannelFactory{
turbostreams.ChannelName: turbostreams.NewChannelFactory(h.tsb, sess.ID, h.tss.Check),
turbostreams.ChannelName: turbostreams.NewChannelFactory(h.tsb, sess.ID, h.acs.Check),
},
make(map[string]actioncable.Channel),
actioncable.WithCSRFTokenChecker(func(token string) error {
return h.cc.Check(c.Request(), token)
}),
))
ctx, cancel := context.WithCancel(c.Request().Context())
h.acc.Add(sess.ID, cancel)
serr := acc.Serve(ctx)
// We can't return errors after the HTTP request is upgraded to a websocket, so we just log them
if serr != nil && serr != context.Canceled {
h.l.Error(serr)
}
if err := acc.Close(serr); err != nil {
h.l.Error(err)
h.cc, h.acc, h.wsu, h.l,
)
return nil
}
}

func (h *Handlers) HandleVideoCableGet() auth.HTTPHandlerFuncWithSession {
return func(c echo.Context, _ auth.Auth, sess *sessions.Session) error {
wsc, err := h.wsu.Upgrade(c.Response(), c.Request(), nil)
if err != nil {
return errors.Wrap(err, "couldn't upgrade http request to websocket connection")
}

const wsMaxMessageSize = 512
wsc.SetReadLimit(wsMaxMessageSize)
// TODO: make this action cable connection use msgpack instead of json for efficiency reasons
serveWSConn(
c.Request(), wsc, sess,
map[string]actioncable.ChannelFactory{
videostreams.ChannelName: videostreams.NewChannelFactory(h.vsb, sess.ID, h.l, h.acs.Check),
},
h.cc, h.acc, h.wsu, h.l,
)
return nil
}
}
19 changes: 12 additions & 7 deletions internal/app/pslive/routes/cable/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/sargassum-world/godest/turbostreams"

"github.com/sargassum-world/pslive/internal/app/pslive/auth"
"github.com/sargassum-world/pslive/internal/clients/videostreams"
)

type Handlers struct {
Expand All @@ -20,33 +21,37 @@ type Handlers struct {
cc *session.CSRFTokenChecker

acc *actioncable.Cancellers
tss turbostreams.Signer
acs actioncable.Signer
tsb *turbostreams.Broker

l godest.Logger
vsb *videostreams.Broker

wsu websocket.Upgrader

l godest.Logger
}

func New(
r godest.TemplateRenderer, ss *session.Store, cc *session.CSRFTokenChecker,
acc *actioncable.Cancellers, tss turbostreams.Signer, tsb *turbostreams.Broker, l godest.Logger,
acc *actioncable.Cancellers, acs actioncable.Signer, tsb *turbostreams.Broker,
vsb *videostreams.Broker, l godest.Logger,
) *Handlers {
return &Handlers{
r: r,
ss: ss,
cc: cc,
acc: acc,
tss: tss,
acs: acs,
tsb: tsb,
l: l,
vsb: vsb,
wsu: websocket.Upgrader{
Subprotocols: actioncable.Subprotocols(),
Subprotocols: actioncable.SupportedSubprotocols(),
// TODO: add parameters to the upgrader as needed
},
l: l,
}
}

func (h *Handlers) Register(er godest.EchoRouter) {
er.GET("/cable", auth.HandleHTTPWithSession(h.HandleCableGet(), h.ss))
er.GET("/video-cable", auth.HandleHTTPWithSession(h.HandleVideoCableGet(), h.ss))
}
Loading

0 comments on commit b165b97

Please sign in to comment.