peers / peerjs

Simple peer-to-peer with WebRTC.
https://peerjs.com
MIT License
12.44k stars 1.43k forks source link

Member of videochat can't see anybody If he doesn't have a webcam #944

Open Licege opened 2 years ago

Licege commented 2 years ago

Hello, I have a some problem with video tracks. If user doesn't have a webcam or deny permission in browser than he don't receive video tracks from another users (which send video). I can fix it only if I change options which passed in offer like that:

const offer = await peerConnection.createOffer(
  { ...this.connection.options.constraints, offerToReceiveAudio: true, offerToReceiveVideo: true }
);
jonasgloning commented 2 years ago

Hey @Licege. Thanks for the report!

Can you post a minimal working example of this? I would like to reproduce this.

Also, please add:

Licege commented 2 years ago

Hello, I added simple example here https://github.com/Licege/peerjs-bug

Browser: Chrome (100.0.4896.127); OS: Mac OS Big Sur 11.6 (but try also Windows 10); PeerJS: 1.3.2; Yes we use webpack)

undermuz commented 2 years ago

@Licege I have faced with this bug i fixed it by this code:

static createBlankVideoTrack(opts = {}) {
        const { width = 1920, height = 1080 } = opts

        const canvas = Object.assign(document.createElement("canvas"), {
            width,
            height,
        })

        canvas.getContext("2d").fillRect(0, 0, width, height)

        const stream = canvas.captureStream()

        return stream
    }
    ...
    const audioTrack = stream.getAudioTracks()[0]

     const videoStream = UserMedia.createBlankVideoTrack()

    videoStream.addTrack(audioTrack)

     stream = videoStream

just create blank video track and add an audio track from the main stream