解析javascript函数到两个不同的按钮onclick

时间:2016-12-15 21:01:21

标签: javascript function sip pjsip

大家好我把下面的功能分成两个单独的功能。功能不起作用,但我没有任何错误的想法? 主要功能:

function sipMute() {
if (oSipSessionCall) {
    var i_ret;
    var bMute = !oSipSessionCall.bMute;
    txtCallStatus.innerHTML = '<i>Mute the call...</i>';
    i_ret = oSipSessionCall.mute('audio'/*could be 'video'*/, bMute);
    if (i_ret != 0) {
        txtCallStatus.innerHTML = '<i>Mute failed</i>';
        return;
    }
    oSipSessionCall.bMute = "Unmute";
}

解析函数:

function sipunMute() {
    if (oSipSessionCall) {
        var i_ret;
        var bMute = !oSipSessionCall.bMute;
        txtCallStatus.innerHTML =  '<i>Unmute the call...</i>';
        i_ret = oSipSessionCall.mute('audio', bMute);
        if (i_ret != 0) {
            txtCallStatus.innerHTML = '<i> Unmute failed</i>';
            return;
        }
        oSipSessionCall.bMute = "Mute";
    }

}

CGRect tableFrame = tableView.frame;
tableFrame.size.height = tableView.contentSize.height;
tableView.frame = tableFrame;

scrollView.contentSize = tableView.contentSize;

2 个答案:

答案 0 :(得分:0)

由于以下原因,您的两个功能都在切换当前状态:

var bMute = !oSipSessionCall.bMute;

一个功能应设为true,另一个功能设为false

function sipMute() {
    if (oSipSessionCall) {
        var i_ret;
        var bMute = true;
        txtCallStatus.innerHTML = '<i>Mute the call...</i>';
        i_ret = oSipSessionCall.mute('audio'/*could be 'video'*/, bMute);
        if (i_ret != 0) {
            txtCallStatus.innerHTML = '<i>Mute failed</i>';
            return;
        }
        oSipSessionCall.bMute = bMute;
        // btnMute.value = "Unmute";
}

function sipunMute() {
    if (oSipSessionCall) {
        var i_ret;
        var bMute = false;
        txtCallStatus.innerHTML =  '<i>Unmute the call...</i>'
        i_ret = oSipSessionCall.mute('audio', bMute);
        if (i_ret != 0) {
            txtCallStatus.innerHTML = '<i> Unmute failed</i>';
            return;
        }
        oSipSessionCall.bMute = bMute;
        //btnMute.value = "Mute";
    }

如果您有两个不同的按钮,例如btnMutebtnUnmute,那么您就不需要btnMute.value...

答案 1 :(得分:0)

假设您的oSipSessionCall.bMute属性的初始状态为false(未静音):

var oSipSessionCall = {
  bMute: false
}

您可以使用单个切换功能来静音和取消静音您的播放器(我假设您使用的是jQuery,而您的按钮具有名称属性toggle):

$('[name=toggle]').on('click', function() {
  var i_ret;

  if (oSipSessionCall) {
    txtCallStatus.innerHTML = oSipSessionCall.bMute ? '<i>Mute the call...</i>' : '<i>Unmute the call...</i>';
    i_ret = oSipSessionCall.mute('audio'/*could be 'video'*/, oSipSessionCall.bMute);

    if (i_ret !== 0) {
      txtCallStatus.innerHTML = '<i>Mute failed</i>';
      return;
    }

    oSipSessionCall.bMute = !oSipSessionCall.bMute;
  }
});