Two-way Audio and Video Call

Last Updated on : 2024-12-30 07:27:56download

Two-way audio and video calls include two-way transmission and call capabilities extended based on the audio and video features. When the SDK sends a call request, it initiates live streaming and starts local audio and video capture. After the peer end answers the call and the P2P channel is connected, two-way audio and video data transmission is implemented.

How it works

Two-way Audio and Video Call

Core methods

Demo Class Method Description Remarks
ThingSmartCameraFactory +(id)cameraWithP2PType:deviceId:delegate: Create a ThingSmartCameraType object One device ID matches one ThingSmartCameraType object.
ThingSmartCallChannel -(void)fetchDeviceCallAbilityByDevId:completion: Check if the device supports two-way video calls -
- (void)launch Start the call service -
- (BOOL)registerCallInterfaceManager: Register call UI management Handle generating, presenting, and closing a call page.
- (BOOL)addDelegate: Add a delegate For more information about ThingSmartCallChannelDelegate, see the rest of this table.
- (BOOL)isOnCalling Specifies whether a call is in progress -
- (void)startCallWithTargetId:timeout:extra:success:failure: Initiate a call The error message is returned in failure.
- (void)handlePushMessage: Handle call push messages -
ThingSmartCallChannelDelegate - (void)callChannel:didReceiveInvalidCall: Invalid call Invalid parameter.
- (void)callChannel:didReceiveInvalidPushCall: Invalid call push message Invalid parameter or expired call session.
- (void)callChannel:didReceiveCallEventsMessage: Intercept all call event messages Not recommended. Use this interface if you want to customize the call flow.
ThingSmartCameraType -(void)connectWithMode: Connect When error -3 or -105 occurs, try reconnection.
- (void)bindLocalVideoView: Bind with a local video rendering view -
- (void)unbindLocalVideoView Unbind from a local video rendering view -
-(int)startLocalVideoCaptureWithVideoInfo: Start local video capture Request permission for the phone camera: NSCameraUsageDescription.
-(int)stopLocalVideoCapture Stop local video capture -
-(int)switchLocalCameraPosition Switch the direction of the phone camera -
- (void)startTalk Start audio talk -
- (void)stopTalk Stop audio talk -
- (int)startVideoTalk Start video talk -
-(int)stopVideoTalk Stop video talk -
- (int)pauseVideoTalk Pause video talk -
- (int)resumeVideoTalk Resume video talk -
-(int)startAudioRecordWithAudioInfo: Start audio capture Request permission for the phone microphone: NSMicrophoneUsageDescription.
-(int)stopAudioRecord Stop audio capture -
- (void)startPreviewWithDefinition: Start live streaming at the specified resolution Get the resolution from the reported device capability and invoke a callback through - (void)cameraDidBeginPreview: in ThingSmartCameraDelegate when live streaming starts.
- (int)stopPreview Stop live streaming Invoke a callback through - (void)cameraDidStopPreview: in ThingSmartCameraDelegate when live streaming is stopped.
-(int)disConnect Disconnect. -
ThingSmartCameraDelegate -(void)cameraInitFailed: Failed to create a ThingSmartCameraType object The P2P type is not supported.
-(void)cameraDidConnected: Connected successfully -
- (void)cameraDidBeginPreview: Live streaming starts successfully -
- (void)camera:didReceiveLocalVideoSampleBuffer:localVideoInfo: Video stream data from phone camera -
- (void)cameraDidBeginTalk: Callback for starting audio talk -
- (void)cameraDidStopTalk: Callback for stopping audio talk -
- (void)cameraDidStartVideoTalk: Callback for starting video talk -
- (void)cameraDidStopVideoTalk: Callback for stopping video talk -
- (void)cameraDidPauseVideoTalk: Callback for pausing video talk -
- (void)cameraDidResumeVideoTalk: Callback for resuming video talk -
- (void)cameraDidStopPreview: Live streaming is stopped successfully -
-(void)camera:didOccurredErrorAtStep:specificErrorCode: Return the failed streaming action and error code Errors might occur when you connect, start, or stop live streaming.

