signaling

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2020 License: Apache-2.0 Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Tiny signaling

GoDoc

Simple wrapper for websocket signaling

How to use

Install dependency

go get github.com/andrewdormi/go-tiny-signaling

Using with gin
package main

import (
	"github.com/gin-gonic/gin"
	"github.com/gin-contrib/cors"
	"github.com/andrewdormi/go-tiny-signaling"
)

func main() {
	router := gin.New()
	signalingServer := signaling.NewWebSocketServer()
	signalingServer.On("connect", func(socket *signaling.Socket) {
		socket.On("join", func(data signaling.Payload, callback signaling.CallbackFunc) {
			roomID := data["id"].(string)
			if roomId == "" {
				callback(signaling.Payload{"error": "Invalid id"})
				return
			}
			socket.Join(roomID)
			callback(signaling.Payload{"message": "joined"})
		})
		socket.On("disconnect", func() {

		})
	})

	config := cors.DefaultConfig()
	config.AllowOrigins = []string{"http://google.com"}
	router.Use(cors.New(config))
	router.GET("/ws", gin.WrapH(signalingServer))

	router.Run(":8080")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallbackFunc

type CallbackFunc func(data Payload)

type DisconnectFunc

type DisconnectFunc func(*Socket)

type Message

type Message struct {
	Type  string                 `json:"type"`
	ID    string                 `json:"id"`
	Event string                 `json:"event"`
	Data  map[string]interface{} `json:"data"`
}

type Payload

type Payload map[string]interface{}

type RequestFunc

type RequestFunc func(*Socket, Payload, CallbackFunc)

type Server

type Server struct {
	emission.Emitter
	// contains filtered or unexported fields
}

func NewWebSocketServer

func NewWebSocketServer() *Server

func (*Server) Send added in v0.0.2

func (server *Server) Send(roomID string, event string, data Payload)

func (*Server) ServeHTTP

func (server *Server) ServeHTTP(writer http.ResponseWriter, request *http.Request)

type Socket

type Socket struct {
	emission.Emitter
	ID string
	// contains filtered or unexported fields
}

func (*Socket) Close

func (socket *Socket) Close()

func (*Socket) Join

func (socket *Socket) Join(roomID string)

func (*Socket) Leave

func (socket *Socket) Leave(roomID string)

func (*Socket) Send

func (socket *Socket) Send(event string, data Payload, callback CallbackFunc)

Jump to

Keyboard shortcuts

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