0

I'm trying to build a website with Networked Aframe. I'm using the easyRTC adapter, which allows for audio and video streaming. I am trying to have the user initially join the room without their video or audio on. I've tried to turn off video and audio when entering, but the audio and video are still sent for a brief moment before it stops being sent. I tried to turn off the video stream but that yielded no luck as the webcam indicator is still on when the video is "off" and the video is still sent for a brief moment. Any help will be appreciated.

AFRAME.registerComponent('dynamic-room', {
    init: function () {
        const el = this.el;
        const params = this.getUrlParams();
        const networkedComp = {
            room: params.room,
            debug: true,
            audio: true,
            onConnect: onConnecth,
            adapter: "easyrtc",
            video: true
        };
        console.info('Init networked-aframe with settings:', networkedComp);
        console.log(this.el);
        console.log("setting it", this.el.setAttribute('networked-scene', networkedComp));
        document.body.addEventListener('clientConnected', function (evt) {
            onConnecth();
        });
        this.el.emit("connect", null, false);

    },
let cameraEnabled = true;
let micEnabled = true;
let screenEnabled = false;

const cameraButton = document.getElementById('cameraaction');
const micButton = document.getElementById('micaction');
const screenButton = document.getElementById("screenshareaction");
let first = true;
function onConnecth() {
    if(!first) {
    console.log("something went wrong");
    }
    else {
        document.getElementById('player').setAttribute('player-info', 'name', getUrlParams().username);
        NAF.connection.adapter.enableCamera(!cameraEnabled);
        NAF.connection.adapter.enableMicrophone(!micEnabled);
        console.log("First Load");
        cameraEnabled = !cameraEnabled;
        micEnabled = !micEnabled;
        disableVideo();
        finishLoad();
    }
}

function disableVideo(){

    const stream = NAF.connection.adapter.getMediaStream();
    stream.getTracks().forEach(track => {
        if (track.kind === 'video') {
            track.stop();
        }
    })

}
function finishLoad(){
    cameraButton.onclick = function () {
        NAF.connection.adapter.enableCamera(!cameraEnabled);
        cameraEnabled = !cameraEnabled;
        if(!cameraEnabled){
        disableVideo();
       } 
    };
    micButton.onclick = function () {
        NAF.connection.adapter.enableMicrophone(!micEnabled);
        micEnabled = !micEnabled;
    };
}
piflyer
  • 17
  • 7

0 Answers0