Skip to content

Commit

Permalink
pc: align createDataChannel with standard
Browse files Browse the repository at this point in the history
- Throw TypeError if no argument passed
- Stringify the label

Fixes: react-native-webrtc#1605
  • Loading branch information
saghul committed Aug 7, 2024
1 parent c0ddefd commit fb02a5b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/RTCPeerConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,10 @@ export default class RTCPeerConnection extends EventTarget<RTCPeerConnectionEven
* instance such as id
*/
createDataChannel(label: string, dataChannelDict?: RTCDataChannelInit): RTCDataChannel {
if (arguments.length === 0) {
throw new TypeError('1 argument required, but 0 present');
}

if (dataChannelDict && 'id' in dataChannelDict) {
const id = dataChannelDict.id;

Expand All @@ -747,7 +751,7 @@ export default class RTCPeerConnection extends EventTarget<RTCPeerConnectionEven
}
}

const channelInfo = WebRTCModule.createDataChannel(this._pcId, label, dataChannelDict);
const channelInfo = WebRTCModule.createDataChannel(this._pcId, String(label), dataChannelDict);

if (channelInfo === null) {
throw new TypeError('Failed to create new DataChannel');
Expand Down

0 comments on commit fb02a5b

Please sign in to comment.