# Webrtc recording/compositing- issue in adding audio track at correct position

**URL:** <https://community.wowza.com/t/webrtc-recording-compositing-issue-in-adding-audio-track-at-correct-position/94569>\
**Category:** Wowza Streaming Engine\
**Tags:** webrtc\
**Created:** [February 9, 2022, 10:22am UTC](https://community.wowza.com/t/webrtc-recording-compositing-issue-in-adding-audio-track-at-correct-position/94569 "2022-02-09T10:22:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vinaya\_zeple](https://avatars.discourse-cdn.com/v4/letter/v/eb9ed0/32.png) [@vinaya\_zeple](https://community.wowza.com/u/vinaya_zeple)\
**Post date:** [February 9, 2022, 10:22am UTC](https://community.wowza.com/t/webrtc-recording-compositing-issue-in-adding-audio-track-at-correct-position/94569/1 "2022-02-09T10:22:27Z")

</div>

We are using wowza webrtc and able to implement it in live.  
But on wowza server, seperate streams are getting recorded for every user. As per documentation, compositing on wowza server is not supported. we have to merge streams at client side and republish it.

we compositing all streams via the canvas element and able to add all video track to canvas stream whenever new user joins .  
But there is issue, when trying to add new audio track to existing peer connection that is when new user joins video chat its audio track should get added at correct time .

we are trying below methods:  
1.When we want to add new audio track to our existing canvas stream peer connection, we are using below code.

peerConnections[localUser].addTrack(new\_stream.getAudioTracks()[0],canvas\_stream);

peerConnections[localUser].addEventListener(“negotiationneeded”, ev =\> {

peerConnections[localUser].createOffer(gotLocalDescription, errorHandler);

}, false);

But in gotLocalDescription function, below code is written to send offer-  
wsConnection.send(’{“direction”:“publish”, “command”:“sendOffer”, “streamInfo”:’ + JSON.stringify(streamInfo) + ‘, “sdp”:’ + JSON.stringify(description) + ‘, “userData”:’ + JSON.stringify({}) + ‘}’);

But it is giving error that stream name is already in use.

1. So tried another method.  
When we want to add new audio track to our existing canvas stream peer connection, we closed existing peer connection and created new one. added audio track to canvas\_stream and sending new composite stream to peer connection. But in this method, we are facing audio-video sync that is audio got attached from start and not in the middle in recorded video file.

Does anyone know how to solve this problem?

---

<div class="post-metadata">

**Author:** ![cathy\_lee](https://avatars.discourse-cdn.com/v4/letter/c/ecb155/32.png) [@cathy\_lee](https://community.wowza.com/u/cathy_lee)\
**Post date:** [February 21, 2022, 3:19pm UTC](https://community.wowza.com/t/webrtc-recording-compositing-issue-in-adding-audio-track-at-correct-position/94569/2 "2022-02-21T15:19:31Z")

</div>

I got the same problem…

---

<div class="post-metadata">

**Author:** ![Prashant\_Apte](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@Prashant\_Apte](https://community.wowza.com/u/Prashant_Apte)\
**Post date:** [June 2, 2022, 6:47am UTC](https://community.wowza.com/t/webrtc-recording-compositing-issue-in-adding-audio-track-at-correct-position/94569/3 "2022-06-02T06:47:30Z")

</div>

Any update on this issue?

---

<div class="post-metadata">

**Author:** ![Rose\_Power-Wowza\_Com](https://sea2.discourse-cdn.com/flex002/user_avatar/community.wowza.com/rose_power-wowza_com/32/431_2.png) [@Rose\_Power-Wowza\_Com](https://community.wowza.com/u/Rose_Power-Wowza_Com)\
**Post date:** [June 2, 2022, 10:13pm UTC](https://community.wowza.com/t/webrtc-recording-compositing-issue-in-adding-audio-track-at-correct-position/94569/4 "2022-06-02T22:13:09Z")

</div>

Hello @Prashant_Apte, this is a bit of a complicated process- seems like you must grab the track, and then associate with the correct stream.

Likely you are missing negotiation:

> **[Perfect negotiation in WebRTC - Advancing WebRTC](https://blog.mozilla.org/webrtc/perfect-negotiation-in-webrtc/)**
>
> New preface: What if you could add and remove media to and from a live WebRTC connection, without having to worry about state, glare (signaling collisions), role (what side you’re on), or what condition the connection is in? You’d simply call...

Mixing them together and not just adding them will be a task you may need some assistance with and I don’t have nay documentation on that. You might have to submit a ticket and get an engineer in Wowza tech support to try and help.
