Skip to content

Commit

Permalink
Calls: create data channel only on the caller's side.
Browse files Browse the repository at this point in the history
Removes redundancy and a memory leak (and thus an error upon closing).
  • Loading branch information
aforge authored and or-else committed Feb 16, 2023
1 parent 345f7f3 commit 8f880f4
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions Tinodios/CallViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class WebRTCClient: NSObject {
}
}

func createPeerConnection() -> Bool {
func createPeerConnection(withDataChannel dataChannel: Bool) -> Bool {
let constraints = RTCMediaConstraints(mandatoryConstraints: nil, optionalConstraints: nil)
guard let config = generateRTCConfig() else {
Cache.log.info("WebRTCClient - missing configuration. Quitting.")
Expand All @@ -228,11 +228,12 @@ class WebRTCClient: NSObject {
return false
}

let chanConfig = RTCDataChannelConfiguration()
chanConfig.isOrdered = true
chanConfig.isNegotiated = true
self.localDataChannel = localPeer!.dataChannel(forLabel: "events", configuration: chanConfig)
self.localDataChannel?.delegate = self
if dataChannel {
let chanConfig = RTCDataChannelConfiguration()
chanConfig.isOrdered = true
self.localDataChannel = localPeer!.dataChannel(forLabel: "events", configuration: chanConfig)
self.localDataChannel?.delegate = self
}

let stream = WebRTCClient.factory.mediaStream(withStreamId: "ARDAMS")
stream.addAudioTrack(self.localAudioTrack!)
Expand Down Expand Up @@ -1070,7 +1071,7 @@ extension CallViewController: TinodeVideoCallDelegate {
self.peerAvatarImageView.alpha = 0
}
// The callee has informed us (the caller) of the call acceptance.
guard self.webRTCClient.createPeerConnection() else {
guard self.webRTCClient.createPeerConnection(withDataChannel: true) else {
Cache.log.error("CallVC.handleAcceptedMsg - createPeerConnection failed")
self.handleCallClose()
return
Expand All @@ -1084,7 +1085,8 @@ extension CallViewController: TinodeVideoCallDelegate {
self.handleCallClose()
return
}
guard self.webRTCClient.createPeerConnection() else {
// Data channel should be created by the peer. Not creating one.
guard self.webRTCClient.createPeerConnection(withDataChannel: false) else {
Cache.log.error("CallVC.handleOfferMsg - createPeerConnection failed")
self.handleCallClose()
return
Expand Down

0 comments on commit 8f880f4

Please # to comment.