当我想要麦克风静音时,我会使用我得到的媒体流
session.sessionDescriptionHandler.on('userMedia',
onUserMediaObtained.bind(this))
function onUserMediaObtained(stream) {
localMediaStream = stream
}
会话值来自agent.invite()方法。
但是当我接到来电时,在onInvite事件处理程序中:
agent.on('invite', onInvite(dispatch, store))
const onInvite = (dispatch, store) => session => {
if (session.sessionDescriptionHandler) {}
else { //always undefined here}
}
我再次尝试在onaccepted事件处理程序中附加事件
session.on('accepted', onAccepted(dispatch))
有sessionDescriptionHandler对象初始化,但我认为为时已晚,onUserMediaObtained未被触发。
您可以使用会话对象将麦克风静音/取消静音。似乎这两个函数已从Session API页面中删除,但我很确定它仍然有效。
在这个0.7.0 API页面中你指定了https://sipjs.com/api/0.7.0/session/#muteoptions
在这里,我只是用sipjs 11做到了这一点
`const pc = session.sessionDescriptionHandler.peerConnection;
let togglemute = `true/false`;
// this.emit
if (pc.getSenders) {
pc.getSenders().forEach(function (sender) {
if (sender.track) {
sender.track.enabled = !togglemute;
}
});
} else {
pc.getReceivers().forEach(function (receiver) {
if (receiver.track) {
receiver.track.enabled = !togglemute;
}
});
}`
let pc = this.session.sessionDescriptionHandler.peerConnection;
pc.getLocalStreams().forEach(function (stream) {
stream.getAudioTracks().forEach(function (track) {
try {
track.enabled = !track.enabled;
} catch (e) {
toastr.error('Error occured in executing this command.');
console.log(e);
}
});
});