stream

package
v3.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: CC-BY-4.0, MIT Imports: 12 Imported by: ? 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

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

The API provides a handler for a WebSocket stream API.

func New

func New(pingPeriod, pongTimeout time.Duration, allowedWebSocketOrigins []string) *API

New creates a new instance of API. pingPeriod: is the interval, in which is server sends the a ping to the client. pongTimeout: is the duration after the connection will be terminated, when the client does not respond with the pong command.

func (*API) Close

func (a *API) Close()

Close closes all client connections and stops answering new connections.

func (*API) CollectConnectedClientTokens

func (a *API) CollectConnectedClientTokens() []string

CollectConnectedClientTokens returns all tokens of the connected clients.

func (*API) Handle

func (a *API) Handle(ctx *gin.Context)

Handle handles incoming requests. First it upgrades the protocol to the WebSocket protocol and then starts listening for read and writes. swagger:operation GET /stream message streamMessages

Websocket, return newly created messages.

---
schema: ws, wss
produces: [application/json]
security: [clientTokenAuthorizationHeader: [], clientTokenHeader: [], clientTokenQuery: [], basicAuth: []]
responses:
  200:
    description: Ok
    schema:
        $ref: "#/definitions/Message"
  400:
    description: Bad Request
    schema:
        $ref: "#/definitions/Error"
  401:
    description: Unauthorized
    schema:
        $ref: "#/definitions/Error"
  403:
    description: Forbidden
    schema:
        $ref: "#/definitions/Error"
  500:
    description: Server Error
    schema:
        $ref: "#/definitions/Error"

func (*API) Notify

func (a *API) Notify(userID uint, msg *model.MessageExternal)

Notify notifies the clients with the given userID that a new messages was created.

func (*API) NotifyDeletedClient

func (a *API) NotifyDeletedClient(userID uint, token string)

NotifyDeletedClient closes existing connections with the given token.

func (*API) NotifyDeletedUser

func (a *API) NotifyDeletedUser(userID uint) error

NotifyDeletedUser closes existing connections for the given user.

Jump to

Keyboard shortcuts

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