Skip to content

Commit

Permalink
add wss support (#169)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrey Kaipov <[email protected]>
  • Loading branch information
andreykaipov and andreykaipov authored Aug 8, 2024
1 parent 63f4642 commit 97d0154
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Client struct {
Categories

conn *websocket.Conn
scheme string
host string
password string
dialer *websocket.Dialer
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}},
Expand Down Expand Up @@ -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())

Expand Down

0 comments on commit 97d0154

Please sign in to comment.