phonertc 未定义 - 浏览器上的 Cordova phonertc

phonertc is not defined - Cordova phonertc on browser

我正在尝试使用 phonertc plugin for apache cordova 构建一个 测试应用程序 。 我正在关注 wiki,所以我创建了 turn 服务器,并且我已经实现了一个 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 world 的默认值,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);

现在可以使用了。