SocketIO

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2022 License: GPL-3.0 Imports: 8 Imported by: 0

README

socket.io-go-emitter

Build Status

A Golang implementation of socket.io-emitter

This project uses redis. Make sure your environment has redis.

Install and development

To install in your golang project.

$ go get github.com/yosuke-furukawa/socket.io-go-emitter

Usage

Example:

  emitter, _ := SocketIO.NewEmitter(&SocketIO.EmitterOpts{
    Host:"localhost",
    Port:6379,
  })
  emitter.Emit("message", "I love you!!")
Broadcasting and other flags

Possible flags

  • json
  • volatile
  • broadcast
  emitter, _ := SocketIO.NewEmitter(&SocketIO.EmitterOpts{
    Host:"localhost",
    Port:6379,
  })
  emitter.Volatile().Emit("message", "I love you!!")

** Binary Support

  emitter, _ := SocketIO.NewEmitter(&SocketIO.EmitterOpts{
    Host:"localhost",
    Port:6379,
  })
  val := bytes.NewBufferString("I love you!!")
  emitter.EmitBinary("message", val)

Documentation

Index

Constants

View Source
const (
	UID          = "emitter"
	EVENT        = 2
	BINARY_EVENT = 5
)

Variables

This section is empty.

Functions

func HasBinary

func HasBinary(dataSlice ...interface{}) bool

Types

type BroadcastOpts

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

type Emitter

type Emitter struct {
	Key string

	*BroadcastOpts
	// contains filtered or unexported fields
}

func NewEmitter

func NewEmitter(opts *EmitterOpts) (*Emitter, error)

Emitter constructor Usage:

SocketIO.NewEmitter(&SocketIO.EmitterOpts{
   Host:"localhost",
   Port:6379,
})

func (*Emitter) Broadcast

func (emitter *Emitter) Broadcast() *Emitter

func (*Emitter) Emit

func (emitter *Emitter) Emit(event string, data ...interface{}) (*Emitter, error)

send the packet by string, json, etc Usage: Emit("event name", "data")

func (*Emitter) EmitBinary

func (emitter *Emitter) EmitBinary(event string, data ...interface{}) (*Emitter, error)

send the packet by binary Usage: EmitBinary("event name", []byte{0x01, 0x02, 0x03})

func (*Emitter) In

func (emitter *Emitter) In(room string) *Emitter

In emits msg to a specific room

func (*Emitter) InRooms

func (emitter *Emitter) InRooms(room string) *Emitter

*

  • Limit emission to a certain `room`. *
  • @param {String} room

func (*Emitter) Join

func (emitter *Emitter) Join() *Emitter

func (*Emitter) Of

func (emitter *Emitter) Of(namespace string) *Emitter

*

  • Limit emission to certain `namespace`. *
  • @param {String} namespace

func (*Emitter) To

func (emitter *Emitter) To(room string) *Emitter

func (*Emitter) Volatile

func (emitter *Emitter) Volatile() *Emitter

type EmitterOpts

type EmitterOpts struct {
	// Host means hostname like localhost
	Host string
	// Port means port number, like 6379
	Port int
	// Key means redis subscribe key
	Key string
	// Protocol, like tcp
	Protocol string
	// Address, like localhost:6379
	Addr string
}

Jump to

Keyboard shortcuts

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