使用HTTPS时,信号WebRTC服务器未运行,获取PermissionDenied

时间:2014-02-22 16:34:29

标签: javascript node.js https webrtc

尝试使用https在localhost上的simplewebrtc.com上部署代码 服务器代码与https:

的演示有些不同
/*global console*/
var fs = require('fs');

var options = {
    key: fs.readFileSync('./ssl_key/blarg.key'),
    cert: fs.readFileSync('./ssl_crt/blarg.cert')
};

var yetify = require('yetify'),
    config = require('getconfig'),
    uuid = require('node-uuid'),
    app = require('express'),
    https = require('https').createServer(options, app),
    io = require('socket.io').listen(https);

io.sockets.on('connection', function (client) {
    client.resources = {
        screen: false,
        video: true,
        audio: false
    };

    // pass a message to another id
    client.on('message', function (details) {
        var otherClient = io.sockets.sockets[details.to];
        if (!otherClient) return;
        details.from = client.id;
        otherClient.emit('message', details);
    });

    client.on('shareScreen', function () {
        client.resources.screen = true;
    });
.
.
.

});

https.listen(config.server.port);

if (config.uid) process.setuid(config.uid);
console.log(yetify.logo() + ' -- signal master is running at: http://localhost:' + config.server.port);

日志:

GET http://localhost:8888/socket.io/1/?t=1393090153747 net::ERR_EMPTY_RESPONSE

当我点击共享屏幕控制台打印出来时 NavigatorUserMediaError {constraintName: "", message: "", name: "PermissionDeniedError"}

UPDATE
使用https://localhost:8888/socket.io/1/
可以在8888 /,如何工作? 我在chrome:// flags
上启用了屏幕共享的标记 现在视频在一边可见:)
另一方无法播放视频。

更新2
使用https://localhost:8888/socket.io/1/
在另一方面分手的事情,视频和屏幕共享都没有在远程方面工作。

2 个答案:

答案 0 :(得分:1)

连接('http://localhost:8888/socket.io/1/?');到io.connect('https://localhost:8888/socket.io/1/?');在客户端

答案 1 :(得分:0)

/ 全局控制台 /

var fs = require('fs'),
    express = require('express'),
    https = require('https'),
    http = require('http');

var app = express();

app.use(express.static(__dirname));

app.use(function (req, res, next) {

    // Website you wish to allow to connect
    res.setHeader('Access-Control-Allow-Origin', 'https://172.17.20.67');

    // Request methods you wish to allow
    res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');

    // Request headers you wish to allow
    res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');

    // Set to true if you need the website to include cookies in the requests sent
    // to the API (e.g. in case you use sessions)
    res.setHeader('Access-Control-Allow-Credentials', true);

    // Pass to next layer of middleware
    next();
});


var privateKey = fs.readFileSync('./ssl_key/blarg.key'),
    certificate = fs.readFileSync('./ssl_crt/blarg.cert');
    //fs.readFileSync('fakekeys/privatekey.pem').toString(),
    //fs.readFileSync('fakekeys/certificate.pem').toString();

//http.createServer(app).listen(8001);

var yetify = require('yetify'),
    config = require('getconfig'),
    uuid = require('node-uuid'),
    io = require('socket.io').listen(https.createServer({key: privateKey, cert: certificate}, app).listen(8000));

function describeRoom(name) {
    var clients = io.sockets.clients(name);
    var result = {
        clients: {}
    };
    clients.forEach(function (client) {
        result.clients[client.id] = client.resources;
    });
    return result;
}

function safeCb(cb) {
    if (typeof cb === 'function') {
        return cb;
    } else {
        return function () {};
    }
}

io.sockets.on('connection', function (client) {
    client.resources = {
        screen: false,
        video: true,
        audio: false
    };

    // pass a message to another id
    client.on('message', function (details) {
        var otherClient = io.sockets.sockets[details.to];
        if (!otherClient) return;
        details.from = client.id;
        otherClient.emit('message', details);
    });

    client.on('shareScreen', function () {
        client.resources.screen = true;
    });

    client.on('unshareScreen', function (type) {
        client.resources.screen = false;
        if (client.room) removeFeed('screen');
    });

    client.on('join', join);

    function removeFeed(type) {
        io.sockets.in(client.room).emit('remove', {
            id: client.id,
            type: type
        });
    }

    function join(name, cb) {
        // sanity check
        if (typeof name !== 'string') return;
        // leave any existing rooms
        if (client.room) removeFeed();
        safeCb(cb)(null, describeRoom(name))
        client.join(name);
        client.room = name;
    }

    // we don't want to pass "leave" directly because the
    // event type string of "socket end" gets passed too.
    client.on('disconnect', function () {
        removeFeed();
    });
    client.on('leave', removeFeed);

    client.on('create', function (name, cb) {
        if (arguments.length == 2) {
            cb = (typeof cb == 'function') ? cb : function () {};
            name = name || uuid();
        } else {
            cb = name;
            name = uuid();
        }
        // check if exists
        if (io.sockets.clients(name).length) {
            safeCb(cb)('taken');
        } else {
            join(name);
            safeCb(cb)(null, name);
        }
    });
});

if (config.uid) process.setuid(config.uid);

console.log('running on https://localhost:8000 and http://localhost:8001')

以这种方式重写代码。它奏效了。