0

我有 Reactjs 应用程序,其中有一个视频通话概念。我已经使用 RTCMultiConnection 包来实现视频通话。

对等服务器已连接,视频通话在 localhost 中运行良好。

但是,当我在服务器中托管 react js 应用程序(也有 ssl 证书)时,视频通话无法正常工作。

视频通话开始时,onStream 函数未调用,因此未显示用户视频

我已经通过构建托管了 react js 应用程序,并在 Heroku 服务器和 Windows 专用服务器(通过 IIS)中进行了尝试。但是视频通话在任何一个服务器上都不起作用。

如何让视频通话也能在服务器上工作。

我的示例代码:

export function AudioVideoConferenceStart(data, callback) {
var liveOrJoined = data.liveOrJoined;
var callType = data.callType;
var documentData = data.documentData;
var sectionCount = data.sectionCount;
var roomId = data.roomId;
var isChat = data.isChat;
var isOnetoOne = data.isOnetoOne;

globalVar.connection = new RTCMultiConnection();

globalVar.connection.socketURL = defaultVal.ENV === "dev" ? defaultVal.APILINK_DEV : defaultVal.APILINK_PROD;
globalVar.connection.socketMessageEvent = 'video-conference-demo';

globalVar.connection.session = {
    audio: true,
    video: true
};

globalVar.connection.sdpConstraints.mandatory = {
    OfferToReceiveAudio: true,
    OfferToReceiveVideo: true
};

var bitrates = 512;
var resolutions = 'Ultra-HD';
var videoConstraints = {};

if (resolutions == 'HD') {
    videoConstraints = {
        width: {
            ideal: 1280
        },
        height: {
            ideal: 720
        },
        frameRate: 30
    };
}

if (resolutions == 'Ultra-HD') {
    videoConstraints = {
        width: {
            ideal: 1920
        },
        height: {
            ideal: 1080
        },
        frameRate: 30
    };
}

globalVar.connection.mediaConstraints = {
    video: videoConstraints,
    audio: true
};

var CodecsHandler = globalVar.connection.CodecsHandler;
globalVar.connection.processSdp = function (sdp) {
    var codecs = 'vp8';

    if (codecs.length) {
        sdp = CodecsHandler.preferCodec(sdp, codecs.toLowerCase());
    }

    if (resolutions == 'HD') {
        sdp = CodecsHandler.setApplicationSpecificBandwidth(sdp, {
            audio: 128,
            video: bitrates,
            screen: bitrates
        });

        sdp = CodecsHandler.setVideoBitrates(sdp, {
            min: bitrates * 8 * 1024,
            max: bitrates * 8 * 1024,
        });
    }

    if (resolutions == 'Ultra-HD') {
        sdp = CodecsHandler.setApplicationSpecificBandwidth(sdp, {
            audio: 128,
            video: bitrates,
            screen: bitrates
        });

        sdp = CodecsHandler.setVideoBitrates(sdp, {
            min: bitrates * 8 * 1024,
            max: bitrates * 8 * 1024,
        });
    }

    return sdp;
};
globalVar.connection.iceServers = [{
    'urls': [
        'stun:stun.l.google.com:19302',
        'stun:stun1.l.google.com:19302',
        'stun:stun2.l.google.com:19302',
        'stun:stun.l.google.com:19302?transport=udp',
    ]
}];

globalVar.connection.onstream = function (event) {
    alert("Stream Added");
};

globalVar.connection.onstreamended = function (event) {
    alert("stream removed");
};

globalVar.connection.onMediaError = function (e) {
    alert(e.message);
};

// document.getElementById('room-id').value = roomid;
localStorage.setItem(globalVar.connection.socketMessageEvent, roomid);

// auto-join-room
(function reCheckRoomPresence() {
    globalVar.connection.checkPresence(roomid, function (isRoomExist) {
        if (isRoomExist) {
            globalVar.connection.join(roomid);
            return;
        }

        setTimeout(reCheckRoomPresence, 5000);
    });
})();
}
4

0 回答 0