wsapi

package
v24.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package wsapi defines the websocket interface required for the bot

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MessageHandler

type MessageHandler interface {
	HandleRequest(WSMessage, chan<- WSMessage) snowflake.Snowflake
}

MessageHandler is the api of an object that has a HandleRequest MessageHandlerFunc method

func NewMessageHandler

func NewMessageHandler(h MessageHandlerFunc) MessageHandler

NewMessageHandler creates a MessageHandler from the given MessageHandlerFunc

type MessageHandlerFunc

type MessageHandlerFunc func(m WSMessage, resp chan<- WSMessage) snowflake.Snowflake

MessageHandlerFunc is the api of a handler that processes a WSMessage and sends a response back over the response channe;

type MessageType

type MessageType int

MessageType represents the type of data being sent or received over a websocket connection

const (
	Text   MessageType = 1
	Binary MessageType = 2
)

Websocket Message types

func (MessageType) String

func (t MessageType) String() string

type WSClient

type WSClient interface {
	Connect(string, string) error
	Close()
	HandleRequests(context.Context, MessageHandler) error
	SendMessage(msg WSMessage)
}

WSClient is the api for a client that maintains an active websocket connection and hands off messages to be processed.

type WSMessage

type WSMessage struct {
	Ctx             context.Context
	MessageType     MessageType
	MessageContents []byte
}

WSMessage is a struct that wraps a message received or to be sent over a websocket connection

func (WSMessage) String

func (m WSMessage) String() string

Jump to

Keyboard shortcuts

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