mock_server

package
v1.1.22 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

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 RPCCloseHandler

func RPCCloseHandler(args rpc.RPCArgs) rpc.RPCResponse

$ twitch event websocket close

func RPCFireEventSubHandler

func RPCFireEventSubHandler(args rpc.RPCArgs) rpc.RPCResponse

$ twitch event trigger <event> --transport=websocket

func RPCReconnectHandler

func RPCReconnectHandler(args rpc.RPCArgs) rpc.RPCResponse

$ twitch event websocket reconnect

func RPCSubscriptionHandler

func RPCSubscriptionHandler(args rpc.RPCArgs) rpc.RPCResponse

$ twitch event websocket subscription

func ResolveRPCName

func ResolveRPCName(cmd string) string

Resolves console commands to their RPC names defined in the server manager

func StartWebsocketServer

func StartWebsocketServer(enableDebug bool, ip string, port int, enableSSL bool, strictMode bool)

Types

type Client

type Client struct {
	ConnectedAtTimestamp string // RFC3339Nano timestamp indicating when the client connected to the server
	// 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 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 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
}

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
	DisabledAt        *time.Time // Not public; Timestamp of when the subscription was disabled
	Status            string     // Status of the subscription
	SessionClientName string     // Client name of the session this is associated with.

	ClientConnectedAt    string // Time client connected
	ClientDisconnectedAt string // Time client disconnected

	Conditions models.EventsubCondition // Values of the subscription's condition object
}

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 models.EventsubCondition         `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 {
	Data []SubscriptionPostSuccessResponseBody `json:"data"`

	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 models.EventsubCondition `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,omitempty"`
	DisconnectedAt string `json:"disconnected_at,omitempty"`
}

Cross-usage

type WebSocketServer

type WebSocketServer struct {
	ServerId     string // Int representing the ID of the server
	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, string)

func (*WebSocketServer) InitiateRestart

func (ws *WebSocketServer) InitiateRestart()

func (*WebSocketServer) WsPageHandler

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

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