Rendering Live View

Access the Webrtc view to show the Live View

To render the Live Stream or access the Live View, add below view:

let liveView = liveViewObject.remoteViews.first

Connect/disconect live view

To connect live view you will need

  • localView (optional): Currently unused by connect; start sending the phone camera with enableLocalVideo(enable:localView:) — see Two-Way Calling.
  • autoDisconnectTime (optional, Double, seconds): If live view needs to be auto disconnected after a defined period.
  • playbackEndTime (optional): If SD card playback needs to be ended after defined time.
liveViewObject.connect(localView: localView,
    autoDisconnectTime: <seconds as Double>,
    playbackEndTime: <Epoch time>)

To disconnect live view you will need

  • localView (optional): Pass the view given to enableLocalVideo so its capture is stopped as well.
liveViewObject.disconnect(localView: localView)

Observing the status of Live View

To observer the status of the Live View, The following observer can be used:

liveViewObject.onConnected = {
    // the stream is up; hide the spinner
}
liveViewObject.onLiveViewTerminate = {
    // the session was torn down
}
liveViewObject.onError = {
    // a connection error that the SDK will not retry
}
liveViewObject.onReconnect = {
    // the SDK is re-establishing the stream
}
liveViewObject.onTimeout = {
    // the connection did not come up within 30 s
}
liveViewObject.onDataChannelMessage = { (data: Data) in
    // every data-channel message the SDK does not consume itself
    // (RSSI and sensor readings are delivered through $rssi, $temperature, $humidity instead)
}
liveViewObject.onDataChannelOpen = { (isOpen: Bool) in
    // the data channel opened or closed
}
liveViewObject.onDeviceRefresh = { (device: DeviceModel) in
    // the SDK refreshed the device record while reconnecting
}
liveViewObject.onFrameTimeout = {
    // no video frame for 15 s
}
liveViewObject.onStreamEnded = {
    // the camera ended the stream
}
liveViewObject.onStreamFailed = {
    // the stream failed
}

These are optional closure properties — assign them (=); trailing-closure call syntax does not compile. Assign them before connect, and clear them when the screen goes away: the model is cached and outlives the view controller.


Connection state and the data channel

Besides the callbacks, the model exposes its state:

liveViewObject.isConnected        // @Published Bool
liveViewObject.$rssi, .$temperature, .$humidity   // @Published Int?
liveViewObject.connectionState    // plain property: .none, .initiated, .connected, .failed
liveViewObject.isDataChannelOpen  // plain property

isConnected, rssi, temperature and humidity are @Published; connectionState and isDataChannelOpen are plain properties — read them from onConnected / onDataChannelOpen rather than observing them.

The SDK does not check isDataChannelOpen before sending. A siren, two-way-call or playback command sent while the channel is closed is silently lost by WebRTC, so gate those controls on the flag (or on onDataChannelOpen) yourself. The flag is reset by disconnect() but not by terminateConnection, so it can read a stale true after a termination until the next onDataChannelOpen.

retryCount is a switch, not a count. Leave it at the default -1 and the model reconnects automatically — immediately, after a device-status refresh confirms the camera is online or asleep and not in privacy mode — whenever a frame times out (15 s), the connection times out (30 s), or the stream ends or fails. Set it to any other value to disable reconnection and receive onError instead.


Keeping a battery camera awake

Note: The camera should have already started streaming LiveView before making any interactions

Battery cameras are woken by connect itself: when the object was created with wakeup set to true, the SDK calls the wake-up REST endpoint (reason LiveViewStart) and repeats it every 20 s until the stream connects. Nothing to do in the app.

sendWakeupMessageOnLiveStart() sends a wake_up/live_start message over an open data channel. connect on a live object sends it automatically on an existing playback session for the same camera before tearing that session down; it is a no-op when wakeup is false.

liveViewObject.sendWakeupMessageOnLiveStart()

Terminating the connection

To fully tear down the peer connection rather than only detaching the views, The following can be used. It also clears onConnected, onError and onReconnect and sets connectionState to .failed — re-assign the callbacks before calling connect again.

  • privacyEnable (required): Whether the camera is entering privacy mode. true also suppresses automatic reconnection.
liveViewObject.terminateConnection(privacyEnable: Bool)