Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: add wss support #169

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading