Intranet P2P direct connection (no server required)

10.1 Get an XHVoipManager instance and add a VOIPP2PDelegate protocol function

[[XHClient sharedClient].voipP2PManager addDelegate:self];

/*
*Receive a call
* @fromID the ID of who calls
*/
- (void)onCalling:(NSString *)fromID
{
}
/*
*The other side has hung up
* @fromID the other side ID
*/
- (void)onHangup:(NSString *)fromID
{
}
/*
*the other side has canceled the call
* @fromID the other side ID
*/
- (void)onCancled:(NSString *)fromID
{
}


/*
*The call has been refused
* @fromID the other side ID
*/
- (void)onRefused:(NSString *)fromID
{
}


/*
*the other side is busy now
* @fromID the other side ID
*/
- (void)onBusy:(NSString *)fromID
{
}
/*
*the other side has been connected now
* @fromID the other side ID
*/
- (void)onConnected:(NSString *)fromID
{
}
/*
*Connection error
* @fromID error information
*/
- (void)onError:(NSError *)error
{
}
/*
*Hang up successfully,and you can close the connection normally
* @code stop information
*/
-(void)onStop:(NSString *)code
{
}

10.2 XHVoipP2PManager API Description


/**
* Initialize the P2P direct connection
*/
-(void)initStarDirectLink;

/**
* Stop the P2P direct connection
*/
-(void)stopStarDircetLink;

/**
* Set the orientation of the device when shooting
* @param deviceDirection the orientation
*/
- (void)setDeviceDirection:(XHDeviceDirectionEnum) deviceDirection;

/**
* set media type
* @param mediaType type
*/
- (void)setRtcMediaType:(XHRtcMediaTypeEnum) mediaType;

/**
Set video parameters

@param config config parameters
*/
- (void)setVideoConfig:(XHVideoConfig *)config;

/**
Switch camera direction
@return Camera orientation after switching
*/
- (XHCameraDirection)switchCamera;

/*
*Set up your own and the other side's video view
@param selfPreview preview
@param targetView target view
*/
- (void)setupView:(UIView *)selfPreview targetView:(UIView *)targetView;

// --- Caller ---

/**
Start a video call
@param toID call targe
@param completion callback
*/
- (void)call:(NSString *)toID completion:(void(^)(NSError *error))completion;

/**
cancel the video call
@param toID the cancelling target
@param completion callback
*/
- (void)cancel:(NSString *)toID completion:(void(^)(NSError *error))completion;

// --- callee ---

/**
Accept a video call
@param fromID caller ID
@param completion callback
*/
- (void)accept:(NSString *)fromID completion:(void(^)(NSError *error))completion;

/**
Refuse a video call
@param fromID caller ID
@param completion callback
*/
- (void)refuse:(NSString *)fromID completion:(void(^)(NSError *error))completion;

// --- Both sides ---

/**
Hang up the video call
@param fromID the user ID who wants yo hange up
@param completion callback
*/
- (void)hangup:(NSString *)fromID completion:(void(^)(NSError *error))completion;

/**
* Switch audio
@param enable switch
*/
- (void)setAudioEnable:(BOOL) enable;

/**
* Switch Video
@param enable switch
*/
- (void)setVideoEnable:(BOOL) enable;