good morning!!!!

Skip to content
Snippets Groups Projects
Verified Commit 841f5418 authored by a's avatar a
Browse files

maybe js will work

parent ca03f7f5
No related branches found
No related tags found
No related merge requests found
......@@ -24,8 +24,8 @@ import (
"time"
"gfx.cafe/open/jrpc/wsjson"
"tuxpa.in/a/zlog/log"
"nhooyr.io/websocket"
"tuxpa.in/a/zlog/log"
)
const (
......@@ -70,45 +70,6 @@ func (e wsHandshakeError) Error() string {
return s
}
// that is listening on the given endpoint using the provided dialer.
func DialWebsocketWithDialer(ctx context.Context, endpoint, origin string, opts *websocket.DialOptions) (*Client, error) {
endpoint, header, err := wsClientHeaders(endpoint, origin)
if err != nil {
return nil, err
}
opts.HTTPHeader = header
return newClient(ctx, func(cctx context.Context) (ServerCodec, error) {
conn, resp, err := websocket.Dial(cctx, endpoint, opts)
if err != nil {
hErr := wsHandshakeError{err: err}
if resp != nil {
hErr.status = resp.Status
}
return nil, hErr
}
out := newWebsocketCodec(resp.Request.Context(), conn, endpoint, header)
return out, err
})
}
// 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.
func DialWebsocket(ctx context.Context, endpoint, origin string) (*Client, error) {
endpoint, header, err := wsClientHeaders(endpoint, origin)
if err != nil {
return nil, err
}
dialer := &websocket.DialOptions{
CompressionMode: websocket.CompressionContextTakeover,
CompressionThreshold: 4096,
HTTPHeader: header,
}
return DialWebsocketWithDialer(ctx, endpoint, origin, dialer)
}
func wsClientHeaders(endpoint, origin string) (string, http.Header, error) {
endpointURL, err := url.Parse(endpoint)
if err != nil {
......
package jrpc
// that is listening on the given endpoint using the provided dialer.
func DialWebsocketWithDialer(ctx context.Context, endpoint, origin string, opts *websocket.DialOptions) (*Client, error) {
endpoint, header, err := wsClientHeaders(endpoint, origin)
if err != nil {
return nil, err
}
return newClient(ctx, func(cctx context.Context) (ServerCodec, error) {
conn, resp, err := websocket.Dial(cctx, endpoint, opts)
if err != nil {
hErr := wsHandshakeError{err: err}
if resp != nil {
hErr.status = resp.Status
}
return nil, hErr
}
out := newWebsocketCodec(resp.Request.Context(), conn, endpoint, header)
return out, err
})
}
// 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.
func DialWebsocket(ctx context.Context, endpoint, origin string) (*Client, error) {
endpoint, header, err := wsClientHeaders(endpoint, origin)
if err != nil {
return nil, err
}
dialer := &websocket.DialOptions{}
return DialWebsocketWithDialer(ctx, endpoint, origin, dialer)
}
//go:build !js
package jrpc
import (
"context"
"nhooyr.io/websocket"
)
// that is listening on the given endpoint using the provided dialer.
func DialWebsocketWithDialer(ctx context.Context, endpoint, origin string, opts *websocket.DialOptions) (*Client, error) {
endpoint, header, err := wsClientHeaders(endpoint, origin)
if err != nil {
return nil, err
}
opts.HTTPHeader = header
return newClient(ctx, func(cctx context.Context) (ServerCodec, error) {
conn, resp, err := websocket.Dial(cctx, endpoint, opts)
if err != nil {
hErr := wsHandshakeError{err: err}
if resp != nil {
hErr.status = resp.Status
}
return nil, hErr
}
out := newWebsocketCodec(resp.Request.Context(), conn, endpoint, header)
return out, err
})
}
// 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.
func DialWebsocket(ctx context.Context, endpoint, origin string) (*Client, error) {
endpoint, header, err := wsClientHeaders(endpoint, origin)
if err != nil {
return nil, err
}
dialer := &websocket.DialOptions{
CompressionMode: websocket.CompressionContextTakeover,
CompressionThreshold: 4096,
HTTPHeader: header,
}
return DialWebsocketWithDialer(ctx, endpoint, origin, dialer)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment