nats_websocket

package module
v0.0.0-...-a02e5fe Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2017 License: MIT Imports: 18 Imported by: 0

README

nats-websocket

WebSocket gateway for nats.io. Supports login by JWT and json/protobuf message formats.

Installation

go get github.com/akaumov/nats-websocket

Unless otherwise noted, the source files are distributed under the MIT License found in the LICENSE.txt file.

Documentation

Index

Constants

View Source
const (
	LOGIN_PREFIX = "login>:"
)

Variables

This section is empty.

Functions

func DefaultPackMessage

func DefaultPackMessage(packetFormat string, messageType MessageType, userId UserId, deviceId DeviceId, data []byte) []byte

Types

type Config

type Config struct {
	ListenInterface string `json:"listenInterface"`
	UrlPattern      string `json:"urlPattern"`
	PacketFormat    string `json:"packetFormat"`
	JwtSecret       string `json:"jwtSecret"`

	NatsAddress       string `json:"natsAddress"`
	NatsPoolSize      int    `json:"natsPoolSize"`
	NatsListenSubject string `json:"natsListenSubject"`
	NatsOutputSubject string `json:"natsOutputSubject"`
}

type Connection

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

Connection wraps user connection.

func NewConnection

func NewConnection(id ConnectionId, ws *websocket.Conn) *Connection

func (*Connection) Close

func (c *Connection) Close(code int, reason string)

func (*Connection) GetInfo

func (c *Connection) GetInfo() (ConnectionId, UserId, DeviceId)

func (*Connection) GetStartTime

func (c *Connection) GetStartTime() time.Time

func (*Connection) IsClosed

func (c *Connection) IsClosed() bool

func (*Connection) IsLoggedIn

func (c *Connection) IsLoggedIn() bool

func (*Connection) Login

func (c *Connection) Login(userId UserId, deviceId DeviceId)

func (*Connection) ReadMessage

func (c *Connection) ReadMessage() (messageType int, p []byte, err error)

func (*Connection) SendBinary

func (c *Connection) SendBinary(message []byte)

func (*Connection) SendText

func (c *Connection) SendText(message []byte)

func (*Connection) UpdateLastPingTime

func (c *Connection) UpdateLastPingTime()

type ConnectionId

type ConnectionId int64

type ConnectionsStats

type ConnectionsStats struct {
	NumberOfUsers                int
	NumberOfDevices              int
	NumberOfNotLoggedConnections int
}

type ConnectionsStorage

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

func NewConnectionsStorage

func NewConnectionsStorage() *ConnectionsStorage

func (*ConnectionsStorage) AddNewConnection

func (s *ConnectionsStorage) AddNewConnection(connection *Connection)

func (*ConnectionsStorage) GetConnectionById

func (s *ConnectionsStorage) GetConnectionById(connectionId ConnectionId) *Connection

func (*ConnectionsStorage) GetDeviceConnection

func (s *ConnectionsStorage) GetDeviceConnection(deviceId DeviceId) *Connection

func (*ConnectionsStorage) GetStats

func (s *ConnectionsStorage) GetStats() ConnectionsStats

func (*ConnectionsStorage) GetUserConnections

func (s *ConnectionsStorage) GetUserConnections(userId UserId) map[DeviceId]*Connection

func (*ConnectionsStorage) OnLogin

func (s *ConnectionsStorage) OnLogin(connection *Connection) *Connection

func (*ConnectionsStorage) RemoveConnection

func (s *ConnectionsStorage) RemoveConnection(connection *Connection)

func (*ConnectionsStorage) RemoveIf

func (s *ConnectionsStorage) RemoveIf(condition func(con *Connection) bool, afterRemove func(con *Connection))

type DeviceId

type DeviceId string

type MessageType

type MessageType int32
const (
	TEXT   MessageType = 0
	BINARY MessageType = 1
)

type NatsWebSocket

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

func New

func New(config *Config) *NatsWebSocket

func NewCustom

func NewCustom(config *Config, packMessageHook PackMessageFunc) *NatsWebSocket

func (*NatsWebSocket) Start

func (w *NatsWebSocket) Start()

func (*NatsWebSocket) Stop

func (w *NatsWebSocket) Stop()

type PackMessageFunc

type PackMessageFunc func(packetFormat string, messageType MessageType, userId UserId, deviceId DeviceId, data []byte) []byte

type Pool

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

func NewPool

func NewPool(size int) *Pool

func (*Pool) Schedule

func (p *Pool) Schedule(task func())

type UserId

type UserId string

Directories

Path Synopsis
cmd
Package pb is a generated protocol buffer package.
Package pb is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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