DirectCall

@objcMembers
@objc(SBCDirectCall)
public class DirectCall : NSObject, SBTimerBoardDelegate, CallContextDataSource
extension DirectCall: NSCopying

DirectCall class for a call between two participants. Every call is identified with a unique key.

Call Info Properties

  • User Role of Direct Call

    • Cases:

      • caller: The user who made the call.
      • callee: The user who received the call.

    Since

    1.0.0

    See more

    Declaration

    Swift

    @objc(SBCDirectCallUserRole)
    public enum UserRole : Int, RawRepresentable
  • Call ID of the call. This value is generated from our Sendbird server and is String representation of a UUID

    Since

    1.0.0

    Declaration

    Swift

    public internal(set) var callId: String { get }
  • The UUID form of callId. Useful when dealing with CallKit.

    Since

    1.0.0

    Declaration

    Swift

    public var callUUID: UUID? { get }
  • The caller object.

    Since

    1.0.0

    Declaration

    Swift

    public internal(set) var caller: DirectCallUser? { get }
  • The callee object.

    Since

    1.0.0

    Declaration

    Swift

    public internal(set) var callee: DirectCallUser? { get }
  • Custom items of the DirectCall.

    Since

    1.0.0

    Declaration

    Swift

    public var customItems: [String : String] { get }
  • The remote user of the call.

    guard let remoteUser = self.call.remoteUser else { return }
    self.remoteUserIdLabel.text = remoteUser.userId
    

    Since

    1.0.0

    Declaration

    Swift

    public var remoteUser: DirectCallUser? { get }
  • The local user of the call.

    guard let localUser = self.call.localUser else { return }
    self.localUserIdLabel.text = localUser.userId
    

    Since

    1.0.0

    Declaration

    Swift

    public var localUser: DirectCallUser? { get }
  • The role of the current user.

    Since

    1.0.0

    Declaration

    Swift

    public internal(set) var myRole: UserRole { get }

Call End Info Property

  • Presents DirectCallLog instance that is a history of the call. The value is nil before the call is ended. The value just after ending can be different from the value after syncing with the server.

    Since

    1.1.0

    Declaration

    Swift

    public var callLog: DirectCallLog? { get }
  • User that ended the call. Only exists for ended calls.

    Since

    1.0.0

    Declaration

    Swift

    public var endedBy: DirectCallUser? { get }
  • End Result of the ended call.

    Since

    1.0.0

    Declaration

    Swift

    public var endResult: DirectCallEndResult { get }
  • Boolean value indicating whether the call has ended.

    Since

    1.0.0

    Declaration

    Swift

    public var isEnded: Bool { get }
  • Boolean value indicating whether the call is ongoing.

    Since

    1.2.0

    Declaration

    Swift

    public var isOngoing: Bool { get }
  • The start time of call. Int64 of miliseconds.

    Important

    Returns 0 if the call hasn’t started.

    Since

    1.0.0

    Declaration

    Swift

    public var startedAt: Int64 { get }
  • The ended time of call. Int64 of miliseconds.

    Important

    Returns 0 if the call hasn’t ended.

    Since

    1.0.0

    Declaration

    Swift

    public var endedAt: Int64 { get }
  • The duration of the call. Int64 of miliseconds.

    Important

    Returns 0 if the call hasn’t started.

    Since

    1.0.0

    Declaration

    Swift

    public var duration: Int64 { get }

Audio Properties

  • The audio status of the remote user.

    Since

    1.0.0

    Declaration

    Swift

    public var isRemoteAudioEnabled: Bool { get }
  • The audio status of the local user.

    Since

    1.0.0

    Declaration

    Swift

    public var isLocalAudioEnabled: Bool { get }

Video Properties.

Delegate

Recording Properties

  • Boolean value indicating whether the call is currently being recorded.

    Since

    1.3.0

    Declaration

    Swift

    @available(*, deprecated, message: "isRecording has been changed to `localRecordingStatus`. ")
    public var isRecording: Bool { get }
  • Value indicating the local recording status of the call.

    Since

    1.4.0

    Declaration

    Swift

    public var localRecordingStatus: RecordingStatus { get }
  • Value indicating the remote recording status of the call.

    Since

    1.4.0

    Declaration

    Swift

    public internal(set) var remoteRecordingStatus: RecordingStatus { get }
  • Indicates whether the local user’s screen is being shared.

    Since

    1.5.4

    Declaration

    Swift

    public var isLocalScreenShareEnabled: Bool { get }

