From 97d0154363f974737817a885bb2fc93b74ef9ab7 Mon Sep 17 00:00:00 2001 From: Andrey Kaipov <9457739+andreykaipov@users.noreply.github.com> Date: Thu, 8 Aug 2024 14:17:47 -0400 Subject: [PATCH] add wss support (#169) Co-authored-by: Andrey Kaipov --- client.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index a49647a..2eeabb1 100644 --- a/client.go +++ b/client.go @@ -32,6 +32,7 @@ type Client struct { Categories conn *websocket.Conn + scheme string host string password string dialer *websocket.Dialer @@ -85,6 +86,17 @@ func WithResponseTimeout(x time.Duration) Option { return func(o *Client) { o.client.ResponseTimeout = time.Duration(x) } } +// WithScheme sets the protocol scheme to use when connecting to the server, +// e.g. "ws" or "wss". The default is "ws". Please note however that the +// obs-websocket server does not currently support connecting over wss (ref: +// https://github.com/obsproject/obs-websocket/issues/26). To be able to +// connect over wss, you'll need to firest set up a reverse proxy in front of +// the server. The obs-websocket folks have a guide here: +// https://github.com/obsproject/obs-websocket/wiki/SSL-Tunneling. +func WithScheme(x string) Option { + return func(o *Client) { o.scheme = x } +} + /* Disconnect sends a message to the OBS websocket server to close the client's open connection. You should defer a disconnection after creating your client to @@ -140,6 +152,7 @@ It also opens up a connection, so be sure to check the error. */ func New(host string, opts ...Option) (*Client, error) { c := &Client{ + scheme: "ws", host: host, dialer: websocket.DefaultDialer, requestHeader: http.Header{"User-Agent": []string{"goobs/" + LibraryVersion}}, @@ -186,7 +199,7 @@ func New(host string, opts ...Option) (*Client, error) { } func (c *Client) connect() (err error) { - u := url.URL{Scheme: "ws", Host: c.host} + u := url.URL{Scheme: c.scheme, Host: c.host} c.client.Log.Printf("[INFO] Connecting to %s", u.String())