mock_server

package
v1.1.17-prerelease.1 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2023 License: Apache-2.0 Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0

Index

Constants

View Source
const (
	COMMAND_RESPONSE_SUCCESS          int = 0
	COMMAND_RESPONSE_INVALID_CMD      int = 1
	COMMAND_RESPONSE_FAILED_ON_SERVER int = 2
	COMMAND_RESPONSE_MISSING_FLAG     int = 3
)
View Source
const (
	STATUS_ENABLED                            = "enabled"
	STATUS_AUTHORIZATION_REVOKED              = "revoked"
	STATUS_MODERATOR_REMOVED                  = "moderator_removed"
	STATUS_USER_REMOVED                       = "user_removed"
	STATUS_VERSION_REMOVED                    = "version_removed"
	STATUS_WEBSOCKET_DISCONNECTED             = "websocket_disconnected"
	STATUS_WEBSOCKET_FAILED_PING_PONG         = "websocket_failed_ping_pong"
	STATUS_WEBSOCKET_RECEIVED_INBOUND_TRAFFIC = "websocket_received_inbound_traffic"
	STATUS_WEBSOCKET_CONNECTION_UNUSED        = "websocket_connection_unused"
	STATUS_INTERNAL_ERROR                     = "websocket_internal_error"
	STATUS_NETWORK_TIMEOUT                    = "network_timeout"
	STATUS_NETWORK_ERROR                      = "websocket_network_error"
)

Subscription Statuses Only includes status values that apply to WebSocket connections https://dev.twitch.tv/docs/api/reference/#get-eventsub-subscriptions

View Source
const KEEPALIVE_TIMEOUT_SECONDS = 10

Minimum time between messages before the server disconnects a client.

Variables

This section is empty.

Functions

func IsValidSubscriptionStatus

func IsValidSubscriptionStatus(status string) bool

func StartRPCListener

func StartRPCListener() error

func StartWebsocketServer

func StartWebsocketServer(enableDebug bool, port int, strictMode bool)

Types

type Client

type Client struct {
	ConnectedAtTimestamp string
	// contains filtered or unexported fields
}

func (*Client) CloseDirty

func (c *Client) CloseDirty()

func (*Client) CloseWithReason

func (c *Client) CloseWithReason(reason *CloseMessage)

func (*Client) SendMessage

func (c *Client) SendMessage(messageType int, data []byte) error

type CloseMessage

type CloseMessage struct {
	// contains filtered or unexported fields
}

func GetCloseMessageFromCode

func GetCloseMessageFromCode(code int) *CloseMessage

type CommandResponse

type CommandResponse struct {
	ResponseCode   int
	AdditionalInfo string
}

type EmptyStruct

type EmptyStruct struct {
}

Cross-usage

type KeepaliveMessage

type KeepaliveMessage struct {
	Metadata MessageMetadata         `json:"metadata"`
	Payload  KeepaliveMessagePayload `json:"payload"`
}

type KeepaliveMessagePayload

type KeepaliveMessagePayload struct{}

type MessageMetadata

type MessageMetadata struct {
	MessageID        string `json:"message_id"`
	MessageType      string `json:"message_type"`
	MessageTimestamp string `json:"message_timestamp"`

	SubscriptionType    string `json:"subscription_type,omitempty"`
	SubscriptionVersion string `json:"subscription_version,omitempty"`
}

type NotificationMessage

type NotificationMessage struct {
	Metadata MessageMetadata         `json:"metadata"`
	Payload  models.EventsubResponse `json:"payload"`
}

type RPCArgs

type RPCArgs struct {
	Body       string
	ClientName string

	ServerCommand      string
	SubscriptionID     string
	SubscriptionStatus string
	CloseReason        string
}

type ReconnectMessage

type ReconnectMessage struct {
	Metadata MessageMetadata         `json:"metadata"`
	Payload  ReconnectMessagePayload `json:"payload"`
}

type ReconnectMessagePayload

type ReconnectMessagePayload struct {
	Session ReconnectMessagePayloadSession `json:"session"`
}

type ReconnectMessagePayloadSession

type ReconnectMessagePayloadSession struct {
	ID                      string `json:"id"`
	Status                  string `json:"status"`
	KeepaliveTimeoutSeconds *int   `json:"keepalive_timeout_seconds"`
	ReconnectUrl            string `json:"reconnect_url"`
	ConnectedAt             string `json:"connected_at"`
}

type ServerManager

type ServerManager struct {
	// contains filtered or unexported fields
}

func (*ServerManager) HandleRPCCommandClose

func (sm *ServerManager) HandleRPCCommandClose(clientName string, closeCode int) (bool, string)

Handler for RPC command "close" $ twitch event websocket close

func (*ServerManager) HandleRPCCommandReconnect

func (sm *ServerManager) HandleRPCCommandReconnect(messageBody string) bool

Handler for RPC command "reconnect" $ twitch event websocket reconnect

func (*ServerManager) HandleRPCCommandSubscription

func (sm *ServerManager) HandleRPCCommandSubscription(subscriptionStatus string, subscriptionId string) (bool, string)

Handler for RPC command "subscription" $ twitch event websocket subscription

type Subscription

