AgoraIO / API-Examples-Web

224 stars 199 forks source link

Error publishing on Agora Web SDK v4 #12

Closed sambhavsharma closed 1 year ago

sambhavsharma commented 3 years ago

I followed the steps as mentioned in the docs. I was earlier using agora v3.6.0 and everything was working fine. I want to upgrade to Agora v4 which isn't backward compatible, but looked easy enough to implement.

I am receiving the following error after I publish my local tracks.

AgoraRTC_N-production.js:637 Uncaught (in promise) TypeError: this.report.forEach is not a function
    at b.<anonymous> (AgoraRTC_N-production.js:637)
    at AgoraRTC_N-production.js:175
    at Object.next (AgoraRTC_N-production.js:176)
    at g (AgoraRTC_N-production.js:174)

-- Code

` import AgoraRTC from 'agora-rtc-sdk-ng'; const AgoraClient = AgoraRTC.createClient({ mode: 'rtc', codec: "h264" });

    // inside useEffect.
    const agoraAccessToken = await actions.auth.getAgoraAccessToken({ requestParams: {channel: props.config.channel}});
    let uid = await AgoraClient.join(props.config.appId, props.config.channel, agoraAccessToken);

    let audioTrack = await AgoraRTC.createMicrophoneAudioTrack();
    let videoTrack = await AgoraRTC.createCameraVideoTrack();

    await AgoraClient.publish([audioTrack, videoTrack]);

`

yoreland commented 3 years ago

Hi, it is a bit hard to check the issue from this message only. If it is possible can you upload part of your code which could reproduce the issue?

sambhavsharma commented 3 years ago

Hi, it is a bit hard to check the issue from this message only. If it is possible can you upload part of your code which could reproduce the issue?

Hi, updated the issue with some code.

wevertoum commented 2 years ago

same issue here, updates?

luissantiagodev commented 2 years ago

any update on this?

yoreland commented 2 years ago

In 4.x sdk createMicrophoneAudioTrack returns Promise Object. And if you could use createMicrophoneAndCameraTracks APIs to publish then at the same time.

        AgoraRTC.createMicrophoneAndCameraTracks({microphoneId: microphoneId}, {cameraId: cameraId})
            .then((tracks) => {
                this.mLocalAudioTrack = tracks[0]
                this.mLocalVideoTrack = tracks[1]
                this._client.publish([this.mLocalAudioTrack, this.mLocalVideoTrack])

                resolve()
            })
            .catch(e => {
                reject(e)
            })

And for sure, you could create camera and microphone tracks relatively like:

    // create local audio and video tracks
    localTracks.audioTrack = await AgoraRTC.createMicrophoneAudioTrack();
    localTracks.videoTrack = await AgoraRTC.createCameraVideoTrack();
    // play local video track
    localTracks.videoTrack.play("local-player");
    // publish local tracks to channel
    await client.publish(Object.values(localTracks));