WebRT C ручной сигнал DOMException unknown ufrag - PullRequest
0 голосов
/ 28 мая 2020

Я пытаюсь узнать о webrt c, и у меня есть код, который предназначен для запуска в двух разных firefox windows на моем ноутбуке, и я копирую соответствующую информацию между консолями разработчика, но я запускаю в ошибку DOMException: "Unknown ufrag (..fragsnippet..)", и я не могу понять, что я испортил. Кто-нибудь знает, что вызывает это?

Я знаю, что серверы сигнализации можно настроить на то, что я делаю, но я хотел разбить шаги, чтобы понять порядок и проверить результат каждого шага. Я включил источник, чтобы любой мог увидеть, возникают ли какие-либо явные проблемы. Для объяснения каждое окно будет называться pc1 или pc2.

шаги

  1. pc1 вызывает initConnection, который создает переменную localcon типа RTCPeerConnection без использования stunServers поскольку в этом примере предполагается использовать локальные ледяные кандидаты

  2. , то мы копируем переменную locOffer, которая уже содержит записи icecandidate

  3. в окне pc2 Я выполняю reactConnection, что делает localcon для этого окна, а затем я вызываю ingestOffer, предоставляя скопированный locOffer из окна pc1, это устанавливает remoteDescription для localcon pc2, а затем создает ответ, который я хотел бы чтобы скопировать обратно на pc1,

    шаги заканчиваются здесь, потому что я сталкиваюсь с ошибкой исключения dom, а localcon для pc2 изменяется на iceConnectionState:fail

Любые идеи о как это исправить было бы очень полезно!

/* new process
create a single pc, and setup binding of candidate stuff and offer stuff to be set, and trigger other parts of the process to continue,
hopefully no servers is going to work
*/
'use strict'


var localcon, remotecon, datachannel, pcconstraint, dataconstraint, recchannel, config

export function setup() {
    var servers = null
    pcconstraint = null
    dataconstraint = null

    config = {
        iceServers: [],
        iceTransportPolicy: "all",
        iceCandidatePoolSize: "0"
    }
    window.ingestOffer = ingestOffer
    window.handleAnswer = handleAnswer
    window.desc1 = desc1
    window.setAnswer = setAnswer
    window.initConnection = initConnection
    window.reactConnection = reactConnection
    // answer will be created in desc1

}
function reactConnection() {
    window.localcon = localcon = new RTCPeerConnection(config)
    localcon.onicecandidate = iceCB2
    // bind different channel events
    localcon.ondatachannel = handleDC
}
function initConnection() {
    window.localcon = localcon = new RTCPeerConnection(config)
    window.datachannel = datachannel = localcon.createDataChannel('sendDataChannel', dataconstraint)
    // bind the ice events
    // attach the datachannel events
    datachannel.onopen = openDC
    datachannel.onclose = closeDC
    localcon.onicecandidate = iceCB1
    localcon.oniceconnectionstatechange = handleConnectionChange
    window.locCanInfo = []
    // start the offers
    localcon.createOffer().then(
        desc1,
        descriptionErr
    )
}
function handleConnectionChange(event) {
    console.log("connection change",event);
    console.log("peer connection ",event.target.iceConnectionState);


}
function openDC () {
    console.log("opening first data channel");

}
function closeDC() {
    console.log("closing first data channel");

}
function handleDC(event) {
    console.log("handling rec channel connect")
    recchannel = event.channel
    recchannel.onmessage = recmessage
    recchannel.onopen = recopen
    recchannel.onclose = recclose

}
function recmessage(event) {
    console.log("rec channel got",event.data);

}
function recopen() {
    console.log("rec channel open");

}
function recclose() {
    console.log("rec channel close");

}
function setAnswer(desc) {
    localcon.setRemoteDescription(new RTCSessionDescription(desc)).then(()=> console.log("success")) 
}
function ingestCandidate(msg) {
    console.log("ingesting candidate")
    let candidate = new RTCIceCandidate({
        sdpMLineIndex: msg.label,
        candidate: msg.candidate
    })
    localcon.addIceCandidate(candidate)
}

function ingestOffer(desc,ocand) {
    // ?? what part of desc should be provided?
    window.theirOffer = desc
    console.log("setting remote desc")
    localcon.setRemoteDescription(new RTCSessionDescription(desc)).then(()=> console.log("ingest success")).catch(e=> console.log("ingest error",e))
    // set window otherCands and use them at add time
    window.otherCands = ocand 
    // create an answer
    localcon.createAnswer().then(handleAnswer)
}
function handleAnswer(desc) {
    window.locAnswer = desc
    localcon.setLocalDescription(desc).then(()=> console.log("handle answer success")).catch(e=> console.log("handle answer error",e))

    // now copy and use in other window

}
function descriptionErr(e) {
    console.log("error ", e)
}

// no send Data func, because we will do this from the window
function closeChannels() {
    console.log("closing send");

    datachannel.close()
    console.log("closing rec");
    recchannel.close()
    localcon.close()
    remotecon.close()

}

function desc1(desc) {
    // assign desc to remote, as remote desc and local to local
    localcon.setLocalDescription(desc)
    console.log("local offer", desc.sdp)
    // put the offer in text
    window.locOffer = desc
}

function desc2(desc) {
    // this is using the answer 
    console.log("answer text", desc.sdp)
    remotecon.setLocalDescription(desc)
    localcon.setRemoteDescription(desc)

}

function iceCB1(event) {
    // this is local dealing with ice candidate
    console.log("lcal ice callbac", event.candidate);
    if (event.candidate != null && event.candidate.candidate != "") {
        window.locCanInfo.push({
            type: 'candidate',
            label: event.candidate.sdpMLineIndex,
            id: event.candidate.sdpMid,
            candidate: event.candidate.candidate
        })
        //localcon.addIceCandidate(event.candidate)
    }

}
function iceCB2(event) {
    console.log("remote ice callback");

    if (event.candidate) {
        localcon.addIceCandidate(
            event.candidate
        ).then(
            iceSuccess,
            iceFail
        )
        console.log("remote ice candidate", event.candidate, "and", event.candidate.candidate)
    }
}

function iceSuccess() {
    console.log("addice success");

}
function iceFail(e) {
    console.log("ice fail", e);

}
function onChannelStateChange() {
    let readystate = datachannel.readyState
    if (readystate === "open") {
        console.log("og channel ope");
    } else {
        console.log("og channel is not open");
    }
}
function onRecChannelStateChange() {
    console.log("rec channel state is ", recchannel.readyState);

}
...