【问题标题】:cordova sip plugin error Uncaught TypeError: Cannot read property 'sip' of undefinedcordova s​​ip 插件错误 Uncaught TypeError: Cannot read property 'sip' of undefined
【发布时间】:2020-06-07 20:55:30
【问题描述】:

我必须使用这个插件在 cordova 中制作一个 android 应用程序:https://github.com/sezerkorkmaz/cordova-plugin-sip 但是当我尝试使用一些插件功能时,我收到了这个错误消息:

index.js:23 Uncaught TypeError: Cannot read property 'sip' of undefinedat Object.register (index.js:23) at HTMLButtonElement。 (index.js:74)注册@index.js:23 (匿名)@index.js:74

这是我的代码,我只想做一些基础知识,如何为别人使用连接函数和调用函数,我对编程很陌生

<!DOCTYPE html>

<html>

<head>

    <meta http-equiv="Content-Security-Policy"content="script-src * data: https://ssl.gstatic.com 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; img-src 'self' data: content:;">
    <meta name="format-detection" content="telephone=no">
    <meta name="msapplication-tap-highlight" content="no">
    <meta name="viewport" content="initial-scale=1, width=device-width, viewport-fit=cover">
    <link rel="stylesheet" type="text/css" href="css/index.css">


    <title>Sip Teste</title>
</head>

<body>
    <div class="app">
        <div>
            <button class="phoneButton" id="connect">Connect</button>
        </div>
        <div>
            <button class="phoneButton" id="disconnect">Disconnect</button>
        </div>
        <div>
            <button class="phoneButton" id="call">Make Call</button>
        </div>
        <div>
            <button class="phoneButton" id="endcall">End Call</button>
        </div>
    </div>

    <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript" src="cordova.js"></script>
    <script type="text/javascript">

    </script>

</body>

</html>

index.js

document.addEventListener('deviceready', sipManager);
var sipManager = {


    register: function () {
        cordova.plugins.sip.login('203', '203', '192.168.1.111:5060', function (e) {

            if (e == 'RegistrationSuccess') {
                console.log(e);
                sipManager.listen();
            } else {
                alert("Registration Failed!");
            }

        }, function (e) { console.log(e) })
    },
    call: function () {
        console.log(cordova)
        cordova.plugins.sip.call('sip:111@192.168.1.111:5060', '203', sipManager.events, sipManager.events)
        alert("ligou")
    },
    listen: function () {
        cordova.plugins.sip.listenCall(sipManager.events, sipManager.events);
    },
    hangup: function () {
        cordova.plugins.sip.hangup(function (e) { console.log(e) }, function (e) { console.log(e) })
    },
    events: function (e) {
        console.log(e);
        if (e == 'Incoming') {
            var r = confirm("Incoming Call");
            if (r == true) {
                cordova.plugins.sip.accept(true, sipManager.events, sipManager.events);
            } else {

            }
        }
        if (e == 'Connected') {
            alert("Connected!");
            sipManager.listen();
        }
        if (e == 'Error') {
            alert("Call Error!");
            sipManager.listen();
        }
        if (e == 'End') {
            alert("Call End!");
            sipManager.listen();
        }


    }
}


document.getElementById("connect").addEventListener("click", () => {
    sipManager.register();
    alert("a")
});

【问题讨论】:

    标签: javascript html cordova plugins sip


    【解决方案1】:

    将此行添加到您的 js 文件并检查:

    声明 const cordova: any;

    【讨论】:

      【解决方案2】:

      我发现问题是标准的Windows命令提示符安装插件不正确,所以我开始使用cmder,一切顺利

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-04-24
        • 1970-01-01
        • 2013-01-15
        • 2016-06-01
        • 2019-02-12
        • 2021-09-20
        • 2021-06-08
        • 1970-01-01
        相关资源
        最近更新 更多