User Interaction

  • Accepts the incoming direct call. SendBirdCalls will continue to process the call with the server.

    • Tag: accept(with)

    Since

    1.0.0

    Declaration

    Swift

    @objc(acceptWithParams:)
    public func accept(with params: AcceptParams)

    Parameters

    params

    Set up the call that you’re receiving. Cannot be empty

  • Ends the call. DirectCallDelegate.didEnd(call:) delegate method will be called after successful ending. This delegate will also be called when the remote user ends the call.

    // End a call
    call.end();
    
    // receives the event
    class MyClass: DirectCallDelegate {
        ...
        func didEnd(_ call: DirectCall) {
            //
        }
        ...
    }
    

    Since

    1.0.0

    Declaration

    Swift

    public func end()
  • Ends the call. This method has a closeHandler that is called when the end message is successfully sent to the server.

    Note

    One example of implementing this method is for CallKit implementation, where CXEndCallAction should be fulfilled when call has been ended to ensure that the end command has been sent to the server before the Callkit is terminated and sent to background. Aside from that, you may choose to use the original end() method.

    func provider(_ provider: CXProvider, perform action: CXEndCallAction) {
      // After Authenticating...
    
      // End the call
      call.end {
          action.fulfill()
      };
    }
    

    Since

    1.0.0

    Declaration

    Swift

    public func end(closeHandler: VoidHandler?)
  • Holds the active call.

    Since

    1.8.0

    Declaration

    Swift

    public func hold(completionHandler: ErrorHandler?)
  • Removes the hold that you put on a call.

    Since

    1.8.0

    Declaration

    Swift

    public func unhold(force: Bool, completionHandler: ErrorHandler?)
  • Mutes the audio of local user. Will trigger DirectCallDelegate.didRemoteAudioSettingsChange() delegate method of the remote user. If the remote user changes their audio settings, local user will be notified via same delegate method.

    // mute my microphone
    call.muteMicrophone();
    
    // receives the event
    class MyClass: DirectCallDelegate {
        ...
        func didRemoteAudioSettingsChange(_ call: DirectCall) {
            if (call.isRemoteAudioEnabled) {
                // The peer has been unmuted.
            } else {
                // The peer has been muted.
            }
        }
        ...
    }
    

    Since

    1.0.0

    Declaration

    Swift

    public func muteMicrophone()
  • Unmutes the audio of local user. Will trigger DirectCallDelegate.didRemoteAudioSettingsChange() delegate method of the remote user. If the remote user changes their audio settings, local user will be notified via same delegate method.

    // unmute my microphone
    call.unmuteMicrophone();
    
    // receives the event
    class MyClass: DirectCallDelegate {
        ...
        func didRemoteAudioSettingsChange(_ call: DirectCall) {
            if (call.isRemoteAudioEnabled) {
                // The peer has been unmuted.
            } else {
                // The peer has been muted.
            }
        }
        ...
    }
    

    Since

    1.0.0

    Declaration

    Swift

    public func unmuteMicrophone()

Custom Items

  • Updates custom items of the call.

    Since

    1.0.0

    Declaration

    Swift

    public func updateCustomItems(customItems: [String : String], completionHandler: @escaping CustomItemsHandler)

    Parameters

    customItems

    Custom items of [String: String] to be updated or inserted.

    completionHandler

    Callback completionHandler. Contains custom items, changes custom items, and error.

  • Deletes custom items of the call.

    Since

    1.0.0

    Declaration

    Swift

    public func deleteCustomItems(customItemKeys: [String], completionHandler: @escaping CustomItemsHandler)

    Parameters

    customItemKeys

    Keys of the custom item that you want to delete.

    completionHandler

    Callback completionHandler. Contains custom items, changes custom items, and error.

  • Deletes all custom items of the call.

    Declaration

    Swift

    public func deleteAllCustomItems(completionHandler: @escaping CustomItemsHandler)

    Parameters

    completionHandler

    Callback completionHandler. Contains custom items, changes custom items, and error.

Equatable

  • The hash value of DirectCall.

    Declaration

    Swift

    public override var hash: Int { get }
  • Returns a Boolean value that indicates whether the DirectCall and a given object are equal.

    Declaration

    Swift

    public override func isEqual(_ object: Any?) -> Bool
  • Returns a copied instance of the DirectCall.

    Declaration

    Swift

    public func copy(with zone: NSZone? = nil) -> Any
  • Starts a media recording session of a direct call. Only one ongoing recording session is allowed.

    let options = RecordingOptions(recordingType: .localRemoteAudios, directoryPath: FileManager.default.getDocumentsDirectory())
    
    call.startRecording(options: options) { recorderId, error in
        if let id = recorderId {
            // Recording successfully started
        }
    }
    
    

    Since

    1.3.0

    Declaration

    Swift

    public func startRecording(options: RecordingOptions, recordingStartedHandler: @escaping RecordingStartedHandler)

    Parameters

    options

    An option that is used when creating a recording session. It contains information about the type of the recording and its settings.

    recordingStartedHandler

    A handler that receives the recordingId and an error depending on the result.

  • Stops a media recording session with the specified recordingId, and depending on the result of the recording, calls the didSaveRecording method of a SendBirdRecordingDelegate.

    call.stopRecording(recorderId: recorderId)
    

    Since

    1.3.0

    Declaration

    Swift

    @discardableResult
    public func stopRecording(recordingId: String) -> Bool

    Parameters

    recordingId

    A unique identifier returned through the recordingStartedHandler when the startRecording method is called.

    Return Value

    (discardable) Boolean value that indicates whether the specified recordingId is valid.

  • Starts screen share of the local user. Used with Apple’s ReplayKit.

    let recorder = RPScreenRecorder.shared()
    
    call.startScreenShare { (bufferHandler, error) in
       guard error == nil else { return }
    
       recorder.startCapture { (buffer, bufferType, error) in
           bufferHandler?(buffer, error)
       } completionHandler: { (error) in
           guard error == nil else { return } // Handle error
           // Successfully started screen share
       }
    }
    
    

    Since

    1.5.4

    Declaration

    Swift

    public func startScreenShare(completionHandler: @escaping ((((CMSampleBuffer, Error?) -> Void)?, SBCError?) -> Void))

    Parameters

    completionHandler

    A handler that contains CMSampleBuffer Handler and an error depending on the result. CMSampleBuffer Handler should be called inside the completionHandler of RPScreenRecorder.startCapture.

  • Stops screen share of the local user.

    RPScreenRecorder.stopCapture should be called before calling this method.

    let recorder = RPScreenRecorder.shared()
    ...
    recorder.stopCapture { (error) in
        self.call.stopScreenShare()
    }
    

    Since

    1.5.4

    Declaration

    Swift

    public func stopScreenShare(completionHandler: ErrorHandler? = nil)

    Parameters

    completionHandler

    A handler that contains an error depending on the result.

