AgoraIO-Community / AgoraWebSDK-NG

The Next Generation of Agora Web SDK
https://agoraio-community.github.io/AgoraWebSDK-NG/
161 stars 74 forks source link

Sometimes in user-published method I don't receive audio track #141

Closed tsyrya closed 3 years ago

tsyrya commented 3 years ago

Describe the bug

I can't identify circumstances, but in some cases when a remote client publishes its tracks (both audio and video). In the user-published event handler int the IAgoraRTCRemoteUser parameter there is no audio track. But based on the logs, the publishing was successful.

SDK Logs

Remote client logs: 11:27:21:419 Agora-SDK [INFO]: [client-a277b] Publishing tracks, id track-436835f3 ,track-c4a072d3 AgoraRTC_N-production.js?e671:384 11:27:21:535 Agora-SDK [INFO]: [client-a277b-pub-4] ice-state: pub p2p checking AgoraRTC_N-production.js?e671:384 11:27:21:536 Agora-SDK [INFO]: [client-a277b-pub-4] connection-state: pub p2p connecting AgoraRTC_N-production.js?e671:384 11:27:21:742 Agora-SDK [INFO]: [client-a277b-pub-4] ice-state: pub p2p connected AgoraRTC_N-production.js?e671:384 11:27:21:946 Agora-SDK [INFO]: [client-a277b-pub-5] ice-state: pub p2p checking AgoraRTC_N-production.js?e671:384 11:27:21:946 Agora-SDK [INFO]: [client-a277b-pub-5] connection-state: pub p2p connecting AgoraRTC_N-production.js?e671:384 11:27:21:952 Agora-SDK [INFO]: [client-a277b-pub-4] connection-state: pub p2p connected AgoraRTC_N-production.js?e671:384 11:27:22:55 Agora-SDK [INFO]: [client-a277b] on publish stream, {"proxy":false,"uid":"770"} AgoraRTC_N-production.js?e671:384 11:27:22:66 Agora-SDK [INFO]: [client-a277b-pub-5] ice-state: pub p2p connected AgoraRTC_N-production.js?e671:384 11:27:22:66 Agora-SDK [INFO]: [client-a277b] Publish success, id track-436835f3 ,track-c4a072d3 AgoraRTC_N-production.js?e671:384 11:27:22:187 Agora-SDK [INFO]: [client-a277b-pub-5] connection-state: pub p2p connected

Local client logs: 11:27:22:211 Agora-SDK [INFO]: [client-30b3f] remote user 770 published video AgoraRTC_N-production.js?e671:384 11:27:22:212 Agora-SDK [INFO]: [client-30b3f] subscribe user 770, mediaType: video AgoraRTC_N-production.js?e671:384 11:27:22:217 Agora-SDK [INFO]: [client-30b3f] remote user 770 published audio

log of IagoraRTCRemoteUser: audioTrack: undefined hasAudio: true hasVideo: true videoTrack: nd

Channel: c5769006-1f82-45a1-9cdf-349546c84a68@Test1

UID: local - 768 , remote - 770

Platform and Browser: PC, Chrome 89

SDK Version: 4.4.0

To Reproduce

Steps to reproduce the behavior:

  1. Publish tracks on the remote client
  2. console.log track in the user-published event of the local client
yoreland commented 3 years ago

Hello, thanks for report the issue. For the provided the channel name c5769006-1f82-45a1-9cdf-349546c84a68@Test1, seems you have created lots of channel with same id. If it is convent, can you reproduce this issue again with a different channel name? Then we could have check on the backend.

tsyrya commented 3 years ago

Thanks for the reply. Sure, that's the new channel: appercode_test_c5769006-1f82-45a1-9cdf-349546c84a68@Test1

The behavior is kinda inconsistent, as of now I can't find the exact conditions when it happens.

Thanks for your help

yoreland commented 3 years ago

@tsyrya For subscribe remote user audio/video track, did you try below:

