tencent cloud

Mobile Live Video Broadcasting

AtomicPusher

Baixar
Modo Foco
Tamanho da Fonte
Última atualização: 2026-11-02 17:31:51
Traduzido por IA

Introduction

Typical usage flow: bind the preview view via AtomicPusher.shared.setView(view), start pushing via startPush(config), monitor state for state changes, and release resources via release().

Features

PusherState: Real-time pusher state, including connection state, statistics, and live room info.
PusherEvent: Pusher event callbacks, including error, live ended, kicked out, and other event types.

Subscribable Data

PusherState fields are described below:
Property
Type
Description
networkState
Connection state.
statistics
Pusher runtime statistics.
pusherInfo
Pusher live room info.
totalViewerCount
Int
Total viewer count.

API List

Function
Description
shared
Get the global singleton.
Pusher event publisher.
setView
Set the render view.
startPush
Start pushing (streaming).
stopPush
Stop pushing (streaming).
Update live room configuration.
release
Release pusher resources.
Enable advanced features by key-value pair.

Getting Instance

shared

Get the global singleton.

Observing State and Events

pusherEvent

Pusher event publisher.

View Management

setView

Set the render view. The locally captured video frames will be rendered into the given AtomicLiveView container.
public func setView(_ view: AtomicLiveView) {
fatalError("\\(#function) must be overridden by subclass")
}
Version
Supported since version 3.5.
Parameters
Parameter
Type
Description
view
The render view container.

Push Control

startPush

Start pushing (streaming). Pass in the live room configuration; the SDK will create the push link accordingly.
public func startPush(config: PusherInfo) {
fatalError("\\(#function) must be overridden by subclass")
}
Version
Supported since version 3.5.
Parameters
Parameter
Type
Description
config
Live room configuration.

stopPush

Stop pushing (streaming).
public func stopPush() {
fatalError("\\(#function) must be overridden by subclass")
}
Version
Supported since version 3.5.

updateConfig

Update live room configuration. Call this after startPush to update live room info such as name, cover, category etc.
public func updateConfig(config: PusherInfo, modifyFlag: PusherInfo.ModifyFlag) {
fatalError("\\(#function) must be overridden by subclass")
}
Version
Supported since version 3.5.
Parameters
Parameter
Type
Description
config
Updated configuration.
modifyFlag
PusherInfo.ModifyFlag
Modify flag.

release

Actively release the pusher. After calling, all APIs become no-ops, and internally held underlying resources, state, and event subscriptions will be cleaned up.
public func release() {
fatalError("\\(#function) must be overridden by subclass")
}
Version
Supported since version 3.5.

Advanced Features

enableAdvancedFeature

Advanced feature. Enable an advanced feature by key-value pair. Supported keys depend on the underlying native pusher capability and may evolve over versions.
public func enableAdvancedFeature(key: String, value: Any) {
fatalError("\\(#function) must be overridden by subclass")
}
Version
Supported since version 3.5.
Parameters
Parameter
Type
Description
key
String
Feature key.
value
Any
Feature value, type depends on the specific key.

Data Structures

PusherCode

Atomic pusher error code enum, used to report push operation results and runtime errors.
Enum Value
Value
Description
OK
0
No error, operation succeeded.
ERROR_INVALID_PARAMETER
-1
Invalid parameter.
ERROR_INVALID_STATE
-2
The operation is not allowed in the current state (e.g. startPush again while pushing, updateConfig before startPush).
ERROR_START_PUSH_REQUEST_FAILED
-3
The startPush request chain failed (server / signaling / TRTC). See message for details.
ERROR_UPDATE_CONFIG_REQUEST_FAILED
-4
The updateConfig request chain failed (server / signaling). See message for details.

PusherConnectState

The connection state between the pusher and the push target. State machine (typical transitions):
startPush
DISCONNECTED ─────────────▶ CONNECTING
▲ │
│ │ join/push succeeded
│ ▼
│ CONNECTED
│ │
│ network jitter / dropped, SDK auto-reconnects
│ ▼
│ CONNECTING
│ │
│ reconnect succeeded ─▶ CONNECTED
└───── reconnect failed / stopPush / release
Note:
DISCONNECTED is the initial state; it is also returned to after calling stopPush / release. The auto-reconnect process reuses CONNECTING, without distinguishing "first connection" from "reconnecting".
Enum Value
Value
Description
DISCONNECTED
0
Not connected. Initial state, or after actively stopping the push / final reconnect failure.
CONNECTING
1
Establishing connection. Used for both the first room-join handshake and auto-reconnect after a disconnection.
CONNECTED
2
Connected, the push link is normal.

PusherListener

Pusher event listener, used to receive one-shot events such as push errors, live ended, kicked out, etc. Register/remove listeners via addListener / removeListener.

PusherStatistics

Pusher runtime statistics.
Property
Type
Description
videoWidth
Int
Video width (pixels).
videoHeight
Int
Video height (pixels).
videoFps
Int
Video frame rate (fps).
videoBitrate
Int
Video bitrate (bps).
audioBitrate
Int
Audio bitrate (bps).
rtt
Int
Network round-trip time (milliseconds).
packetLossRate
Int
Network packet loss rate (percentage).

PusherState

Atomic pusher reactive state. Carries the state of AtomicPusher. You can read the current value or subscribe to changes via state.
Property
Type
Description
networkState
Connection state.
statistics
Pusher runtime statistics.
pusherInfo
Pusher live room info.
totalViewerCount
Int
Total viewer count.

PusherInfo

Pusher live room info. Used both as the input parameter of startPush / updateConfig, and carried in state.pusherInfo as the live room info returned from the engine.
Property
Type
Description
liveID
String
Live ID.
liveName
String
Live name.
coverURL
String
Cover URL.
backgroundURL
String
Background URL.
notice
String
Notice.
createTime
Int
Create time.
categoryList
[Int]
Category list.
isPublicVisible
Bool
Whether publicly visible.
metaData
[String: String]
Custom metadata.

Ajuda e Suporte

Esta página foi útil?

comentários