FreeSWITCH 1.10.10 简单图形化界面15 - JsSIP媒体控制
FreeSWITCH界面安装参考:https://blog.csdn.net/jia198810/article/details/137820796
0、 界面预览
用户名:admin,密码:admin
FreeSWITCH界面安装参考:https://blog.csdn.net/jia198810/article/details/137820796
1、本地媒体流
通过JsSIP建立通话后,获取JsSIP.RTCSession类,通过mute()方法可控制是否关闭和开启本地音频或者视频媒体。
可参考JsSIP使用手册https://jssip.net/documentation/api/session/#method_mute
如下:
获取session
javascript
//通过JsSIP.UA的newRTCSession事件获取呼叫session,并通过mute开启关闭本地音频和视频
this.ua.on('newRTCSession', (e) => {
this.currentSession = e.session;
//其他代码
.....
})
本地音频
javascript
//关闭本地音频
//通过options控制是关闭音频还是视频
this.muteLocalAudio = () =>{
//开启音频,则audio:false
this.currentSession.mute(options={audio:true,video:false})
}
本地视频
javascript
//关闭本地视频
//通过options控制是关闭音频还是视频
this.muteLocalVideo = () =>{
//开启视频,则video:false
this.currentSession.mute(options={audio:true,video:true})
}
2、远端媒体流
通过JsSIP建立通话后,获取JsSIP.RTCSession类的confirmed事件获取远端媒体MediaStream对象,然后通过媒体轨道MediaStreamTrack关闭和开启远端媒体。
可参考web开发手册https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack/enabled
如下:
获取媒体流
javascript
//获取JsSIP.RTCSession类的confirmed事件获取远端媒体
this.audioReceiver = null;
this.videoReceiver = null;
this.currentSession.on("confirmed", (e) => {
// 分别获取音频和视频
receivers.forEach((receiver) => {
if (receiver.track.kind === "audio") {
audioReceiver = receiver;
} else if (receiver.track.kind === "video") {
videoReceiver = receiver;
}
});
// 播放音频及视频
......
});
远端音频
通过MediaStreamTrack的enabled属性控制媒体轨道
javascript
//关闭远端音频
this.closeRemoteAudio = () =>{
//开启音频,则enabled = true
this.audioReceiver.getAudioTracks()[0].enabled = false
}
远端视频
javascript
//关闭远端视频,黑屏
this.closeRemoteVideo = () =>{
//开启视频,则enabled = true
this.videoReceiver.getVideoTracks()[0].enabled = false
}