我已经在 Ionic 平台上实现了视频通话集成,我可以打电话,但我不能静音音频和视频流。为了获取本地流,我使用了 apiRTC.getLocalStreams(),但获取 getLocalStreams 不是一种方法。对于静音音频,我使用了 localStraem.muteAudio()、this.webRTCClient.toggleAudioMute(this.callId)。这里也同样的错误静音音频不是一种方法。有人可以帮我解决这个问题吗?
谢谢你。
这是我的代码
declare var iosrtc;
declare var apiRTC;
declare var apiCC;
const STATE_WAIT = "wait";
const STATE_INCALL = "incall";
const LABEL_CALL = "Call";
const LABEL_HANGOUT = "Hangout";
const COLOR_CALL = "#5cb85c";
const COLOR_HANGOUT = "#d9534f";
@Component({
selector: 'page-home',
templateUrl: 'home.html'
});
export class HomePage {
distantNumber: any;
webRTCClient: any;
infoLabel: any;
buttonLabel: any;
buttonColor: any;
state: any;
localStraem;
callId;
isMute;
constructor(public navCtrl: NavController, public alertCtrl: AlertController, public platform: Platform, public nativeAudio: NativeAudio) {
this.isMute = false;
this.incomingCallHandler = this.incomingCallHandler.bind(this);
this.userMediaErrorHandler = this.userMediaErrorHandler.bind(this);
this.remoteStreamAddedHandler = this.remoteStreamAddedHandler.bind(this);
this.hangupHandler = this.hangupHandler.bind(this);
this.refreshVideoView = this.refreshVideoView.bind(this);
this.sessionReadyHandler = this.sessionReadyHandler.bind(this);
this.userMediaSuccessHandler = this.userMediaSuccessHandler.bind(this);
apiRTC.init({
onReady: this.sessionReadyHandler,
apiKey: "My APIKey",
});
this.nativeAudio.preloadComplex('uniqueI1', 'assets/tone.mp3', 1, 1, 0).then((succ) => {
console.log("suu..........", succ)
}, (err) => {
console.log("err..........", err)
});
this.infoLabel = "Registration Ongoing...";
this.buttonLabel = LABEL_CALL;
this.buttonColor = COLOR_CALL;
this.state = STATE_WAIT;
}
/**
* Call Action
*/
pushCall(event) {
console.log("Push, callState=" + this.state);
if (this.distantNumber && this.state == STATE_WAIT) {
setTimeout(this.refreshVideoView, 4000);
this.webRTCClient.call(this.distantNumber);
} else if (this.state == STATE_INCALL) {
this.state = STATE_WAIT;
this.buttonColor = COLOR_CALL;
this.buttonLabel = LABEL_CALL;
this.webRTCClient.hangUp();
}
}
sessionReadyHandler(e) {
console.log("sessionReadyHandler");
apiRTC.addEventListener("incomingCall", this.incomingCallHandler);
apiRTC.addEventListener("userMediaError", this.userMediaErrorHandler);
apiRTC.addEventListener("remoteStreamAdded", this.remoteStreamAddedHandler);
apiRTC.addEventListener("userMediaSuccess", this.userMediaSuccessHandler);
apiRTC.addEventListener("hangup", this.hangupHandler);
this.webRTCClient = apiCC.session.createWebRTCClient({});
this.infoLabel = "Your local ID : " + apiCC.session.apiCCId;
this.callId = apiCC.session.apiCCId;
this.localStraem= this.webRTCClient.getLocalStreams() // getting here error like getLocalStreams is not a method
// this.localStraem= apiRTC.getLocalStreams() // getting here also same error
}
refreshVideoView() {
if (this.platform.is('ios')) {
console.log("REFRESH");
iosrtc.refreshVideos();
}
}
incomingCallHandler(e) {
console.log("incomingCallHandler");
this.state = STATE_INCALL;
this.buttonColor = COLOR_HANGOUT;
this.buttonLabel = LABEL_HANGOUT;
setTimeout(this.refreshVideoView, 2000);
}
hangupHandler(e) {
console.log("hangupHandler");
this.state = STATE_WAIT;
this.buttonColor = COLOR_CALL;
this.buttonLabel = LABEL_CALL;
this.initMediaElementState(e.detail.callId);
}
;
userMediaSuccessHandler(e) {
console.log("userMediaSuccessHandler", e);
console.log('loca..........' + JSON.stringify(e.detail.stream))
this.webRTCClient.addStreamInDiv(
e.detail.stream,
e.detail.callType,
"mini",
'miniElt-' + e.detail.callId,
{ width: "200px", height: "200px" },
false
);
}
userMediaErrorHandler(e) {
}
muteAudio() {
this.localStraem.muteAudio(); // here mute audio not a method error
console.log('cal......id............' + this.callId)
// this.webRTCClient.toggleAudioMute(this.callId)
// this.localStraem.getAudioTracks()[0].stop();
// this.localStraem.getTracks().forEach((track) => {
// track.stop();
// });
}
unmuteAudio() {
// this.localStraem.unmuteAudio();
this.localStraem.getTracks().forEach((track) => {
track.start();
});
}
remoteStreamAddedHandler(e) {
console.log('mute..........' + this.isMute)
console.log("remoteStreamAddedHandler", e);
this.state = STATE_INCALL;
this.buttonColor = COLOR_HANGOUT;
this.buttonLabel = LABEL_HANGOUT;
this.webRTCClient.addStreamInDiv(
e.detail.stream,
e.detail.callType,
"remote",
'remoteElt-' + e.detail.callId,
{ width: "200px", height: "200px" },
this.isMute
);
setTimeout(this.refreshVideoView, 1000);
}
initMediaElementState(callId) {
this.webRTCClient.removeElementFromDiv('mini', 'miniElt-' + callId);
this.webRTCClient.removeElementFromDiv('remote', 'remoteElt-' + callId);
}
}