call

package
v0.251.1 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 20 Imported by: 0 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.

Documentation

Overview

Package call is the media server of calls in chats: everybody on a call sends their microphone, and their camera when it is on, to the server once, and the server forwards each of those to everybody else on the call without mixing it (a selective forwarding unit). A phone sends its microphone once and its camera in two sizes however many people are on the call; each person is sent the whole picture of whoever they feature and the small one of the rest (video.go), and is told who is speaking (speaker.go).

One port of each kind carries every call: UDP, and TCP for networks that let no UDP through. The server's public address is what it tells the devices to send to. The server is an ICE-lite agent: it is reachable at that address, so a device needs to tell it nothing about its own; the server answers whatever reaches it.

Signaling is the caller's: Join answers a device's offer, and every later change (somebody's stream to add or take away) is an offer from the server, handed to the signal function given at Join, which the device answers with Answer. Only the server offers after the first exchange, so the two sides never offer at once.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotOnCall is a device answering for a call it has not joined.
	ErrNotOnCall = errors.New("call: not on the call")

	// ErrClosed is the media server stopped.
	ErrClosed = errors.New("call: the media server is stopped")
)

Functions

This section is empty.

Types

type AudioRecorder

type AudioRecorder func(callId, userId string, packet []byte, codec webrtc.RTPCodecParameters)

AudioRecorder is told each packet of each person's microphone; it keeps those it has been asked to. The packet is the server's to reuse once the call returns.

type RecordedVoice

type RecordedVoice struct {
	UserID    string
	Path      string
	StartedAt time.Time
}

RecordedVoice is one stretch of one person's microphone on a call.

type Recorder

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

Recorder keeps the microphone of everybody on a call being transcribed, each in files of their own: the server hears each person apart, so whose words are whose is known without guessing. A file holds one stretch of one person's microphone; a person who leaves and joins again has a file for each time.

A stretch is cut into files of at most recordingPieceDuration, each short enough to be transcribed at once.

The files are kept under the directory given, on this server's disk, until the call's recording is made from them: a server that stops before then finds them again when it starts (Finish reads the directory, not what this process remembers).

func NewRecorder

func NewRecorder(directory string) *Recorder

func (*Recorder) Discard

func (self *Recorder) Discard(callId string) error

Discard removes whatever is kept of a call on disk.

func (*Recorder) Finish

func (self *Recorder) Finish(callId string) []RecordedVoice

Finish ends a call's recordings and returns what is kept of it on disk, oldest first, also what a process that stopped kept; the files are the caller's to remove with Discard once read.

func (*Recorder) Record

func (self *Recorder) Record(callId, userId string, packet []byte, codec webrtc.RTPCodecParameters)

Record is the media server's AudioRecorder: it keeps the packet when the call's microphones are wanted.

func (*Recorder) Want

func (self *Recorder) Want(callId string, isWanted bool)

Want starts or stops keeping the microphones on a call: everybody's on it now, and of whoever joins it later.

type Server

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

Server is the media server.

func New

func New(settings Settings) (*Server, error)

New starts listening on the ports and is ready for calls.

func (*Server) Answer

func (self *Server) Answer(callId, userId, answerSDP string) error

Answer is a device's answer to the server's latest offer.

func (*Server) Close

func (self *Server) Close() error

Close ends every call and stops listening.

func (*Server) End

func (self *Server) End(callId string)

End takes everybody off a call.

func (*Server) Feature added in v0.217.0

func (self *Server) Feature(callId, userId, featuredUserId string) error

Feature sets whose camera the person's device is sent whole: the person chosen, or whoever is speaking when featuredUserId is empty. It is the device's own, and goes when it leaves.

func (*Server) IsOn

func (self *Server) IsOn(callId, userId string) bool

IsOn says whether the person has a device on the call on this server.

func (*Server) Join

func (self *Server) Join(callId, userId, offerSDP string, shouldTellSpeaker bool, signal func(Signal)) (string, error)

Join puts a device on a call with its offer, and returns the server's answer. A device already on it for the person is replaced: the person moved to another device, or this one connected again. shouldTellSpeaker says the device is to be told who is speaking; a device that does not read such signals is not sent them.

func (*Server) Leave

func (self *Server) Leave(callId, userId string)

Leave takes the person's device off a call.

func (*Server) SetAudioRecorder

func (self *Server) SetAudioRecorder(recorder AudioRecorder)

SetAudioRecorder sets what is told each microphone packet.

func (*Server) SetDeviceLost

func (self *Server) SetDeviceLost(deviceLost func(callId, userId string))

SetDeviceLost sets what is told when a device's connection fails, after it has been taken off the call: the person is no longer on it, though nothing said so. A device the server takes off itself (it joined again, it left) is not lost.

func (*Server) SpeakingUserID added in v0.217.0

func (self *Server) SpeakingUserID(callId string) string

SpeakingUserID is who is speaking on a call, as far as the server can tell; empty when nobody has yet.

type Settings

type Settings struct {
	// PublicAddress is the address devices send to: the server's own, or the
	// address of the gateway that forwards the ports to it.
	PublicAddress string
	UDPPort       int
	TCPPort       int
}

Settings say where the media server listens and what address it gives.

type Signal

type Signal struct {
	OfferSDP       string
	SpeakingUserID string
}

Signal is something the server tells one device on a call: an offer to answer, or who is speaking now (for a device that asked to be told). An offer can arrive before the device has read the server's answer to its join, so a device takes its join and then each offer one at a time, in that order.

Jump to

Keyboard shortcuts

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