client.on("user-published", async (user, mediaType) => { // Initiate the subscription await client.subscribe(user, mediaType);

// If the subscribed track is an audio track if (mediaType === "audio") { const audioTrack = user.audioTrack; // Play the audio audioTrack.play(); } else { const videoTrack = user.videoTrack; // Play the video videoTrack.play(DOM_ELEMENT); } });

If your logic is different, can you share the same here?

tsyrya commented 3 years ago

Yeah, the logic is similar. That's how I subscribe to the user-published event:

this.client.on(AgoraUserEvents.UserPublished, this.handlePublished.bind(this));

In the handler there is some logic, but I do console.log immediately and I get audioTrack: undefined

async handlePublished(user: IAgoraRTCRemoteUser, mediaType: AgoraMediaType): Promise<void> {
    console.log('user published', user);
    mediaType == AgoraMediaTypeEnum.Audio && await this.client.subscribe(user, AgoraMediaTypeEnum.Audio);
    mediaType == AgoraMediaTypeEnum.Video && await this.client.subscribe(user, AgoraMediaTypeEnum.Video);

    ...some logic
}
yoreland commented 3 years ago

Yeah, the logic is similar. That's how I subscribe to the user-published event:

this.client.on(AgoraUserEvents.UserPublished, this.handlePublished.bind(this));

In the handler there is some logic, but I do console.log immediately and I get audioTrack: undefined

async handlePublished(user: IAgoraRTCRemoteUser, mediaType: AgoraMediaType): Promise<void> {
    console.log('user published', user);
    mediaType == AgoraMediaTypeEnum.Audio && await this.client.subscribe(user, AgoraMediaTypeEnum.Audio);
    mediaType == AgoraMediaTypeEnum.Video && await this.client.subscribe(user, AgoraMediaTypeEnum.Video);

    ...some logic
}

In this case, the current MediaType is "video", right? Will you get another event with MediaType as "audio"?

tsyrya commented 3 years ago

Yeah, the event fires 2 times, but in both cases the autioTrack property is undefined.

tsyrya commented 3 years ago

that's the full log of the object when the mediaType = 'audio':

uid: "770"
_audio_added_: true
_audio_enabled_: true
_audio_muted_: false
_trust_audio_enabled_state_: true
_trust_audio_mute_state_: true
_trust_in_room_: true
_trust_stream_added_state_: true
_trust_video_enabled_state_: true
_trust_video_mute_state_: true
_uintid: 10022
_videoTrack: nd {…}
_video_added_: true
_video_enabled_: true
_video_muted_: false
audioTrack: undefined
hasAudio: true
hasVideo: true
videoTrack: nd
yoreland commented 3 years ago

Yeah, the event fires 2 times, but in both cases the autioTrack property is undefined.

So far, we didn't receive issue like this from any other users.. do you have a chance to try on different environment? For example, use two different PC and different browsers.. , etc

tsyrya commented 3 years ago

We have tried different devices and browsers, it happens time to time. I don’t deny that it might be our code’s problem. But I have difficulties to narrow down the case. Maybe you can give me a hint where I can dig in. Like in what cases it might be that hasVolume: true, but audioTrack is undefined (maybe I publish it wrong). Also as you see based on the log information the track was published successfully. Thank you.

tsyrya commented 3 years ago

that's how I publish

let [localAudioTrack, localVideoTrack] = await Promise.all([
                this.createAudioTrack(),
                this.createVideoTrack()
            ]);

await this.client.publish([localAudioTrack, localVideoTrack]);

for now All I do in the user-published event is


console.log('user published', user, mediaType);
await this.client.subscribe(user, mediaType);
tsyrya commented 3 years ago

Could it because I do subscription with a delay, because before I subscribe there is a user rights checking logic?

yoreland commented 3 years ago

that's how I publish

let [localAudioTrack, localVideoTrack] = await Promise.all([
                this.createAudioTrack(),
                this.createVideoTrack()
            ]);

await this.client.publish([localAudioTrack, localVideoTrack]);

for now All I do in the user-published event is

console.log('user published', user, mediaType);
await this.client.subscribe(user, mediaType);

If you publish audio and video track separately, can make the things different?

tsyrya commented 3 years ago

Well, seems like my problem is gone if I remove my checking role logic before subscription. I don't really understand why thought :) When the user-published event is fired, the user parameter of the handler is a link to the same object in both audio and video cases? Maybe I somehow messed up with the object, because I was keeping it in the memory while checking the rights. I will test more and let you know the results once I am done. Thank you for your help!

tsyrya commented 3 years ago

To be honest I still don't know what the problem was, but it is working stable now. Thank you for your help