wsocket

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2020 License: MIT Imports: 7 Imported by: 0

README

wsocket

Go abstraction on top of gorilla websocket with socket.io type functionality

Documentation

Index

Constants

View Source
const (
	REGISTER_SOCKET = iota + 1
	MESSAGE
	PUBLISH_ROOM
	UNPUBLISH_ROOM
	SUBSCRIBE_TO_ROOM
	UNSUBSCRIBE_FROM_ROOM
)

Variables

This section is empty.

Functions

func Connect

func Connect(ws *WebSocket)

Connect the websocket object to the websocket connection

Types

type BroadcastMessage

type BroadcastMessage struct {
	Type     int         `json:"type,omitempty" bson:"type,omitempty"`
	SocketID string      `json:"socketId,omitempty" bson:"socketId,omitempty"`
	Room     string      `json:"room,omitempty" bson:"room,omitempty"`
	Channel  string      `json:"channel,omitempty" bson:"channel,omitempty"`
	Payload  interface{} `json:"payload,omitempty" bson:"payload,omitempty"`
}

type ClientMessage

type ClientMessage struct {
	Type     int         `json:"type,omitempty" bson:"type,omitempty"`
	SocketID string      `json:"socketId,omitempty" bson:"socketId,omitempty"`
	Room     string      `json:"room,omitempty" bson:"room,omitempty"`
	Channel  string      `json:"channel,omitempty" bson:"channel,omitempty"`
	Payload  interface{} `json:"payload,omitempty" bson:"payload,omitempty"`
}

type EmitMessage

type EmitMessage struct {
	Type     int         `json:"type,omitempty" bson:"type,omitempty"`
	SocketID string      `json:"socketId,omitempty" bson:"socketId,omitempty"`
	Channel  string      `json:"channel,omitempty" bson:"channel,omitempty"`
	Payload  interface{} `json:"payload,omitempty" bson:"payload,omitempty"`
	JWT      string      `json:"jwt,omitempty" bson:"jwt,omitempty"`
}

type Socket

type Socket struct {
	WebSocket *WebSocket
	Conn      *websocket.Conn
	Send      chan []byte
	Rooms     map[string]bool
	// PvtRooms  map[string]bool
	SocketID string
}

Socket is a middleman between the websocket connection and the websocket object.

type WebSocket

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

WebSocket maintains the set of active clients and broadcasts messages to the clients.

func Create

func Create() *WebSocket

Create websocket object

func (*WebSocket) Broadcast

func (ws *WebSocket) Broadcast(bms *BroadcastMessage)

Broadcast message to many sockets

func (*WebSocket) Emit

func (ws *WebSocket) Emit(ems *EmitMessage)

Emit message to one socket

func (*WebSocket) Listen

func (ws *WebSocket) Listen()

Listen for socket activity

func (*WebSocket) On

func (ws *WebSocket) On(channel string, handler handlerFunc)

On message from client

Jump to

Keyboard shortcuts

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