androidioswebrtcvideochatphonertc

In PhoneRTC, how can I turn an existing voice chat into a video chat?


I have a simple voice chat working:

var config = {
    isInitiator: true,
    turn: {
        host: 'turn:turn.example.com:3478',
        username: 'test',
        password: '123'
    },
    streams: {
        audio: true,
        video: false
    }
}

var session = new phonertc.Session(config);

// ... event handling

session.call();

How can I add a button that adds video to the existing voice chat?


Solution

  • You'll first need to make sure that you have a video view. To set up a video view, create a simple video container:

    <div id="video-container"></div>
    

    Make sure to make it square with fixed width and height:

    #video-container {
        width: 300px;
        height: 300px;
        background-color: #000;
    }
    

    Then, use the setVideoView API:

    phonertc.setVideoView({
        container: document.getElementById('video-container'),
        local: {
            position: [0, 0],
            size: [100, 100]
        }
    });
    

    To finally start sending the video stream, renegotiate the session:

    session.streams.video = true;
    session.renegotiate();