@@ -43,7 +43,13 @@ public final class WebRTCConnector: NSObject, Connector, Sendable {
43
43
}
44
44
self . connection = connection
45
45
46
- guard let dataChannel = self . connection. dataChannel ( forLabel: " WebRTCData " , configuration: RTCDataChannelConfiguration ( ) ) else {
46
+ let audioTrackSource = WebRTCConnector . factory. audioSource ( with: nil )
47
+ let audioTrack = WebRTCConnector . factory. audioTrack ( with: audioTrackSource, trackId: " audio0 " )
48
+ let mediaStream = WebRTCConnector . factory. mediaStream ( withStreamId: " stream0 " )
49
+ mediaStream. addAudioTrack ( audioTrack)
50
+ self . connection. add ( audioTrack, streamIds: [ " stream0 " ] )
51
+
52
+ guard let dataChannel = self . connection. dataChannel ( forLabel: " oai-events " , configuration: RTCDataChannelConfiguration ( ) ) else {
47
53
throw WebRTCError . failedToCreateDataChannel
48
54
}
49
55
self . dataChannel = dataChannel
@@ -57,13 +63,19 @@ public final class WebRTCConnector: NSObject, Connector, Sendable {
57
63
58
64
var request = request
59
65
60
- let offer = try await self . connection. offer ( for: . init( mandatoryConstraints: nil , optionalConstraints: nil ) )
66
+ let offer = try await self . connection. offer ( for: RTCMediaConstraints ( mandatoryConstraints: nil , optionalConstraints: [
67
+ " OfferToReceiveAudio " : " true " ,
68
+ " googEchoCancellation " : " true " ,
69
+ " googAutoGainControl " : " true " ,
70
+ " googNoiseSuppression " : " true " ,
71
+ " googHighpassFilter " : " true " ,
72
+ ] ) )
61
73
try await self . connection. setLocalDescription ( offer)
62
74
63
75
request. httpBody = offer. sdp. data ( using: . utf8)
64
76
65
77
let ( data, res) = try await URLSession . shared. data ( for: request)
66
- guard ( res as? HTTPURLResponse ) ? . statusCode == 200 , let sdp = String ( data: data, encoding: . utf8) else {
78
+ guard let res = res as? HTTPURLResponse , res . statusCode == 201 , let sdp = String ( data: data, encoding: . utf8) else {
67
79
throw WebRTCError . badServerResponse
68
80
}
69
81
0 commit comments