Skip to content

Commit

Permalink
Add public func to create web socket connection
Browse files Browse the repository at this point in the history
  • Loading branch information
jagoPG committed Jan 19, 2024
1 parent d7c816a commit 15df28c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion websocketconnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,20 @@ import (
"bytes"
"context"
"fmt"

"net/http"
"net/url"
"nhooyr.io/websocket"
)

func NewWebSocketConnection(ctx context.Context, reqURL *url.URL, connectionID string, headers http.Header) (Connection, error) {
ws, _, err := websocket.Dial(ctx, reqURL.String(), &websocket.DialOptions{HTTPHeader: headers})
if err != nil {
return nil, err
}

return newWebSocketConnection(ctx, connectionID, ws), nil
}

type webSocketConnection struct {
ConnectionBase
conn *websocket.Conn
Expand Down

0 comments on commit 15df28c

Please sign in to comment.