AngularJS中的Skype URI按钮问题

skype uri button in angularjs issue

本文关键字:按钮 问题 URI Skype 中的 AngularJS      更新时间:2023-09-26

我正在尝试使用AngularJS将skype按钮添加到我的项目中。代码如下:

.HTML:

<script type="text/javascript" src="http://www.skypeassets.com/i/scom/js/skype-uri.js"></script>
<skype-ui id="SkypeButton_Call_1" participants="participants">
                </skype-ui>

AngularJs:

app.directive("skypeUi", function () {
    return {
        restrict: "E",
        template: "<div></div>",
        replace: true,
        scope: {
            participants: "="
        },
        link: function (scope, element, attrs) {
            Skype.ui({
                "name": "chat",
                "element": attrs.id,
                "participants": scope.participants,
                "imageSize": 32
            });
        }
    };
});

但是当我单击它时,它会打开Skype窗口,同时显示一条错误消息:"请安装Skype应用程序以进行此呼叫或发送消息。 呵呵,我在我的系统上安装了Skype。你能告诉我为什么它会这样显示吗?

有同样的问题...问题是skype-uri.js写得很丑...

它导出全局变量Skype,但它不是具有共享函数的命名空间 - 它是对象实例,正如我发现的那样 - 该实例只能正确初始化一个 Skype 按钮...... 脸掌...

要添加另一个脚本,您需要再次包含该脚本(以创建该对象的新实例),或者从该实例获取构造函数并使用它创建新函数...

这是工作指令:

app.directive("skypeUi", function () {
  var TrueSkype = Skype.constructor;
  return {
    restrict: 'E',
    scope: {
      participants: "="
    },
    link: function (scope, element) {
      var btn = null;
      function removeButton() {
        if (btn) {
          btn.remove();
        }
      }
      scope.$watch('participants', function () {
        removeButton();
        btn = angular.element('<div></div>');
        var id = "SkypeButton_Call_" + Math.random();
        element.append(btn);
        btn.attr('id', id);
        (new TrueSkype()).ui({
          "name": "call",
          "element": id,
          "participants": participants,
          "imageColor": "white",
          "imageSize": 32
        });
      });
      scope.$on('$destroy', removeButton);
    }
  };
});