type Subscription struct {
	SubscriptionID    string // Random GUID for the subscription
	ClientID          string // Client ID included in headers
	Type              string // EventSub topic
	Version           string // EventSub topic version
	CreatedAt         string // Timestamp of when the subscription was created
	Status            string // Status of the subscription
	SessionClientName string // Client name of the session this is associated with.
}

type SubscriptionGetSuccessResponse

type SubscriptionGetSuccessResponse struct {
	Total        int         `json:"total"`
	TotalCost    int         `json:"total_cost"`
	MaxTotalCost int         `json:"max_total_cost"`
	Pagination   EmptyStruct `json:"pagination"`

	Data []SubscriptionPostSuccessResponseBody `json:"data"`
}

Response (Success) - GET /eventsub/subscriptions

type SubscriptionPostErrorResponse

type SubscriptionPostErrorResponse struct {
	Error   string `json:"error"`
	Message string `json:"message"`
	Status  int    `json:"status"`
}

Response (Error) - POST /eventsub/subscriptions

type SubscriptionPostRequest

type SubscriptionPostRequest struct {
	Type      string      `json:"type"`
	Version   string      `json:"version"`
	Condition interface{} `json:"condition"`

	Transport SubscriptionPostRequestTransport `json:"transport"`
}

Request - POST /eventsub/subscriptions

type SubscriptionPostRequestTransport

type SubscriptionPostRequestTransport struct {
	Method    string `json:"method"`
	SessionID string `json:"session_id"`
}

Request - POST /eventsub/subscriptions

type SubscriptionPostSuccessResponse

type SubscriptionPostSuccessResponse struct {
	Body SubscriptionPostSuccessResponseBody `json:"body"`

	Total        int `json:"total"`
	MaxTotalCost int `json:"max_total_cost"`
	TotalCost    int `json:"total_cost"`
}

Response (Success) - POST /eventsub/subscriptions

type SubscriptionPostSuccessResponseBody

type SubscriptionPostSuccessResponseBody struct {
	ID        string `json:"id"`
	Status    string `json:"status"`
	Type      string `json:"type"`
	Version   string `json:"version"`
	CreatedAt string `json:"created_at"`
	Cost      int    `json:"cost"`

	Condition EmptyStruct           `json:"condition"`
	Transport SubscriptionTransport `json:"transport"`
}

Response (Success) - POST /eventsub/subscriptions Response (Success) - GET /eventsub/subscriptions

type SubscriptionTransport

type SubscriptionTransport struct {
	Method      string `json:"method"`
	SessionID   string `json:"session_id"`
	ConnectedAt string `json:"connected_at"`
}

Cross-usage

type WebSocketServer

type WebSocketServer struct {
	ServerId string // Int representing the ID of the server
	//ConnectionUrl string // Server's url for people to connect to. Used for messaging in reconnect testing
	DebugEnabled bool // Display debug messages; --debug
	StrictMode   bool // Force stricter production-like qualities; --strict
	Upgrader     websocket.Upgrader

	Clients *util.List[Client] // All connected clients

	Status int // 0 = shut down; 1 = shutting down; 2 = online

	Subscriptions map[string][]Subscription // Active subscriptions on this server -- Accessed via Subscriptions[clientName]

	ReconnectClients *util.List[[]Subscription] // Clients that were part of the last server
	// contains filtered or unexported fields
}

func (*WebSocketServer) GetCurrentSubscriptionsForReconnect

func (ws *WebSocketServer) GetCurrentSubscriptionsForReconnect() *util.List[[]Subscription]

Gets client subscriptions to be transfered to another server. Used during reconnect testing.

func (*WebSocketServer) HandleRPCEventSubForwarding

func (ws *WebSocketServer) HandleRPCEventSubForwarding(eventsubBody string, clientName string) bool

func (*WebSocketServer) InitiateRestart

func (ws *WebSocketServer) InitiateRestart()

func (*WebSocketServer) WsPageHandler

func (ws *WebSocketServer) WsPageHandler(w http.ResponseWriter, r *http.Request)

type WebSocketServerRPC

type WebSocketServerRPC struct{}

func (*WebSocketServerRPC) RemoteFireEventSub

func (wsrpc *WebSocketServerRPC) RemoteFireEventSub(args *RPCArgs, reply *bool) error

RPC function to execute EventSub events on the WebSocket server. May be used to send it to a single client, or all clients.

func (*WebSocketServerRPC) ServerCommand

func (wsrpc *WebSocketServerRPC) ServerCommand(args *RPCArgs, reply *CommandResponse) error

RPC function to attempt to start reconnect testing on the primary WebSocket server

type WelcomeMessage

type WelcomeMessage struct {
	Metadata MessageMetadata       `json:"metadata"`
	Payload  WelcomeMessagePayload `json:"payload"`
}

type WelcomeMessagePayload

type WelcomeMessagePayload struct {
	Session WelcomeMessagePayloadSession `json:"session"`
}

type WelcomeMessagePayloadSession

type WelcomeMessagePayloadSession struct {
	ID                      string  `json:"id"`
	Status                  string  `json:"status"`
	KeepaliveTimeoutSeconds int     `json:"keepalive_timeout_seconds"`
	ReconnectUrl            *string `json:"reconnect_url"`
	ConnectedAt             string  `json:"connected_at"`
}

Jump to

Keyboard shortcuts

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