DialWebsocket creates a new RPC client that communicates with a JSON-RPC server that is listening on the given endpoint. The context is used for the initial connection establishment. It does not affect subsequent interactions with the client.
(ctx context.Context, endpoint, origin string)
| 124 | // The context is used for the initial connection establishment. It does not |
| 125 | // affect subsequent interactions with the client. |
| 126 | func DialWebsocket(ctx context.Context, endpoint, origin string) (*Client, error) { |
| 127 | if origin == "" { |
| 128 | var err error |
| 129 | if origin, err = os.Hostname(); err != nil { |
| 130 | return nil, err |
| 131 | } |
| 132 | if strings.HasPrefix(endpoint, "wss") { |
| 133 | origin = "https://" + strings.ToLower(origin) |
| 134 | } else { |
| 135 | origin = "http://" + strings.ToLower(origin) |
| 136 | } |
| 137 | } |
| 138 | config, err := websocket.NewConfig(endpoint, origin) |
| 139 | if err != nil { |
| 140 | return nil, err |
| 141 | } |
| 142 | |
| 143 | return newClient(ctx, func(ctx context.Context) (net.Conn, error) { |
| 144 | return wsDialContext(ctx, config) |
| 145 | }) |
| 146 | } |
| 147 | |
| 148 | func wsDialContext(ctx context.Context, config *websocket.Config) (*websocket.Conn, error) { |
| 149 | var conn net.Conn |
no test coverage detected