message

package
v4.2.7 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknownMessageType = errors.New("unknown message type")

Functions

This section is empty.

Types

type Direction

type Direction string
const (
	DirectionSendRecv Direction = "sendrecv"
	DirectionSendOnly Direction = "sendonly"
	DirectionRecvOnly Direction = "recvonly"
	DirectionInactive Direction = "inactive"
)

func (Direction) RTPTransceiverDirection

func (d Direction) RTPTransceiverDirection() (webrtc.RTPTransceiverDirection, bool)

type HangUp

type HangUp struct {
	PeerID identifiers.ClientID `json:"peerId"`
}

type JSON

type JSON struct {
	Type Type `json:"type"`
	// Room this message is related to
	Room identifiers.RoomID `json:"room"`
	// Payload content
	Payload json.RawMessage `json:"payload"`
}

type Message

type Message struct {
	// Types 0-10 are reserved for base functionality, others can be used for
	// custom implementations.
	Type Type
	// Room this message is related to
	Room identifiers.RoomID
	// Payload content
	Payload Payload
}

func NewHangUp

func NewHangUp(roomID identifiers.RoomID, payload HangUp) Message

func NewPing added in v4.1.3

func NewPing(roomID identifiers.RoomID) Message

func NewPubTrack

func NewPubTrack(roomID identifiers.RoomID, payload PubTrack) Message

func NewReady

func NewReady(roomID identifiers.RoomID, payload Ready) Message

func NewRoomJoin

func NewRoomJoin(roomID identifiers.RoomID, payload RoomJoin) Message

func NewRoomLeave

func NewRoomLeave(roomID identifiers.RoomID, clientID identifiers.ClientID) Message

func NewSignal

func NewSignal(roomID identifiers.RoomID, payload UserSignal) Message

func NewSubTrack

func NewSubTrack(roomID identifiers.RoomID, payload SubTrack) Message

func NewUsers

func NewUsers(roomID identifiers.RoomID, payload Users) Message

func (Message) MarshalJSON

func (m Message) MarshalJSON() ([]byte, error)

func (*Message) UnmarshalJSON

func (m *Message) UnmarshalJSON(b []byte) error

type Payload

type Payload struct {
	HangUp *HangUp
	// Ready is sent from the client to the server.
	Ready  *Ready
	Signal *UserSignal
	Ping   *Ping
	Pong   *Pong

	PubTrack *PubTrack
	SubTrack *SubTrack

	// RoomJoin is only sent to other server-side clients in the same room.
	RoomJoin *RoomJoin
	// RoomLeave is only sent to other server-side clients in the same room.
	RoomLeave identifiers.ClientID

	// Users is sent as a response to Ready.
	// TODO use PubTrack instead.
	Users *Users
}

Payload should only have a single field set, depending on the type of the message.

type Ping

type Ping struct{}

type Pong added in v4.1.3

type Pong struct{}

type PubTrack

type PubTrack struct {
	// TrackID is the unique track identifier.
	TrackID identifiers.TrackID `json:"trackId"`
	// PubClientID is the ID of the remote client that published the track.
	PubClientID identifiers.ClientID `json:"pubClientId"`
	// PeerID is the original track source.
	PeerID identifiers.PeerID `json:"peerId"`
	// Kind defines whether this is an audio or video track.
	Kind transport.TrackKind `json:"kind"`
	// Type can contain only Add or Remove.
	Type transport.TrackEventType `json:"type"`
}

PubTrack will be sent to the clients whenever a track is published or unpublished.

Note about PubClientID, PeerID and SourceID: these values will be the same for Mesh, but different for SFU.

In the case of a single-node SFU:

  • PubClientID and PeerID will be the same and define the original track source.

In the case of multi-node SFU:

  • PubClientID will be ID of the transport (WebRTC or Server) that published the track to current node.
  • PeerID will be the ID of the original track source (most likely a WebRTC transport)

type Ready

type Ready struct {
	Nickname string `json:"nickname"`
}

type RoomJoin

type RoomJoin struct {
	ClientID identifiers.ClientID `json:"peerId"`
	Metadata string               `json:"metadata"`
}

type Signal

type Signal struct {
	Candidate          *webrtc.ICECandidateInit `json:"candidate,omitempty"`
	Renegotiate        bool                     `json:"renegotiate,omitempty"`
	Type               SignalType               `json:"type"`
	SDP                string                   `json:"sdp,omitempty"`
	TransceiverRequest *TransceiverRequest      `json:"transceiverRequest,omitempty"`
}

type SignalType

type SignalType string
const (
	SignalTypeCandidate          SignalType = "candidate"
	SignalTypeTransceiverRequest SignalType = "transceiverRequest"
	SignalTypeRenegotiate        SignalType = "renegotiate"
	SignalTypeOffer              SignalType = "offer"
	SignalTypePranswer           SignalType = "pranswer"
	SignalTypeAnswer             SignalType = "answer"
	SignalTypeRollback           SignalType = "rollback"
)

func NewSignalTypeFromSDPType

func NewSignalTypeFromSDPType(sdpType webrtc.SDPType) (SignalType, bool)

func (SignalType) SDPType

func (s SignalType) SDPType() (webrtc.SDPType, bool)

type SubTrack

type SubTrack struct {
	TrackID     identifiers.TrackID  `json:"trackId"`
	PubClientID identifiers.ClientID `json:"pubClientId"`
	// Type can contain only Sub or Unsub.
	Type transport.TrackEventType `json:"type"`
}

type TransceiverInit

type TransceiverInit struct {
	Direction Direction `json:"direction,omitempty"`
}

type TransceiverRequest

type TransceiverRequest struct {
	Kind transport.TrackKind `json:"kind"`
	Init TransceiverInit     `json:"init"`
}

type Type

type Type string
const (
	TypeHangUp Type = "hangUp"
	TypeReady  Type = "ready"
	TypeSignal Type = "signal"
	TypePing   Type = "ping"
	TypePong   Type = "pong"

	TypePubTrack Type = "pubTrack"
	TypeSubTrack Type = "subTrack"

	TypeRoomJoin  Type = "wsRoomJoin"
	TypeRoomLeave Type = "wsRoomLeave"

	TypeUsers Type = "users"
)

type UserSignal

type UserSignal struct {
	PeerID identifiers.ClientID `json:"peerId"`
	Signal Signal               `json:"signal"`
}

type Users

type Users struct {
	Initiator identifiers.ClientID            `json:"initiator"`
	PeerIDs   []identifiers.ClientID          `json:"peerIds"`
	Nicknames map[identifiers.ClientID]string `json:"nicknames"`
}

The only thing that's not easy to handle this way are nicknames.

Jump to

Keyboard shortcuts

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