0

我正在尝试使用phonertc 插件为 apache cordova构建一个测试应用程序。我正在关注 wiki,所以我创建了转向服务器,并实现了一个 socket.io 信号服务器。所有这些服务器都在工作。

但是当我尝试构建一个演示应用程序时,在创建项目、添加平台和插件、从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 中导入一些东西吗? 谢谢

4

1 回答 1

1

好的,我换行了

var session = new phonertc.Session(config);

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

现在它可以工作了。

于 2016-08-02T13:54:33.753 回答