Почему onstream не запускается при соединении (RTCMulticonnection)? - PullRequest
1 голос
/ 26 февраля 2020

Я использую последнюю версию rtcmulticonnection, использую соединение "многие ко многим" с vue, и когда кто-то присоединяется к комнате, событие onNewParticipant срабатывает, но onstream нет.

Я пытался добавить поток addStream, но выбрасывает RTCMultiConnection.js?cd68:683 Peer (xxxxx) does not exist. Renegotiation skipped.

Это мой созданный метод:

this.connection = new RTCMultiConnection();

this.connection.socketURL = 'http://localhost:9001/';

this.connection.socketMessageEvent = 'video-conference';

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

this.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
    };
}

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

var CodecsHandler = this.connection.CodecsHandler;

this.connection.processSdp = (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;
};

this.connection.onNewParticipant = (pId, userPreferences, c) => {
    console.log(pId, userPreferences, c)
}
this.connection.onmessage = (event) => {
    console.log(event)
}
// this.connection.videosContainer = this.$refs.videoChat;
this.connection.onstream = (event) => {
    console.log(event)
    var existing = document.getElementById(event.streamid);
    if (existing && existing.parentNode) {
        existing.parentNode.removeChild(existing);
    }


    if (event.type == 'local') {
        this.videoChat.senderStream = event.stream;
    } else {
        this.videoChat.receiverStream = event.stream;
    }

    // to keep room-id in cache
    localStorage.setItem(this.connection.socketMessageEvent, this.connection.sessionid);

    if (event.type === 'local') {
        this.connection.socket.on('disconnect', function () {
            if (!this.connection.getAllParticipants().length) {
                location.reload();
            }
        });
    }
};

this.connection.onMediaError = (e) => {
    if (e.message === 'Concurrent mic process limit.') {
        if (DetectRTC.audioInputDevices.length <= 1) {
            alert('Please select external microphone. Check github issue number 483.');
            return;
        }

        var secondaryMic = DetectRTC.audioInputDevices[1].deviceId;
        this.connection.mediaConstraints.audio = {
            deviceId: secondaryMic
        };

        this.connection.join(this.connection.sessionid);
    }
    console.log(e)
};
...