Skip to content

Commit 97d0154

Browse files
authored
add wss support (#169)
Co-authored-by: Andrey Kaipov <andreykaipov@users.noreply.github.com>
1 parent 63f4642 commit 97d0154

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

client.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type Client struct {
3232
Categories
3333

3434
conn *websocket.Conn
35+
scheme string
3536
host string
3637
password string
3738
dialer *websocket.Dialer
@@ -85,6 +86,17 @@ func WithResponseTimeout(x time.Duration) Option {
8586
return func(o *Client) { o.client.ResponseTimeout = time.Duration(x) }
8687
}
8788

89+
// WithScheme sets the protocol scheme to use when connecting to the server,
90+
// e.g. "ws" or "wss". The default is "ws". Please note however that the
91+
// obs-websocket server does not currently support connecting over wss (ref:
92+
// https://github.com/obsproject/obs-websocket/issues/26). To be able to
93+
// connect over wss, you'll need to firest set up a reverse proxy in front of
94+
// the server. The obs-websocket folks have a guide here:
95+
// https://github.com/obsproject/obs-websocket/wiki/SSL-Tunneling.
96+
func WithScheme(x string) Option {
97+
return func(o *Client) { o.scheme = x }
98+
}
99+
88100
/*
89101
Disconnect sends a message to the OBS websocket server to close the client's
90102
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.
140152
*/
141153
func New(host string, opts ...Option) (*Client, error) {
142154
c := &Client{
155+
scheme: "ws",
143156
host: host,
144157
dialer: websocket.DefaultDialer,
145158
requestHeader: http.Header{"User-Agent": []string{"goobs/" + LibraryVersion}},
@@ -186,7 +199,7 @@ func New(host string, opts ...Option) (*Client, error) {
186199
}
187200

188201
func (c *Client) connect() (err error) {
189-
u := url.URL{Scheme: "ws", Host: c.host}
202+
u := url.URL{Scheme: c.scheme, Host: c.host}
190203

191204
c.client.Log.Printf("[INFO] Connecting to %s", u.String())
192205

0 commit comments

Comments
 (0)