Important notes

  • Request system permissions in advance to collect audio and video data from the users’ mobile phones.
  • When initiating an audio and video call, a large number of atomic interfaces are called. To prevent lag when opening the page, please manage the sequence of interface requests.
  • The device shall enable the two-way video advanced capability to send and receive calls.

Core code

Create a ThingSmartCameraType object

+ (id<ThingSmartCameraType>)cameraWithP2PType:(id)type deviceId:(NSString *)devId delegate:(id<ThingSmartCameraDelegate>)delegate;

- (void)cameraInitFailed:(ThingSmartCameraErrorCode)errorCode;

Connect

- (void)connectWithMode:(ThingSmartCameraConnectMode)mode;

- (void)cameraDidConnected:(id<ThingSmartCameraType>)camera;

Start live streaming

// Start live streaming
- (void)startPreviewWithDefinition:(ThingSmartCameraDefinition)definition;
// Live streaming is started successfully
- (void)cameraDidBeginPreview:(id<ThingSmartCameraType>)camera;

Stop live streaming

// Stop live streaming
- (void)stopPreview;
// Live streaming is stopped successfully
- (void)cameraDidStopPreview:(id<ThingSmartCameraType>)camera;

Disconnect

// Proactively disconnect
- (void)disConnect;
// Passively disconnect
- (void)cameraDisconnected:(id<ThingSmartCameraType>)camera specificErrorCode:(NSInteger)errorCode;

Local video rendering view

// Bind with a custom local video rendering view
- (void)bindLocalVideoView:(UIView<ThingSmartVideoViewType> *)videoView;
// Unbind from a custom local video rendering view
- (void)unbindLocalVideoView:(UIView<ThingSmartVideoViewType> *)videoView;

Audio talk

// Start audio capture
-(int)startAudioRecordWithAudioInfo:(nullable id<ThingSmartLocalAudioInfoType>)audioInfo;
// Start audio talk
- (void)startTalk;
// Completion callback of starting audio talk
- (void)cameraDidBeginTalk:(id<ThingSmartCameraType>)camera;

// Stop audio capture
 -(int)stopAudioRecord;
// Stop audio talk
- (void)stopTalk;
// Completion callback of stopping audio talk
- (void)cameraDidStopTalk:(id<ThingSmartCameraType>)camera;

Video talk

// Enable local camera
-(int)startLocalVideoCaptureWithVideoInfo:(nullable id<ThingSmartLocalVideoInfoType>)videoInfo;

// Disable local camera
 -(int)stopLocalVideoCapture;

// Switch between cameras
 -(int)switchLocalCameraPosition;

// Local video stream
 - (void)camera:(id<ThingSmartCameraType>)camera didReceiveLocalVideoSampleBuffer:(CMSampleBufferRef)sampleBuffer localVideoInfo:(id<ThingSmartLocalVideoInfoType>)localVideoInfo;

// Start video talk
 - (int)startVideoTalk;
// Completion callback of starting video talk
- (void)cameraDidStartVideoTalk:(id<ThingSmartCameraType>)camera;

// Stop video talk
 -(int)stopVideoTalk;
// Completion callback of stopping video talk
- (void)cameraDidStopVideoTalk:(id<ThingSmartCameraType>)camera;

// Pause video talk
 - (int)pauseVideoTalk;
// Completion callback of pausing video talk
- (void)cameraDidPauseVideoTalk:(id<ThingSmartCameraType>)camera;;

// Resume video talk
 - (int)resumeVideoTalk;
// Completion callback of resuming video talk
- (void)cameraDidResumeVideoTalk:(id<ThingSmartCameraType>)camera;

Example

You can refer to the complete process in the SDK sample.