Browse Source

Replaced the GoogleWebRTC library (deprecated) with WebRTC-lib

pull/624/head
Morgan Pretty 3 months ago
parent
commit
531ddcb079
  1. 2
      Podfile
  2. 10
      Podfile.lock
  3. 17
      Session/Calls/Views & Modals/CallVideoView.swift
  4. 15
      Session/Calls/Views & Modals/MiniCallView.swift
  5. 2
      SessionMessagingKit/Calls/WebRTCSession+DataChannel.swift
  6. 4
      SessionMessagingKit/Calls/WebRTCSession+MessageHandling.swift
  7. 20
      SessionMessagingKit/Calls/WebRTCSession.swift

2
Podfile

@ -10,7 +10,7 @@ abstract_target 'GlobalDependencies' do
pod 'CryptoSwift'
pod 'Sodium', '~> 0.9.1'
pod 'YapDatabase/SQLCipher', :git => 'https://github.com/oxen-io/session-ios-yap-database.git', branch: 'signal-release'
pod 'GoogleWebRTC'
pod 'WebRTC-lib'
pod 'SocketRocket', '~> 0.5.1'
target 'Session' do

10
Podfile.lock

@ -21,7 +21,6 @@ PODS:
- Curve25519Kit (2.1.0):
- CocoaLumberjack
- SignalCoreKit
- GoogleWebRTC (1.1.31999)
- Mantle (2.1.0):
- Mantle/extobjc (= 2.1.0)
- Mantle/extobjc (2.1.0)
@ -52,6 +51,7 @@ PODS:
- SQLCipher/standard (4.5.0):
- SQLCipher/common
- SwiftProtobuf (1.5.0)
- WebRTC-lib (96.0.0)
- YapDatabase/SQLCipher (3.1.1):
- YapDatabase/SQLCipher/Core (= 3.1.1)
- YapDatabase/SQLCipher/Extensions (= 3.1.1)
@ -125,7 +125,6 @@ DEPENDENCIES:
- AFNetworking
- CryptoSwift
- Curve25519Kit (from `https://github.com/signalapp/Curve25519Kit.git`)
- GoogleWebRTC
- Mantle (from `https://github.com/signalapp/Mantle`, branch `signal-master`)
- NVActivityIndicatorView
- PromiseKit
@ -136,6 +135,7 @@ DEPENDENCIES:
- SocketRocket (~> 0.5.1)
- Sodium (~> 0.9.1)
- SwiftProtobuf (~> 1.5.0)
- WebRTC-lib
- YapDatabase/SQLCipher (from `https://github.com/oxen-io/session-ios-yap-database.git`, branch `signal-release`)
- YYImage (from `https://github.com/signalapp/YYImage`)
- ZXingObjC
@ -145,7 +145,6 @@ SPEC REPOS:
- AFNetworking
- CocoaLumberjack
- CryptoSwift
- GoogleWebRTC
- NVActivityIndicatorView
- OpenSSL-Universal
- PromiseKit
@ -156,6 +155,7 @@ SPEC REPOS:
- Sodium
- SQLCipher
- SwiftProtobuf
- WebRTC-lib
- ZXingObjC
EXTERNAL SOURCES:
@ -195,7 +195,6 @@ SPEC CHECKSUMS:
CocoaLumberjack: 543c79c114dadc3b1aba95641d8738b06b05b646
CryptoSwift: a532e74ed010f8c95f611d00b8bbae42e9fe7c17
Curve25519Kit: e63f9859ede02438ae3defc5e1a87e09d1ec7ee6
GoogleWebRTC: b39a78c4f5cc6b0323415b9233db03a2faa7b0f0
Mantle: 2fa750afa478cd625a94230fbf1c13462f29395b
NVActivityIndicatorView: 1f6c5687f1171810aa27a3296814dc2d7dec3667
OpenSSL-Universal: e7311447fd2419f57420c79524b641537387eff2
@ -208,10 +207,11 @@ SPEC CHECKSUMS:
Sodium: 23d11554ecd556196d313cf6130d406dfe7ac6da
SQLCipher: 98dc22f27c0b1790d39e710d440f22a466ebdb59
SwiftProtobuf: 241400280f912735c1e1b9fe675fdd2c6c4d42e2
WebRTC-lib: 508fe02efa0c1a3a8867082a77d24c9be5d29aeb
YapDatabase: b418a4baa6906e8028748938f9159807fd039af4
YYImage: f1ddd15ac032a58b78bbed1e012b50302d318331
ZXingObjC: fdbb269f25dd2032da343e06f10224d62f537bdb
PODFILE CHECKSUM: 610d1ebc4e559cf746dc3ae0ae7c78b011373d4c
PODFILE CHECKSUM: a3d89a6cc8735285fd51348ca05cea71f2c28872
COCOAPODS: 1.11.2

