gecgosio

package module
v0.0.0-...-214f963 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2024 License: GPL-3.0 Imports: 11 Imported by: 1

README

gecgos.io

Gecgos.io is a reimplementation of geckos.io for golang, which is a library for real-time udp client/server communication using WebRTC.

This library is NOT production ready, and is in need of contributors to help improve this project! See Issue #1 for more details.

Install

Install the package with:

go get github.com/lulzsun/gecgos.io

Import it with:

import "github.com/lulzsun/gecgos.io"

Examples

Please take a look at the provided examples in the examples folder for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Broadcast

type Broadcast map[string]*Peer

func (Broadcast) Emit

func (r Broadcast) Emit(e string, msg ...string)

type Cors

type Cors struct {
	Origin             string
	AllowAuthorization bool
}

type EventEmitter

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

func (*EventEmitter) Emit

func (em *EventEmitter) Emit(evt string, args ...interface{}) bool

func (*EventEmitter) Off

func (em *EventEmitter) Off(e string, listener interface{}) bool

func (*EventEmitter) On

func (em *EventEmitter) On(e string, listener interface{}) IEventEmitter

type IEventEmitter

type IEventEmitter interface {
	On(evt string, listener interface{}) IEventEmitter
	Off(e string, listener interface{}) bool
	Emit(evt string, args ...interface{}) bool
}

func CreateEventEmitter

func CreateEventEmitter() IEventEmitter

type Options

type Options struct {
	Ordered bool
	// Only effective when using gecgos.io provided HTTP server
	Cors
	// Disables gecgos.io provided HTTP server
	DisableHttpServer bool
	// If defined, bind only to the given local address if it exists
	BindAddress string
	// Sets a list of external IP addresses of 1:1 (D)NAT and a candidate type for which the external IP address is used.
	// This is useful when you host a server using Pion on an AWS EC2 instance which has a private address, behind a 1:1 DNAT with a public IP (e.g. Elastic IP).
	NAT1To1IPs []string
}

type Peer

type Peer struct {
	Id string

	IEventEmitter
	// contains filtered or unexported fields
}

The server's definition of a client

func (*Peer) AddCandidate

func (p *Peer) AddCandidate(can webrtc.ICECandidateInit) []webrtc.ICECandidateInit

func (*Peer) Broadcast

func (p *Peer) Broadcast(roomIds ...string) Broadcast

Returns a list of peers given roomIds, NOT including sender.

If no roomIds are given, returns all peers from all rooms the sender is in.

If the sender is not in a room, returns no peers.

func (*Peer) Disconnect

func (p *Peer) Disconnect()

func (*Peer) Emit

func (p *Peer) Emit(e string, msg ...string)

Send a message to peer

- e: The event as a string

- msg: The message as a string (optional)

Example usage:

peer.Emit("x", "hello") // with message "hello"
peer.Emit("y", "hello", "world") // with message "hello, world"
peer.Emit("z") // with no message

func (*Peer) Join

func (p *Peer) Join(ids ...string)

func (*Peer) Leave

func (p *Peer) Leave(ids ...string)

func (*Peer) Reliable

func (p *Peer) Reliable(interval int, runs int) *Peer

Will make the next Emit call to be reliable

- interval: The interval between each message in ms

- runs: How many times the message should be sent

Example usage:

peer.Reliable(150, 10).Emit("ping", "hello") // reliable
peer.Emit("pong", "world") // no longer reliable

func (*Peer) Room

func (p *Peer) Room(roomIds ...string) Room

Returns a list of peers given roomIds, including sender.

If no roomIds are given, returns all peers from all rooms the sender is in.

If the sender is not in a room, returns only sender.

func (*Peer) Rooms

func (p *Peer) Rooms() []string

Returns a list of roomIds given a peer

type Room

type Room map[string]*Peer

func (Room) Emit

func (r Room) Emit(e string, msg ...string)

type Server

type Server struct {
	Options

	Rooms map[string]Room
	IEventEmitter
	// contains filtered or unexported fields
}

func Gecgos

func Gecgos(opt *Options) *Server

Instantiate and return a new Gecgos server

func (*Server) CreateConnection

func (s *Server) CreateConnection(w http.ResponseWriter, r *http.Request)

This function will try to prepare a WebRTC connection by first offering the SDP challenge to the potential client https://github.com/geckosio/geckos.io/blob/1d15c1ae8877b62f53fa026de2323c09202b07ab/packages/server/src/wrtc/connectionsManager.ts#L50

func (*Server) Listen

func (s *Server) Listen(port int) error

Make the server listen on a specific port

If DisableHttpHandler is true, Listen() will no longer be blocking

func (*Server) OnConnection

func (s *Server) OnConnection(f func(c *Peer))

func (*Server) OnDisconnect

func (s *Server) OnDisconnect(f func(c *Peer))

func (*Server) SendAdditionalCandidates

func (s *Server) SendAdditionalCandidates(w http.ResponseWriter, r *http.Request)

This function will send the client additional ice candidates to aid in connection https://github.com/geckosio/geckos.io/blob/6ad2535a8f26d6cce0e7af2c4cf7df311622b567/packages/server/src/httpServer/routes.ts#L68

func (*Server) SetRemoteDescription

func (s *Server) SetRemoteDescription(w http.ResponseWriter, r *http.Request)

This function will try to accept the SDP challenge from a potential client https://github.com/geckosio/geckos.io/blob/6ad2535a8f26d6cce0e7af2c4cf7df311622b567/packages/server/src/httpServer/routes.ts#L38

Directories

Path Synopsis
examples
test Module

Jump to

Keyboard shortcuts

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