psig

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

README

# psig

psig defines the data structure over [YoMo](https://github.com/yomorun/yomo) and [Presencejs](https://presence.js.org).

## Usage

`go get github.com/yomorun/psig`

## License

[Apache 2.0](./LICENSE]

Documentation

Overview

Package psig describes the communication protocol.

Index

Constants

View Source
const (
	// SigControl describes Control Signal
	SigControl = "control"
	// SigData describes Data Signal
	SigData = "data"
)
View Source
const (
	// OpChannelJoin describes peer join a channel. If it is client->server, means the peer is requesting to join the channel; if it's server->client, means the peer has joined the channel.
	OpChannelJoin = "channel_join"
	// OpPeerOffline describes peer leave a channel.
	OpPeerOffline = "peer_offline"
	// OpPeerOnline only used in server->client, notify others in the channel that the peer has joined the channel.
	OpPeerOnline = "peer_online"
	// OpState only used in client->client, notify others in the channel that the peer's state has been updated.
	OpState = "peer_state"
)
View Source
const PrscdDataTag uint32 = 0x21

PrscdDataTag is the tag of prscd data.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChannelEvent

type ChannelEvent struct {
	Event string `msgpack:"event"`
	Data  string `msgpack:"data"`
}

ChannelEvent is Presencejs Channel event data structure used in channel.broadcast() and channel.subscribe()

type PrscdContext

type PrscdContext interface {
	// ReadEvent loads event from ctx.
	ReadEvent() (*ChannelEvent, error)
	// WriteEvent writes event to ctx.
	WriteEvent(event *ChannelEvent) error
	// ReadSignalling returns the Signalling.
	ReadSignalling() *Signalling
}

PrscdContext is the context for prscd, you can load events from ctx and write events to it.

func NewContext

func NewContext(ctx serverless.Context, sfnName string) (PrscdContext, error)

NewContext returns context for prscd from serverless.Context. The Context can be used to load events and write events.

type Signalling

type Signalling struct {
	Type    string `msgpack:"t"`              // Type describes the type of signalling, `Data Signal` or `Control Signal`
	OpCode  string `msgpack:"op,omitempty"`   // OpCode describes the operation type of signalling
	Channel string `msgpack:"c"`              // Channel describes the channel
	Sid     string `msgpack:"sid,omitempty"`  // Sid describes the peer id on this node in backend
	Payload []byte `msgpack:"pl,omitempty"`   // Payload describes the payload data of signalling
	Cid     string `msgpack:"p"`              // Cid describes the client id of peer, set by developer
	AppID   string `msgpack:"app,omitempty"`  // AppID describes the app_id
	MeshID  string `msgpack:"mesh,omitempty"` // MeshID describes the mesh_id of this node
}

Signalling describes the message format on this geo-distributed network.

func (*Signalling) Clone

func (sig *Signalling) Clone() Signalling

Clone a signalling.

func (*Signalling) String

func (sig *Signalling) String() string

String returns the string representation of signalling.

Jump to

Keyboard shortcuts

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