peer

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateRandomNumber

func GenerateRandomNumber() int

func RandInt

func RandInt(min, max int) int

Types

type AcceptFunc

type AcceptFunc func(data map[string]interface{})

type Notification

type Notification struct {
	Notification bool                   `json:"notification"`
	Method       string                 `json:"method"`
	Data         map[string]interface{} `json:"data"`
}

* Notification

{
  notification : true,
  method       : 'chatmessage',
  data         :
  {
    foo : 'bar'
  }
}

type Peer

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

func NewPeer

func NewPeer(id string, transport *transport.WebSocketTransport) *Peer

func (*Peer) Close

func (peer *Peer) Close()

func (*Peer) ID

func (peer *Peer) ID() string

func (*Peer) Notify

func (peer *Peer) Notify(method string, data map[string]interface{})

func (*Peer) Request

func (peer *Peer) Request(method string, data map[string]interface{}, success AcceptFunc, reject RejectFunc)

type RejectFunc

type RejectFunc func(errorCode int, errorReason string)

type Request

type Request struct {
	Request bool                   `json:"request"`
	Id      int                    `json:"id"`
	Method  string                 `json:"method"`
	Data    map[string]interface{} `json:"data"`
}

* Request

{
  request : true,
  id      : 12345678,
  method  : 'chatmessage',
  data    :
  {
    type  : 'text',
    value : 'Hi there!'
  }
}

type Response

type Response struct {
	Response bool                   `json:"response"`
	Id       int                    `json:"id"`
	Ok       bool                   `json:"ok"`
	Data     map[string]interface{} `json:"data"`
}

* Success response

{
	response : true,
	id       : 12345678,
	ok       : true,
	data     :
	{
	  foo : 'lalala'
	}
}

type ResponseError

type ResponseError struct {
	Response    bool   `json:"response"`
	Id          int    `json:"id"`
	Ok          bool   `json:"ok"`
	ErrorCode   int    `json:"errorCode"`
	ErrorReason string `json:"errorReason"`
}

* Error response

{
  response    : true,
  id          : 12345678,
  ok          : false,
  errorCode   : 123,
  errorReason : 'Something failed'
}

type Transcation

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

Jump to

Keyboard shortcuts

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