簡體   English   中英

使用HTTPS時發信號通知WebRTC服務器未運行,獲得PermissionDenied

[英]Signalling WebRTC server not running while using HTTPS, Getting PermissionDenied

嘗試使用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/
事情在另一端破裂,視頻和屏幕共享都無法在遠端運行。

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

/ 全局控制台 /

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')

用這種方式重寫代碼。 有效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM