我正在尝试使用phonertc plugin for apache cordova构建测试应用。
我正在跟踪Wiki,因此创建了转弯服务器,并实现了socket.io信令服务器。所有这些服务器都在工作。

但是当我尝试构建演示应用程序时,在创建项目之后,添加平台和插件,从the wiki复制,

var config = {
    isInitiator: true,
    turn: {
        host: 'turn:turn.example.com:3478',
        username: 'test',
        password: '123'
    },
    streams: {
        audio: true,
        video: false
    }
}

var session = new phonertc.Session(config);


我得到错误

var session = new phonertc.Session(config);


在chrome上运行演示时。错误是

main.js:27 Uncaught ReferenceError: phonertc is not defined


index.html的完整版本是

<!DOCTYPE html>

<html>
    <head>
        <meta name="format-detection" content="telephone=no">
        <meta name="msapplication-tap-highlight" content="no">
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
        <link rel="stylesheet" type="text/css" href="css/index.css">
        <title>Hello World</title>
    </head>
    <body>
        <div class="app">
            <h1>Apache Cordova</h1>
            <div id="deviceready" class="blink">
                <p class="event listening">Connecting to Device</p>
                <p class="event received">Device is Ready</p>
            </div>
        </div>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
        <script src="js/socket.io-1.4.5.js"></script>
        <script src="js/main.js"></script>
        <script>
            document.addEventListener('deviceready', function() {
                doAll();
            });
        </script>
    </body>
</html>


index.js和cordova.js是来自cordova hello世界的dafault,main.js是

var socket;
var config;
var session;
function doAll(){
    socket;
    function setup(){
        socket = io.connect("http://192.168.1.121:3000");
        socket.emit("add-user", {"userCode": "1"});

    }
    setup();


    config = {
        isInitiator: true,
        turn: {
            host: 'turn:192.168.1.121:3478',
            username: 'aaaa',
            password: 'bbbb'
        },
        streams: {
            audio: true,
            video: false
        }
    }

    session = new phonertc.Session(config);
    session.on('sendMessage', function (data) {
        socket.emit("private-message",{content:data,userCode:"2"});
    });
    socket.on("add-message", function(data){

            console.log(data.content);
            session.receiveMessage(JSON.parse(data.content));
        });
    session.on('answer', function () {
        console.log('Other client answered!');
    });

    session.on('disconnect', function () {
        console.log('Other client disconnected!');
    });
    session.call();
}


我知道,代码太可怕了,但这只是一个演示。我该如何解决对phonertc的引用?我是否需要在index.html中导入内容?
谢谢

最佳答案

好,我换了线

var session = new phonertc.Session(config);




var session = new cordova.plugins.phonertc.Session(config);


现在可以了。

关于javascript - 未定义phonertc-浏览器上的Cordova phonertc,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38718223/

10-09 16:54