17
Session/Calls/Views & Modals/CallVideoView.swift

@ -2,12 +2,11 @@
import WebRTC
import Foundation
#if arch(arm64)
// Note: 'RTCMTLVideoView' requires arm64 (so won't work on the simulator which
// we need to build for x86_64 due to WebRTC not supporting arm64 simulator builds)
typealias TargetView = RTCMTLVideoView
#else
#if targetEnvironment(simulator)
// Note: 'RTCMTLVideoView' doesn't seem to work on the simulator so use 'RTCEAGLVideoView' instead
typealias TargetView = RTCEAGLVideoView
#else
typealias TargetView = RTCMTLVideoView
#endif
// MARK: RemoteVideoView
@ -17,6 +16,7 @@ class RemoteVideoView: TargetView {
override func renderFrame(_ frame: RTCVideoFrame?) {
super.renderFrame(frame)
guard let frame = frame else { return }
DispatchMainThreadSafe {
let frameRatio = Double(frame.height) / Double(frame.width)
let frameRotation = frame.rotation
@ -47,7 +47,9 @@ class RemoteVideoView: TargetView {
// Assume we're already setup for the correct orientation.
break
}
#if arch(arm64)
#if targetEnvironment(simulator)
#else
if let rotationOverride = rotationOverride {
self.rotationOverride = NSNumber(value: rotationOverride.rawValue)
if [ RTCVideoRotation._0, RTCVideoRotation._180 ].contains(rotationOverride) {
@ -86,7 +88,8 @@ class LocalVideoView: TargetView {
// sometimes the rotationOverride is not working
// if it is only set once on initialization
self.rotationOverride = NSNumber(value: RTCVideoRotation._0.rawValue)
#if arch(arm64)
#if targetEnvironment(simulator)
#else
self.videoContentMode = .scaleAspectFill
#endif
}

15
Session/Calls/Views & Modals/MiniCallView.swift

@ -16,22 +16,21 @@ final class MiniCallView: UIView, RTCVideoViewDelegate {
private var top: NSLayoutConstraint?
private var bottom: NSLayoutConstraint?
#if arch(arm64)
// Note: 'RTCMTLVideoView' requires arm64 (so won't work on the simulator which
// we need to build for x86_64 due to WebRTC not supporting arm64 simulator builds)
private lazy var remoteVideoView: RTCMTLVideoView = {
let result = RTCMTLVideoView()
#if targetEnvironment(simulator)
// Note: 'RTCMTLVideoView' doesn't seem to work on the simulator so use 'RTCEAGLVideoView' instead
private lazy var remoteVideoView: RTCEAGLVideoView = {
let result = RTCEAGLVideoView()
result.delegate = self
result.alpha = self.callVC.call.isRemoteVideoEnabled ? 1 : 0
result.videoContentMode = .scaleAspectFit
result.backgroundColor = .black
return result
}()
#else
private lazy var remoteVideoView: RTCEAGLVideoView = {
let result = RTCEAGLVideoView()
private lazy var remoteVideoView: RTCMTLVideoView = {
let result = RTCMTLVideoView()
result.delegate = self
result.alpha = self.callVC.call.isRemoteVideoEnabled ? 1 : 0
result.videoContentMode = .scaleAspectFit
result.backgroundColor = .black
return result
}()

2
SessionMessagingKit/Calls/WebRTCSession+DataChannel.swift

@ -8,7 +8,7 @@ extension WebRTCSession: RTCDataChannelDelegate {
dataChannelConfiguration.isOrdered = true
dataChannelConfiguration.isNegotiated = true
dataChannelConfiguration.channelId = 548
guard let dataChannel = peerConnection.dataChannel(forLabel: "CONTROL", configuration: dataChannelConfiguration) else {
guard let dataChannel = peerConnection?.dataChannel(forLabel: "CONTROL", configuration: dataChannelConfiguration) else {
SNLog("[Calls] Couldn't create data channel.")
return nil
}

4
SessionMessagingKit/Calls/WebRTCSession+MessageHandling.swift

@ -4,12 +4,12 @@ extension WebRTCSession {
public func handleICECandidates(_ candidate: [RTCIceCandidate]) {
SNLog("[Calls] Received ICE candidate message.")
candidate.forEach { peerConnection.add($0) }
candidate.forEach { peerConnection?.add($0) }
}
public func handleRemoteSDP(_ sdp: RTCSessionDescription, from sessionID: String) {
SNLog("[Calls] Received remote SDP: \(sdp.sdp).")
peerConnection.setRemoteDescription(sdp, completionHandler: { [weak self] error in
peerConnection?.setRemoteDescription(sdp, completionHandler: { [weak self] error in
if let error = error {
SNLog("[Calls] Couldn't set SDP due to error: \(error).")
} else {

20
SessionMessagingKit/Calls/WebRTCSession.swift

@ -35,7 +35,7 @@ public final class WebRTCSession : NSObject, RTCPeerConnectionDelegate {
/// Represents a WebRTC connection between the user and a remote peer. Provides methods to connect to a
/// remote peer, maintain and monitor the connection, and close the connection once it's no longer needed.
internal lazy var peerConnection: RTCPeerConnection = {
internal lazy var peerConnection: RTCPeerConnection? = {
let configuration = RTCConfiguration()
if let defaultICEServer = defaultICEServer {
configuration.iceServers = [ RTCIceServer(urlStrings: defaultICEServer.urls, username: defaultICEServer.username, credential: defaultICEServer.password) ]
@ -67,7 +67,7 @@ public final class WebRTCSession : NSObject, RTCPeerConnectionDelegate {
}()
internal lazy var remoteVideoTrack: RTCVideoTrack? = {
return peerConnection.transceivers.first { $0.mediaType == .video }?.receiver.track as? RTCVideoTrack
return peerConnection?.transceivers.first { $0.mediaType == .video }?.receiver.track as? RTCVideoTrack
}()
// Data Channel
@ -94,8 +94,8 @@ public final class WebRTCSession : NSObject, RTCPeerConnectionDelegate {
self.uuid = uuid
super.init()
let mediaStreamTrackIDS = ["ARDAMS"]
peerConnection.add(audioTrack, streamIds: mediaStreamTrackIDS)
peerConnection.add(localVideoTrack, streamIds: mediaStreamTrackIDS)
peerConnection?.add(audioTrack, streamIds: mediaStreamTrackIDS)
peerConnection?.add(localVideoTrack, streamIds: mediaStreamTrackIDS)
// Configure audio session
configureAudioSession()
@ -125,12 +125,12 @@ public final class WebRTCSession : NSObject, RTCPeerConnectionDelegate {
SNLog("[Calls] Sending offer message.")
guard let thread = TSContactThread.fetch(for: sessionID, using: transaction) else { return Promise(error: Error.noThread) }
let (promise, seal) = Promise<Void>.pending()
peerConnection.offer(for: mediaConstraints(isRestartingICEConnection)) { [weak self] sdp, error in
peerConnection?.offer(for: mediaConstraints(isRestartingICEConnection)) { [weak self] sdp, error in
if let error = error {
seal.reject(error)
} else {
guard let self = self, let sdp = self.correctSessionDescription(sdp: sdp) else { preconditionFailure() }
self.peerConnection.setLocalDescription(sdp) { error in
self.peerConnection?.setLocalDescription(sdp) { error in
if let error = error {
print("Couldn't initiate call due to error: \(error).")
return seal.reject(error)
@ -157,12 +157,12 @@ public final class WebRTCSession : NSObject, RTCPeerConnectionDelegate {
SNLog("[Calls] Sending answer message.")
guard let thread = TSContactThread.fetch(for: sessionID, using: transaction) else { return Promise(error: Error.noThread) }
let (promise, seal) = Promise<Void>.pending()
peerConnection.answer(for: mediaConstraints(false)) { [weak self] sdp, error in
peerConnection?.answer(for: mediaConstraints(false)) { [weak self] sdp, error in
if let error = error {
seal.reject(error)
} else {
guard let self = self, let sdp = self.correctSessionDescription(sdp: sdp) else { preconditionFailure() }
self.peerConnection.setLocalDescription(sdp) { error in
self.peerConnection?.setLocalDescription(sdp) { error in
if let error = error {
print("Couldn't accept call due to error: \(error).")
return seal.reject(error)
@ -221,7 +221,7 @@ public final class WebRTCSession : NSObject, RTCPeerConnectionDelegate {
}
public func dropConnection() {
peerConnection.close()
peerConnection?.close()
}
private func mediaConstraints(_ isRestartingICEConnection: Bool) -> RTCMediaConstraints {
@ -263,7 +263,7 @@ public final class WebRTCSession : NSObject, RTCPeerConnectionDelegate {
if state == .connected {
delegate?.webRTCIsConnected()
} else if state == .disconnected {
if self.peerConnection.signalingState == .stable {
if self.peerConnection?.signalingState == .stable {
delegate?.reconnectIfNeeded()
}
}

Loading…
Cancel
Save