From 164f24dec48a4ddfbf40b295ad1b20a388a9ba83 Mon Sep 17 00:00:00 2001 From: "Gerasimos (Makis) Maropoulos" Date: Sat, 15 Jun 2019 14:07:35 +0300 Subject: [PATCH] add more websocket helpers from neffos project Former-commit-id: fcb9ec46849fd745fe0f62524d9b85067a334048 --- _examples/websocket/basic/go-client/client.go | 2 +- websocket/websocket.go | 15 +++++++++++---- websocket/websocket_go19.go | 12 +++++++++++- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/_examples/websocket/basic/go-client/client.go b/_examples/websocket/basic/go-client/client.go index 29e23aeb..edfff936 100644 --- a/_examples/websocket/basic/go-client/client.go +++ b/_examples/websocket/basic/go-client/client.go @@ -42,7 +42,7 @@ func main() { ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(dialAndConnectTimeout)) defer cancel() - client, err := websocket.Dial(ctx, websocket.GorillaDialer, endpoint, clientEvents) + client, err := websocket.Dial(ctx, websocket.DefaultGorillaDialer, endpoint, clientEvents) if err != nil { panic(err) } diff --git a/websocket/websocket.go b/websocket/websocket.go index 5b097cce..ad65ca3d 100644 --- a/websocket/websocket.go +++ b/websocket/websocket.go @@ -28,10 +28,17 @@ var ( // See examples for more. New = neffos.New - // GorillaDialer is a gorilla/websocket dialer with all fields set to the default values. - GorillaDialer = gorilla.DefaultDialer - // GobwasDialer is a gobwas/ws dialer with all fields set to the default values. - GobwasDialer = gobwas.DefaultDialer + // GorillaDialer is a `Dialer` type for the gorilla/websocket subprotocol implementation. + // Should be used on `Dial` to create a new client/client-side connection. + GorillaDialer = gorilla.Dialer + // GobwasDialer is a `Dialer` type for the gobwas/ws subprotocol implementation. + // Should be used on `Dial` to create a new client/client-side connection. + GobwasDialer = gobwas.Dialer + + // DefaultGorillaDialer is a gorilla/websocket dialer with all fields set to the default values. + DefaultGorillaDialer = gorilla.DefaultDialer + // DefaultGobwasDialer is a gobwas/ws dialer with all fields set to the default values. + DefaultGobwasDialer = gobwas.DefaultDialer // Dial establishes a new websocket client connection. // Context "ctx" is used for handshake timeout. // Dialer "dial" can be either `GorillaDialer` or `GobwasDialer`, diff --git a/websocket/websocket_go19.go b/websocket/websocket_go19.go index 34d4802c..af0f3c57 100644 --- a/websocket/websocket_go19.go +++ b/websocket/websocket_go19.go @@ -4,15 +4,25 @@ package websocket import ( "github.com/kataras/neffos" + "github.com/kataras/neffos/gobwas" + "github.com/kataras/neffos/gorilla" ) type ( + // Dialer is the definition type of a dialer, gorilla or gobwas or custom. + // It is the second parameter of the `Dial` function. + Dialer = neffos.Dialer + // GorillaDialerOptions is just an alias for the `gobwas/ws.Dialer` struct type. + GorillaDialerOptions = gorilla.Options + // GobwasDialerOptions is just an alias for the `gorilla/websocket.Dialer` struct type. + GobwasDialerOptions = gobwas.Options + // Conn describes the main websocket connection's functionality. // Its `Connection` will return a new `NSConn` instance. // Each connection can connect to one or more declared namespaces. // Each `NSConn` can join to multiple rooms. Conn = neffos.Conn - // NSConn describes a connected connection to a specific namespace, + // NSConn describes a connection connected to a specific namespace, // it emits with the `Message.Namespace` filled and it can join to multiple rooms. // A single `Conn` can be connected to one or more namespaces, // each connected namespace is described by this structure.