Ionic2 离子2和ApiRTC
我目前正在尝试在ionic 2应用程序中使用ApiRTC API,我希望被调用方能够在发送任何媒体流之前接受或拒绝调用。我正在尝试复制此功能,但在我的情况下,即使在按照文档中的建议设置了webRTCClient.setUserAcceptOnIncomingCall(true)之后,被调用方也不会单击“接受”按钮,呼叫会自动被接受。请参见下面我的实现Ionic2 离子2和ApiRTC,ionic2,webrtc,Ionic2,Webrtc,我目前正在尝试在ionic 2应用程序中使用ApiRTC API,我希望被调用方能够在发送任何媒体流之前接受或拒绝调用。我正在尝试复制此功能,但在我的情况下,即使在按照文档中的建议设置了webRTCClient.setUserAcceptOnIncomingCall(true)之后,被调用方也不会单击“接受”按钮,呼叫会自动被接受。请参见下面我的实现 从'@angular/core'导入{Component}; 从'ionic angular'导入{NavController}; 声明var-
从'@angular/core'导入{Component};
从'ionic angular'导入{NavController};
声明var-apiRTC:any
@组成部分({
选择器:“主页”,
templateUrl:'home.html'
})
导出类主页{
showCall:boolean;
展示:布尔;
回答:布尔;
showReject:布尔型;
showStatus:布尔型;
showmotevideo:boolean=true;
showMyVideo:boolean=true;
一场
网络实时客户端;
incomingCallId=0;
myCallId;
地位
calleeId;
构造函数(公共navCtrl:NavController){
此参数为.InitializeApiRTC();
}
初始化EAPIRTC(){
//apiRTC初始化
apiRTC.init({
apiKey:“,
//APICID:“1”,
onReady:(e)=>{
本节为会议准备就绪的Handler(e);
}
});
}
会话ReadyHandler(e){
this.myCallId=apiRTC.session.apiCCId;
this.initializeControl();
this.AddEventListeners();
this.initializeWebRTClient();
}
初始化控件(){
this.showCall=true;
this.showAnswer=false;
this.showHangup=false;
this.showReject=false;
}
InitializeControlsForIncomingCall(){
this.showCall=false;
this.showAnswer=true;
this.showReject=true;
this.showHangup=true;
}
InitializeControlsForHangup(){
this.showCall=true;
this.showAnswer=false;
this.showReject=false;
this.showHangup=false;
}
UpdateControlsOnAnswer(){
this.showAnswer=false;
this.showReject=false;
this.showHangup=true;
this.showCall=false;
}
UpdateControlsOnReject(){
this.showAnswer=false;
this.showReject=false;
this.showHangup=false;
this.showCall=true;
}
RemoveMediaElements(callId){
this.webrtclient.removeElementFromDiv('mini','miniElt-'+callId);
this.webrtclient.removeElementFromDiv('remote','remoteElt-'+callId);
}
AddStreamInDiv(流、调用类型、divId、mediaEltId、样式、静音){
设mediaElt=null;
设divElement=null;
如果(调用类型==='audio'){
mediaElt=document.createElement(“音频”);
}否则{
mediaElt=document.createElement(“视频”);
}
mediaElt.id=mediaEltId;
mediaElt.autoplay=true;
mediaElt.muted=静音;
mediaElt.style.width=style.width;
mediaElt.style.height=style.height;
divElement=document.getElementById(divId);
divElement.appendChild(mediaElt);
this.webrtclient.attachMediaStream(mediaElt,stream);
}
AddEventListeners(){
apiRTC.addEventListener(“userMediaSuccess”,(e)=>{
this.status=“您正在调用“+e.detail.remoteId+”
”;
this.status=this.status+“CallID=“+e.detail.CallID+”
;
this.status=this.status+“Call Type=“+e.detail.callType;
this.showStatus=true;
this.showMyVideo=true;
this.webrtclient.addStreamInDiv(e.detail.stream,e.detail.callType,“mini”,“miniElt-”+e.detail.callId{
宽度:“128px”,
高度:“96px”
},对);
/*this.AddStreamInDiv(e.detail.stream,e.detail.callType,“mini”,“miniElt-”+e.detail.callId{
宽度:“128px”,
高度:“96px”
},对)*/
});
apiRTC.addEventListener(“userMediaError”,(e)=>{
this.InitializeControlsForHangup();
this.status=this.status+“
发生了以下错误
”+e;
});
apiRTC.addEventListener(“incomingCall”,(e)=>{
this.InitializeControlsForIncomingCall();
this.incomingCallId=e.detail.callId;
});
apiRTC.addEventListener(“挂起”,(e)=>{
如果(e.detail.lastEstabledCall===true){
this.InitializeControlsForHangup();
}
this.status=this.status+“
由于以下原因,呼叫被挂起
”+e.detail.reason;
此.removeMedia元素(如detail.callId);
});
apiRTC.addEventListener(“remoteStreamAdded”,(e)=>{
this.webrtclient.addStreamInDiv(e.detail.stream,e.detail.callType,“remote”,“remoteElt-”+e.detail.callId{
宽度:“300px”,
高度:“225px”
},假);
});
}
初始化WebRTClient(){
this.webRTCClient=apiRTC.session.createWebRTCClient({
状态:“状态”//Optionnal
});
this.webrtclient.setAllowMultipleCalls(true);
这个.webRTCClient.setVideoBandwidth(300);
this.webrtclient.setUserAcceptOnIncomingCall(true);
}
MakeCall(calleeId){
var callId=this.webrtclient.call(calleeId);
if(callId!=null){
this.incomingCallId=callId;
this.showHangup=true;
}
}
挂断{
this.webrtclient.hangUp(this.incomingCallId);
}
应答呼叫(incomingCallId){
this.webrtclient.acceptCall(incomingCallId);
this.UpdateControlsOnAnswer();
}
拒绝呼叫(incomingCallId){
this.webrtclient.refuseCall(incomingCallId);
this.UpdateControlsOnReject();
这。删除中间元素(incomingCallId);
}
}
调用Demo-{myCallId}
呼叫ID:
呼叫
挂断
答复
拒绝
远程流
function webRTCClientCreatedHandler(e) {
this.webRTCClient.setAllowMultipleCalls(true);
this.webRTCClient.setVideoBandwidth(300);
this.webRTCClient.setUserAcceptOnIncomingCall(true);
}
apiRTC.addEventListener("webRTCClientCreated", webRTCClientCreatedHandler);