[webrtc-pc] `negotiationneeded` event payload should be more descriptive about what is triggering the event (#3003)

jpsantosbh has just created a new issue for https://github.com/w3c/webrtc-pc:

== `negotiationneeded` event payload should be more descriptive about what is triggering the event ==
### Summary
The `negotiationneeded` event currently lacks detailed information about what specifically triggers it. This limitation makes it challenging for developers to handle signaling efficiently, especially in complex applications where multiple actions can cause renegotiation.

### Detailed Description:

When the negotiationneeded event is fired on an RTCPeerConnection, it does not provide any context about the underlying reason. For instance, the event could be triggered by:

Adding a new track via addTrack() or addTransceiver()
Removing a track with removeTrack()
Changing the parameters of an RTCRtpSender
Modifications to data channels
Other internal state changes that require renegotiation
Without knowing the specific cause, developers might:

Perform unnecessary or redundant signaling operations
Face difficulties in optimizing the negotiation process
Encounter challenges in debugging and maintaining code

### Proposed Solution:

Enhance the `negotiationneeded` event by including additional information in its payload that describes the reason(s) for the event. This could be achieved by:

- Introducing a reason property in the event object, possibly as an array if multiple actions triggered the event.
- Defining a set of enumerated values or constants that represent different triggering actions.

### Example
```javascript
pc.addEventListener('negotiationneeded', (event) => {
  console.log('Negotiation needed due to:', event.reason);
  // event.reason could be something like ['addTrack', 'modifySender']
});
```

### Benefits:

- **Improved Clarity**: Developers can tailor their signaling logic based on the specific cause.
- **Optimization**: Potential to avoid full renegotiations when only minor adjustments are needed.
- **Debugging**: Easier to trace and resolve issues related to peer connection state changes.

Please view or discuss this issue at https://github.com/w3c/webrtc-pc/issues/3003 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Tuesday, 17 September 2024 13:48:25 UTC