c++程序与web电话操作交互设计

  • A+
所属分类:其他

概述

cpp通过window.onCppSendMessageToJs( messageBody: json )方法向js发送消息

js通过window.onJsSendMessageToCpp( messageBody: json ) 方法向cpp发送消息

消息体:

{
  action_from_js   : 'hang_up', /*dial_up, hang_up, pick_up, get_phone_statue*/ 
  action_result    : 'success', /*success, failed, processing  */
  phone_statue     : 'on_the_phone', /*on_the_phone, free */ 
  current_call_info: {  
    number: '',  
    duration: ''  
  },  
  post_phone_record : {},  
  patch_phone_record: {},  
  message         : {  
    type: '', /* error, warn, tips  */
    text: ''  
  }  
}  

js主动请求的消息, cpp响应时需加上 action_from_jsaction_result

cpp可随时向js发送以下消息(可包含其中的一个或多个):

phone_statue: 电话状态

current_call_info: 当前通话信息

post_phone_record: 告诉网页需新增通话记录

patch_phone_record: 告诉网页需修改通话记录

message: 可调起网页的toast

phone_record 包含的字段(patch_phone_record时必须传id):

id, call_state, user_oprt, start_time, end_time, connect_duration, total_duration, local_uri, remote_uri, rec_file, last_reason, created_at

拨号

//js拨号  
onJsSendMessageToCpp({  
  action: 'dial_up',  
  number_for_dialing_up: '15987654321'  
})  

//cpp响应拨号  
onCppSendMessageToJs({  
  action_from_js: 'dial_up',  
  action_result: 'success', 
  message: {  
    type: 'processing',  
    text: '拨号中'  
  }  
})  

接电话

//js接电话  
onJsSendMessageToCpp({  
  action: 'pick_up'  
})  

//cpp响应接电话  
onCppSendMessageToJs({  
  action_from_js: 'pick_up',  
  action_result: 'success',   
  message: {  
    type: 'failed',  
    text: '电话占线中'  
  }  
})  

挂电话

//js挂电话  
onJsSendMessageToCpp({  
  action: 'hang_up'  
})  

//cpp响应挂电话  
onCppSendMessageToJs({  
  action_from_js: 'hang_up',  
  action_result: 'success', 
  message: {  
    type: 'processing',  
    text: '正在挂断'  
  }  
})  

获取通话状态

//js获取通话状态  
onJsSendMessageToCpp({  
  action: 'get_phone_statue'  
})  

//cpp响应js获取电话状态  
onCppSendMessageToJs({  
  action_from_js   : 'hang_up', 
  action_result: 'success', 
  phone_statue: 'on_the_phone',  
  current_call_info: {  
    number  : '',  
    duration: ''  
  }  
})  

cpp主动向网页发送消息

//cpp主动向网页发送挂电话消息  
onCppSendMessageToJs({  
  message: {  
    type: 'failed',  
    text: '电话已被挂断'  
  },  
  phone_statue: 'free',   
})  

//cpp主动向网页发送来电消息  
onCppSendMessageToJs({  
  message: {  
    type: 'success',  
    text: '15987654321来电'  
  },  
  phone_statue: 'free', 
})  

//cpp主动告诉网页需新增通话记录  
onCppSendMessageToJs({  
  post_phone_record : {/*通话信息*/}  
})  

//cpp主动告诉网页需修改通话记录  
onCppSendMessageToJs({  
  patch_phone_record : {id:'', /*通话信息*/}  
})  

//cpp主动告诉网页其他信息  
onCppSendMessageToJs({  
  message: {  
    type: 'failed',  
    text: '通话被拒绝'  
  },  
})  
onCppSendMessageToJs({  
  message: {  
    type: 'tips',  
    text: '通话服务器连接丢失'  
  },  
})  


//建立录音文件
{
  "patch_phone_record": {
    "id"      : "1234",
    /*通话id*/
    "rec_file": "recorder/test.wav" /*录音文件保存路径*/
  }
}

//通话结束
{
  "patch_phone_record": {
    "id"              : "",
    "end_time"        : "2017-01-01 00:00:00", /*通话结束时间*/
    "connect_duration": 60, /*通话建立时长,接通开始计时,单位秒,注意用long保存*/
    "total_duration"  : 70, /*总通话时长,振铃开始计时,单位秒,注意用long保存*/
    "last_reason"     : "Normal call clearing" 
     /* 挂断时状态,
      * Normal call clearing、
      * Service Unavailable、
      * Decline,分析数据用的数据
      */
  }
}

//通话建立,接通时
{
  "patch_phone_record": {
    "id"        : "",
    "call_state": "GRIF_CALL_IN"
     /* 通话状态,已接,模拟线振铃开始即为接通,数字线信号正常,
      * GRIF_CALL_IN=已接,
      * GRIF_CALL_MISS=未接,
      * GRIF_CALL_OUT=外呼
      */
  }
}

//摘机接听电话
{
  "patch_phone_record": {
    "id"       : "",
    "user_oprt": "摘机" 
    /*客户端手动摘机添加的动作,兼容模拟线已接状态,
     * 如果call_state=GRIF_CALL_IN且user_oprt="摘机"有摘机动作,
     * 为已接听,数字线不需要
     */
  }
}

//来电
{
  "post_phone_record": {
    "id"        : "",
    "call_state": "GRIF_CALL_MISS", /*通话状态,新来电先置为未接*/
    "start_time": "2017-01-01 00:00:01", /*通话开始时间*/
    "local_uri" : "7000", /*本地坐席号码*/
    "remote_uri": "13800001234" /*来电号码*/
  }
}

//外呼
{
  "post_phone_record": {
    "id"        : "",
    "call_state": "GRIF_CALL_OUT",
    "start_time": "",
    "local_uri" : "",
    "remote_uri": "" /*各字段上同*/
  }
}
楚廉

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: