WIP: callkit & pushkit

This commit is contained in:
ryanzhao 2021-10-26 15:48:31 +11:00
parent bcdf49eada
commit dea57081c7
5 changed files with 49 additions and 0 deletions

View File

@ -149,6 +149,7 @@
7B7CB192271508AD0079FF93 /* Vibration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B7CB191271508AD0079FF93 /* Vibration.swift */; };
7BC01A3E241F40AB00BC7C55 /* NotificationServiceExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BC01A3D241F40AB00BC7C55 /* NotificationServiceExtension.swift */; };
7BC01A42241F40AB00BC7C55 /* SessionNotificationServiceExtension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 7BC01A3B241F40AB00BC7C55 /* SessionNotificationServiceExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
7BC707EA27267973002817AD /* AppDelegate+VoIP.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BC707E927267973002817AD /* AppDelegate+VoIP.swift */; };
7BCD116C27016062006330F1 /* WebRTCSession+DataChannel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BCD116B27016062006330F1 /* WebRTCSession+DataChannel.swift */; };
7BDCFC08242186E700641C39 /* NotificationServiceExtensionContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BDCFC07242186E700641C39 /* NotificationServiceExtensionContext.swift */; };
7BDCFC0B2421EB7600641C39 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = B6F509951AA53F760068F56A /* Localizable.strings */; };
@ -1133,6 +1134,7 @@
7BC01A3B241F40AB00BC7C55 /* SessionNotificationServiceExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = SessionNotificationServiceExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; };
7BC01A3D241F40AB00BC7C55 /* NotificationServiceExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationServiceExtension.swift; sourceTree = "<group>"; };
7BC01A3F241F40AB00BC7C55 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
7BC707E927267973002817AD /* AppDelegate+VoIP.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AppDelegate+VoIP.swift"; sourceTree = "<group>"; };
7BCD116B27016062006330F1 /* WebRTCSession+DataChannel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WebRTCSession+DataChannel.swift"; sourceTree = "<group>"; };
7BDCFC0424206E7300641C39 /* SessionNotificationServiceExtension.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = SessionNotificationServiceExtension.entitlements; sourceTree = "<group>"; };
7BDCFC07242186E700641C39 /* NotificationServiceExtensionContext.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NotificationServiceExtensionContext.swift; sourceTree = "<group>"; };
@ -2074,6 +2076,13 @@
path = SessionNotificationServiceExtension;
sourceTree = "<group>";
};
7BC707EB272788CC002817AD /* CallKit */ = {
isa = PBXGroup;
children = (
);
path = CallKit;
sourceTree = "<group>";
};
9404664EC513585B05DF1350 /* Pods */ = {
isa = PBXGroup;
children = (
@ -2361,6 +2370,7 @@
7B1581E5271FD2A100848B49 /* VideoPreviewVC.swift */,
B877E24526CA13BA0007970A /* CallVC+Camera.swift */,
B8B558F026C4BB0600693325 /* CameraManager.swift */,
7BC707EB272788CC002817AD /* CallKit */,
7B7CB18C270D06350079FF93 /* Views & Modals */,
);
path = Calls;
@ -3475,6 +3485,7 @@
76EB03C218170B33006006FC /* AppDelegate.h */,
76EB03C318170B33006006FC /* AppDelegate.m */,
C3AAFFF125AE99710089E6DD /* AppDelegate.swift */,
7BC707E927267973002817AD /* AppDelegate+VoIP.swift */,
34D99CE3217509C1000AFB39 /* AppEnvironment.swift */,
B81D260326158DF5004D1FE1 /* Certificates */,
B8FF8E6025C10D8B004D1F22 /* Countries */,
@ -4937,6 +4948,7 @@
4CA46F4C219CCC630038ABDE /* CaptionView.swift in Sources */,
C328253025CA55370062D0A7 /* ContextMenuWindow.swift in Sources */,
340FC8B7204DAC8D007AEB0F /* OWSConversationSettingsViewController.m in Sources */,
7BC707EA27267973002817AD /* AppDelegate+VoIP.swift in Sources */,
7B1581E4271FC59D00848B49 /* CallModal.swift in Sources */,
34BECE2E1F7ABCE000D7438D /* GifPickerViewController.swift in Sources */,
B84664F5235022F30083A1CD /* MentionUtilities.swift in Sources */,

View File

@ -302,6 +302,15 @@ final class CallVC : UIViewController, WebRTCSessionDelegate, VideoPreviewDelega
}
}
func dataChannelDidOpen() {
// Send initial video status
if (isVideoEnabled) {
webRTCSession.turnOnVideo()
} else {
webRTCSession.turnOffVideo()
}
}
// MARK: Interaction
func handleAnswerMessage(_ message: CallMessage) {
callInfoLabel.text = "Connecting..."

View File

@ -0,0 +1,21 @@
import PushKit
import SessionUtilitiesKit
extension AppDelegate: PKPushRegistryDelegate {
@objc public func registerVoIP() {
let pushRegistry = PKPushRegistry(queue: .main)
pushRegistry.delegate = self
pushRegistry.desiredPushTypes = [.voIP]
}
public func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
let device = NSData(data: pushCredentials.token)
let deviceId = device.description.replacingOccurrences(of:"<", with:"").replacingOccurrences(of:">", with:"").replacingOccurrences(of:" ", with:"")
SNLog(deviceId)
}
public func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
SNLog("Incoming VoIP with payload \(payload)")
}
}

View File

@ -149,6 +149,8 @@ static NSTimeInterval launchStartedAt;
launchStartedAt = CACurrentMediaTime();
[LKAppModeManager configureWithDelegate:self];
[self registerVoIP];
// OWSLinkPreview is now in SessionMessagingKit, so to still be able to deserialize them we
// need to tell NSKeyedUnarchiver about the changes.

View File

@ -6,6 +6,7 @@ public protocol WebRTCSessionDelegate : AnyObject {
func webRTCIsConnected()
func isRemoteVideoDidChange(isEnabled: Bool)
func dataChannelDidOpen()
}
/// See https://webrtc.org/getting-started/overview for more information.
@ -250,6 +251,9 @@ public final class WebRTCSession : NSObject, RTCPeerConnectionDelegate {
public func peerConnectionShouldNegotiate(_ peerConnection: RTCPeerConnection) {
print("[Calls] Peer connection should negotiate.")
Storage.write { transaction in
self.sendOffer(to: self.contactSessionID, using: transaction).retainUntilComplete()
}
}
public func peerConnection(_ peerConnection: RTCPeerConnection, didChange state: RTCIceConnectionState) {
@ -274,6 +278,7 @@ public final class WebRTCSession : NSObject, RTCPeerConnectionDelegate {
public func peerConnection(_ peerConnection: RTCPeerConnection, didOpen dataChannel: RTCDataChannel) {
print("[Calls] Data channel opened.")
self.remoteDataChannel = dataChannel
delegate?.dataChannelDidOpen()
}
}