add more websocket helpers from neffos project

Former-commit-id: fcb9ec46849fd745fe0f62524d9b85067a334048
This commit is contained in:
Gerasimos (Makis) Maropoulos 2019-06-15 14:07:35 +03:00
parent c93093d6c2
commit 164f24dec4
3 changed files with 23 additions and 6 deletions

View File

@ -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)
}

View File

@ -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`,

View File

@ -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.