Video Methods

  • Starts local video. If the callee changes video settings, the caller is notified via the DirectCallDelegate.didRemoteVideoSettingsChange() delegate.

    // Start my local video
    call.startVideo()
    
    // receives the event
    class MyClass: DirectCallDelegate {
        ...
        func didRemoteVideoSettingsChange(_ call: DirectCall) {
            if (call.isRemoteVideoEnabled) {
                // The peer has been unmuted.
            } else {
                // The peer has been muted.
            }
        }
        ...
    }
    

    Since

    1.0.0

    Declaration

    Swift

    public func startVideo()
  • Stops local video. If the callee changes video settings, the caller is notified via the DirectCallDelegate.didRemoteVideoSettingsChange() delegate.

    // Stop my local video
    call.stopVideo()
    
    // receives the event
    class MyClass: DirectCallDelegate {
        ...
        func didRemoteVideoSettingsChange(_ call: DirectCall) {
            if (call.isRemoteVideoEnabled) {
                // The peer has been unmuted.
            } else {
                // The peer has been muted.
            }
        }
        ...
    }
    

    Since

    1.0.0

    Declaration

    Swift

    public func stopVideo()
  • Updates local SendBirdVideoView

    • Tag: updateLocalVideoView(_)

    See

    See Also: SendBirdVideoView

    Since

    1.0.0

    Declaration

    Swift

    public func updateLocalVideoView(_ videoView: SendBirdVideoView)

    Parameters

    videoView
  • Updates remote SendBirdVideoView

    • Tag: updateRemoteVideoView(_)

    Since

    1.0.0

    See

    See Also: SendBirdVideoView

    Declaration

    Swift

    public func updateRemoteVideoView(_ videoView: SendBirdVideoView)

    Parameters

    videoView
  • List of available video devices that support video capture.

    Since

    1.0.0

    See

    See Also: VideoDevice

    Declaration

    Swift

    public var availableVideoDevices: [VideoDevice] { get }
  • Current video device using with capture device.

    Since

    1.0.0

    See

    See Also: VideoDevice

    Declaration

    Swift

    public var currentVideoDevice: VideoDevice? { get }
  • Changes current video device asynchronously and notifies callback on completion.

    Since

    1.0.0

    See

    See Also: VideoDevice

    Declaration

    Swift

    public func selectVideoDevice(_ device: VideoDevice, completionHandler: @escaping ErrorHandler)

    Parameters

    device

    VideoDevice object.

    completionHandler

    Callback completionHandler. Contains error.

  • Toggles the selection between the front and the back camera.

    func flipCamera(call: DirectCall) {
       call.switchCamera { error in
           // do something when error has occurred.
       }
    }
    

    Since

    1.0.3

    See

    See Also: VideoDevice

    Declaration

    Swift

    public func switchCamera(completionHandler: @escaping ErrorHandler)

    Parameters

    completionHandler

    Callback completionHandler. Contains error.

  • Takes a snapshot of remote video view.

    self.call.captureRemoteVideoView { [weak self] (image, error) in
        if let error = error {
           // error handling.
           return
        }
        self?.snapshotImageView.image = image
    }
    

    Since

    1.3.0

    Declaration

    Swift

    public func captureRemoteVideoView(completionHandler: @escaping CaptureVideoViewHandler)

    Parameters

    completionHandler

    Callback completion handler that takes snapshot image or error.

  • Takes a snapshot of local video view.

    self.call.captureLocalVideoView { [weak self] (image, error) in
        if let error = error {
           // error handling.
           return
        }
        self?.snapshotImageView.image = image
    }
    

    Since

    1.3.0

    Declaration

    Swift

    public func captureLocalVideoView(completionHandler: @escaping CaptureVideoViewHandler)

    Parameters

    completionHandler

    Callback completion handler that takes snapshot image or error.