首页 > 解决方案 > 科尔多瓦 sip 插件错误未捕获的类型错误:无法读取未定义的属性“sip”

问题描述

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

index.js:23 未捕获的类型错误:无法在 HTMLButtonElement 处读取未定义的 Object.register (index.js:23) 的属性“sip”。(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")
});

标签: javascripthtmlcordovapluginssip

解决方案


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

声明 const cordova: any;


推荐阅读