实时对讲

1、实时对讲说明

实时对讲功能是语音会议的一种特殊形式,发言人必须抢麦才能发言,只能有人放麦以后,其他人才能抢麦。 

1.1、接口逻辑 

接口调用是采取“请求回调”和“通知回调”的方式和服务端交互。用户发出创建对讲、抢麦等操作时,在对应的sdk的方法参数中有“请求回调”方法,请求的结果直接在参数的回调方法中处理。会议中的成员收到服务端发送过来的消息通过“通知回调”方法 

1.2、业务流程  

  • 用户A创建实时对讲,创建的同时选择用户B、用户C加入 
  • 用户A先被加入到实时对讲会议室中 
  • 用户B和用户C收到请求并同意加入,同时用户A收到用户B和用户C加入的通知消息。 
  • 通过退出接口可以退出实时对讲。 
  • 实时对讲只要有一个人,实时对讲就不会结束,直到所有人退出实时对讲,会议室自动关闭。 

2、实时对讲操作代码示例

创建实时对讲 

我们假设Tony要和John、Smith建立实时对讲,则Tony创建实时会议的代码如下:
  • {
  •  unsigned int matchKey=0;
  •  CStringArray toArr;
  •  int num = 0;
  •  toArr.Add("John的账号");
  •  toArr.Add("Smith的账号");
  •  if((num = toArr.GetSize())== 0)
  •  return -1;  
  •  const char** p=new const char*[num];
  •  for(int i=0;i<num;i++)
  •  {
  •  p[i]=(LPCTSTR)toArr.GetAt(i);
  •  }
  •  int ret=CreateInterphoneMeeting(&matchKey,p,num);
  •  delete []p;
  •  return ret;
  • }
  • 结果回调:
  • void onCreateInterphoneMeeting (unsigned int matchKey, int reason, const char* interphoneid)
  • {
  •  if(!interphoneid)return;
  •  if(reason != EC_Response_Success)
  •  {   
  •  log(“创建实时对讲失败,跳转到失败界面”);
  •  } else
  •  {
  •  log(“创建实时对讲成功,跳转到实时对讲界面”);
  •  }
  • }

接收到实时对讲通知回调消息

John和Smith收到实时对讲的邀请(在通知消息中同时上报了已经加入会议的成员),或者当有人加入实时对讲时,sdk都通过onReceiveInterphoneMeetingMessage上报相关信息,其代码如下: 
  • void onReceiveInterphoneMeetingMessage:( ECInterphoneMsg* pInterphoneMsg)
  • {
  •  if(pInterphoneMsg == NULL || !CGlobalVarManager::m_pCInterPhoneEnterDlg)return;
  •  
  •  switch(pInterphoneMsg->var)
  •  {
  •  case InterphoneMsgType_Invite://邀请加入实时对讲 
  •  CGlobalVarManager::m_pCInterPhoneEnterDlg->ReceiveInviteInterphoneMeetingNotice(pInterphoneMsg);
  •  break;
  •  case InterphoneMsgType_Join:  //加入实时对讲 
  •  CGlobalVarManager::m_pCInterPhoneEnterDlg->ReceiveJoinInterphoneMeetingNotice(pInterphoneMsg);
  •  break;
  •  case InterphoneMsgType_Exit: //     退出实时对讲 
  •  CGlobalVarManager::m_pCInterPhoneEnterDlg->ReceiveExitInterphoneMeetingNotice(pInterphoneMsg);
  •  break;
  •  case InterphoneMsgType_Over: //结束实时对讲
  •  CGlobalVarManager::m_pCInterPhoneEnterDlg->ReceiveDismissInterphoneMeetingNotice(pInterphoneMsg);
  •  break;
  •  case InterphoneMsgType_ControlMic:// 控麦
  •  CGlobalVarManager::m_pCInterPhoneEnterDlg->ReceiveControlMicInterphoneMeetingNotice(pInterphoneMsg);
  •  break;
  •  case InterphoneMsgType_ReleaseMic:// 放麦
  •  CGlobalVarManager::m_pCInterPhoneEnterDlg->ReceiveReleaseMicInterphoneMeetingNotice(pInterphoneMsg);
  •  break;
  •  default:
  •  break;
  •  }}

主动加入实时对讲  

我们假设Eric要主动加入实时对讲,其示例代码如下。 
  • JoinMeeting(MeetingType_Interphone, "实时对讲id", NULL);
  • 结果回调:
  • void onJoinMeeting(int reason, const char* conferenceId)
  • {
  •  if(reason != EC_Response_Success)
  •  {
  •  log(“加入聊天室返回错误码”);
  •  }else
  •   {
  •  log(“加入会议成功”);
  •  }}

退出实时对讲 

  • ExitMeeting("实时对讲id");
  • void onExitMeeting(constchar* conferenceId);
  • {
  •  Log("退出实时对接");
  • }

实时对讲抢麦 

抢麦只有在实时对讲中才起作用,在语音会议中无效。我们假设Tony在实时对讲中抢麦,其示例代码如下: 
  • UINT matchKey = 0;
  • int nRet = ControlInterphoneMic(&matchKey, true, ”对讲ID”);
  • 结果回调:
  • void onControlInterphoneMic(unsignedint matchKey, int reason, const char* controller,const char* interphoneId,bool requestIsControl)
  • {
  •  if(requestIsControl)
  • {
  •  if(reason != EC_Response_Success)
  •  {
  •  log(“抢麦失败”);
  •  }else
  •   {
  •  log(“抢麦成功”);
  •  } } }

实时对讲放麦 

放麦只有在实时对讲中才起作用,在语音会议中无效。我们假设Tony在实时对讲中放麦,其示例代码如下:
  • UINT matchKey = 0;
  • int nRet = ControlInterphoneMic(&matchKey, false, ”对讲ID”);
  • 结果回调:
  • void onControlInterphoneMic(unsignedint matchKey, int reason, const char* controller,const char* interphoneId,bool requestIsControl)
  • {
  •  if(!requestIsControl)
  • {
  •  if(reason != EC_Response_Success)
  •  {
  •  log(“放麦失败”);
  •  }else
  •   {
  •  log(“放麦成功”);
  •  }    } }