Documentation
¶
Overview ¶
Package gotgcall is a pure-Go library for streaming audio and video into Telegram group calls. The public API mirrors ntgcalls method names so bot code translates one-to-one.
The library is blob-only: signaling JSON is exchanged through your own MTProto client (typically gogram). Two calls are required:
params, _ := client.CreateCall(chatID)
resp, _ := tg.PhoneJoinGroupCall(... Params: &DataJson{Data: params})
client.Connect(chatID, resp.Updates[...].Call.Params.Data)
client.SetStreamSources(chatID, gotgcall.FromFile("song.mp3"))
See README.md for the full pattern.
Index ¶
- Constants
- Variables
- type CallInfo
- type Client
- func (c *Client) AudioSSRC(chatID int64) (uint32, error)
- func (c *Client) Calls() map[int64]CallInfo
- func (c *Client) Close() error
- func (c *Client) Connect(chatID int64, telegramParams string) error
- func (c *Client) CreateCall(chatID int64) (string, error)
- func (c *Client) GetState(chatID int64) (MediaState, error)
- func (c *Client) Mute(chatID int64) (bool, error)
- func (c *Client) OnConnectionChange(fn func(chatID int64, info NetworkInfo))
- func (c *Client) OnStreamEnd(fn func(chatID int64, t StreamType, d Device, err error))
- func (c *Client) Pause(chatID int64) (bool, error)
- func (c *Client) Resume(chatID int64) (bool, error)
- func (c *Client) SetStreamSources(chatID int64, src Source, opt ...EncodeOptions) error
- func (c *Client) StartRTMP(chatID int64, rtmpURL string) error
- func (c *Client) Stop(chatID int64) error
- func (c *Client) Time(chatID int64) (uint64, error)
- func (c *Client) Unmute(chatID int64) (bool, error)
- type ConnState
- type Device
- type EncodeOptions
- type MediaState
- type NetworkInfo
- type Option
- type SeekableSource
- type Source
- type StreamType
- type Track
Constants ¶
const ( TrackAudio = media.TrackAudio TrackVideo = media.TrackVideo Audio = models.Audio Video = models.Video Microphone = models.Microphone Camera = models.Camera Connecting = models.Connecting Connected = models.Connected Failed = models.Failed Closed = models.Closed Timeout = models.Timeout )
Variables ¶
var ( ErrConnectionExists = models.ErrConnectionExists ErrConnectionNotFound = models.ErrConnectionNotFound ErrConnectionTimeout = models.ErrConnectionTimeout ErrConnectionFailed = models.ErrConnectionFailed ErrInvalidParams = models.ErrInvalidParams ErrFFmpegSpawn = models.ErrFFmpegSpawn ErrFFmpegCrashed = models.ErrFFmpegCrashed ErrFile = models.ErrFile ErrClosed = models.ErrClosed ErrInternal = models.ErrInternal ErrNotConnected = models.ErrNotConnected ErrWrongMode = models.ErrWrongMode )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client multiplexes many concurrent group calls behind a single process-wide handle. Safe for concurrent use.
func (*Client) AudioSSRC ¶
AudioSSRC returns the audio SSRC of a WebRTC call. Pass as Source to phone.LeaveGroupCall. Returns ErrWrongMode for RTMP calls.
func (*Client) CreateCall ¶
CreateCall starts a new WebRTC group-call instance for chatID and returns the JSON params the caller must pass to phone.JoinGroupCall.
Concurrent CreateCall / StartRTMP calls for the same chat are serialized; the first one wins, others get ErrConnectionExists without allocating a pion PeerConnection.
func (*Client) GetState ¶
func (c *Client) GetState(chatID int64) (MediaState, error)
GetState returns the current media-state (mute/pause flags).
func (*Client) OnConnectionChange ¶
func (c *Client) OnConnectionChange(fn func(chatID int64, info NetworkInfo))
OnConnectionChange registers a callback for ICE/DTLS state transitions.
func (*Client) OnStreamEnd ¶
func (c *Client) OnStreamEnd(fn func(chatID int64, t StreamType, d Device, err error))
OnStreamEnd registers a callback fired when a track ends (EOF, crash, stop). Called on the dispatcher goroutine so it is safe to re-enter the Client API from within.
func (*Client) SetStreamSources ¶
func (c *Client) SetStreamSources(chatID int64, src Source, opt ...EncodeOptions) error
SetStreamSources installs or replaces the streaming source for chatID.
func (*Client) StartRTMP ¶
StartRTMP creates an RTMP-push call for chatID. The caller obtains rtmpURL via phone.GetGroupCallStreamRtmpUrl gogram-side. Serialised with CreateCall via the same per-chat creation mutex.
func (*Client) Stop ¶
Stop tears down the call and clears every per-chat scrap of state the library kept (call instance, create-mutex). After Stop the chatID can be re-used cleanly.
type EncodeOptions ¶
type EncodeOptions = media.EncodeOptions
type MediaState ¶
type MediaState = models.MediaState
type NetworkInfo ¶
type NetworkInfo = models.NetworkInfo
type Option ¶
type Option func(*config)
func WithDTLSCertPool ¶
WithDTLSCertPool sets the size of the pre-generated DTLS certificate pool. Larger pools absorb bigger call-creation bursts without keygen latency. 0 disables pre-generation.
func WithDispatchBuffer ¶
WithDispatchBuffer sizes the event dispatcher's channel. Default 256.
func WithFFmpegPath ¶
WithFFmpegPath overrides the ffmpeg binary path (default "ffmpeg").
func WithLogger ¶
WithLogger sets a structured logger for internal events.
func WithSharedUDPMux ¶
func WithSharedUDPMux() Option
WithSharedUDPMux makes all calls share one UDP socket for ICE traffic. Useful for high-concurrency setups (100+ simultaneous calls).
type SeekableSource ¶
type SeekableSource = media.SeekableSource
type StreamType ¶
type StreamType = models.StreamType
Directories
¶
| Path | Synopsis |
|---|---|
|
Package instances holds the per-chat call state.
|
Package instances holds the per-chat call state. |
|
jsonparams
Package jsonparams encodes and decodes the SDP-like JSON envelope that Telegram's group-call signaling uses in place of standard SDP O/A.
|
Package jsonparams encodes and decodes the SDP-like JSON envelope that Telegram's group-call signaling uses in place of standard SDP O/A. |