socket

package
v0.0.16 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 24, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ParseSocketMessageEvent = event_emitter.Event[ParseSocketMessageArguments, ParseSocketMessageArguments]{
	Token: "recieveMessageEvent",
	Handler: func(event string, params ParseSocketMessageArguments) (ParseSocketMessageArguments, error) {
		return params, nil
	},
	OnError: func(event string, err error) {
		log.Printf("[Error %s]: %s", event, err.Error())
	},
}

Functions

func Factory

func Factory() *factory

func Handle

func Handle(contextCreator func(clientID string, ctx *gin.Context) (any, error), stateCleaner func(clientID string), stateCleanupTime time.Duration) func(ctx *gin.Context)

func NewFactory

func NewFactory() *factory

func NewSocket

func NewSocket(connection *websocket.Conn, clientID string) *instance

Types

type Action

type Action[TPayload, TContext any] struct {
	Type      string                       `json:"type"`
	Payload   TPayload                     `json:"payload"`
	Inputs    map[string]map[string]string `json:"inputs"`
	EventData map[string]any               `json:"eventData"`
	Context   TContext                     `json:"-"`
}

type Instance

type Instance interface {
	GetClientId() string
	GetSocketID() string
	Send(action Action[any, any]) error
	Reciever() event_emitter.Event[ParseSocketMessageArguments, ParseSocketMessageArguments]
}

type ParseSocketMessageArguments

type ParseSocketMessageArguments struct {
	Message  []byte
	Context  any
	ClientID string
}

type SessionFactory

type SessionFactory interface {
	AddSession(id string, socket Instance)
	GetSession(id string) (Instance, error)
	GetSessions(selector func(socket Instance) bool) []Instance
	RemoveSession(id string)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL