GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - hacktronics/ikisocket: 🧬 WebSocket wrapper with event management for Fiber https://github.com/gofiber/fiber. Based on Fiber WebSocket and inspired by Socket.io

BranchesTags
Open more actions menu
 
 

Latest commit

 

History

59 Commits
59 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/ISSUE_TEMPLATE
.github/ISSUE_TEMPLATE
 
 
examples
examples
 
 
.gitignore
.gitignore
 
 
.travis.yml
.travis.yml
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
go.mod
go.mod
 
 
ikisocket.go
ikisocket.go
 
 
ikisocket_test.go
ikisocket_test.go
 
 

Repository files navigation

WebSocket wrapper for Fiber v2 with events support

Go Report Card GoDoc GitHub license

Based on Fiber Websocket and inspired by Socket.io

Upgrade to Fiber v2 details here

Any bug?

Create ad issue following this template

Feature request?

Create ad issue following this template

⚙️ Installation

go get -u github.com/antoniodipinto/ikisocket

📖 ️ Documentation

// Initialize new ikisocket in the callback this will
// execute a callback that expects kws *Websocket Object
New(callback func(kws *Websocket)) func(*fiber.Ctx) error

// Add listener callback for an event into the listeners list
On(event string, callback func(payload *EventPayload))

ikisocket public/global functions (many thanks to Daniel Morawetz)

// Emit the message to a specific socket uuids list
// Ignores all errors
EmitToList(uuids []string, message []byte)

// Emit to a specific socket connection
EmitTo(uuid string, message []byte) error

// Broadcast to all the active connections
// except avoid broadcasting the message to itself
Broadcast(message []byte)

// Fire custom event on all connections
Fire(event string, data []byte) 

Supported events:

// Supported event list
const (
	// Fired when a Text/Binary message is received
	EventMessage = "message"
	// More details here:
	// @url https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers#Pings_and_Pongs_The_Heartbeat_of_WebSockets
	EventPing = "ping"
	EventPong = "pong"
	// Fired on disconnection
	// The error provided in disconnection event
	// is defined in RFC 6455, section 11.7.
	// @url https://github.com/gofiber/websocket/blob/cd4720c435de415b864d975a9ca23a47eaf081ef/websocket.go#L192
	EventDisconnect = "disconnect"
	// Fired on first connection
	EventConnect = "connect"
	// Fired when the connection is actively closed from the server
	EventClose = "close"
	// Fired when some error appears useful also for debugging websockets
	EventError = "error"
)

Event Payload object

// Event Payload is the object that
// stores all the information about the event and
// the connection
type EventPayload struct {
	// The connection object
	Kws *Websocket
	// The name of the event
	Name string
	// Unique connection UUID
	SocketUUID string
	// Optional websocket attributes
	SocketAttributes map[string]string
	// Optional error when are fired events like
	// - Disconnect
	// - Error
	Error error
	// Data is used on Message and on Error event
	Data []byte
}

Socket instance functions

// Set a specific attribute for the specific socket connection
func (kws *Websocket) SetAttribute(key string, attribute string)

// Get socket connection UUID
func (kws *Websocket) GetUUID() string

// Set socket connection UUID
func (kws *Websocket) SetUUID(uuid string)

// Set socket connection UUID
func (kws *Websocket) SetUUID(uuid string)

// Get a specific attribute from the socket attributes
func (kws *Websocket) GetAttribute(key string) string

// Emit the message to a specific socket uuids list
func (kws *Websocket) EmitToList(uuids []string, message []byte) 

// Emit to a specific socket connection
func (kws *Websocket) EmitTo(uuid string, message []byte) error

// Broadcast to all the active connections
// except avoid broadcasting the message to itself
func (kws *Websocket) Broadcast(message []byte, except bool)

// Fire custom event
func (kws *Websocket) Fire(event string, data []byte)

// Emit/Write the message into the given connection
func (kws *Websocket) Emit(message []byte)

// Actively close the connection from the server
func (kws *Websocket) Close() 

⚡️ Examples

About

🧬 WebSocket wrapper with event management for Fiber https://github.com/gofiber/fiber. Based on Fiber WebSocket and inspired by Socket.io

Resources

Readme
MIT license
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.