From 030c869d06d9e773875a17d0b1c658283af1adf3 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Tue, 10 Aug 2021 14:09:45 +1000 Subject: [PATCH] Add WebRTC dependency & implement CallMessage --- Podfile | 2 + Podfile.lock | 6 +- Session.xcodeproj/project.pbxproj | 30 ++ SessionMessagingKit/Calls/File.swift | 16 + .../Control Messages/CallMessage.swift | 101 ++++++ .../Protos/Generated/SNProto.swift | 153 +++++++++ .../Protos/Generated/SessionProtos.pb.swift | 309 ++++++++++++++---- .../Protos/SessionProtos.proto | 19 +- 8 files changed, 568 insertions(+), 68 deletions(-) create mode 100644 SessionMessagingKit/Calls/File.swift create mode 100644 SessionMessagingKit/Messages/Control Messages/CallMessage.swift diff --git a/Podfile b/Podfile index 5452d4e81..1369c0913 100644 --- a/Podfile +++ b/Podfile @@ -12,6 +12,7 @@ target 'Session' do pod 'PureLayout', '~> 3.1.8', :inhibit_warnings => true pod 'Reachability', :inhibit_warnings => true pod 'Sodium', '~> 0.8.0', :inhibit_warnings => true + pod 'WebRTC', '~> 63.11', :inhibit_warnings => true pod 'YapDatabase/SQLCipher', :git => 'https://github.com/loki-project/session-ios-yap-database.git', branch: 'signal-release', :inhibit_warnings => true pod 'YYImage', git: 'https://github.com/signalapp/YYImage', :inhibit_warnings => true pod 'ZXingObjC', :inhibit_warnings => true @@ -69,6 +70,7 @@ target 'SessionMessagingKit' do pod 'SignalCoreKit', git: 'https://github.com/signalapp/SignalCoreKit.git', :inhibit_warnings => true pod 'Sodium', '~> 0.8.0', :inhibit_warnings => true pod 'SwiftProtobuf', '~> 1.5.0', :inhibit_warnings => true + pod 'WebRTC', '~> 63.11', :inhibit_warnings => true pod 'YapDatabase/SQLCipher', :git => 'https://github.com/loki-project/session-ios-yap-database.git', branch: 'signal-release', :inhibit_warnings => true end diff --git a/Podfile.lock b/Podfile.lock index 804a148c7..86d31c1b4 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -51,6 +51,7 @@ PODS: - SQLCipher/standard (4.4.0): - SQLCipher/common - SwiftProtobuf (1.5.0) + - WebRTC (63.11.20455) - YapDatabase/SQLCipher (3.1.1): - YapDatabase/SQLCipher/Core (= 3.1.1) - YapDatabase/SQLCipher/Extensions (= 3.1.1) @@ -135,6 +136,7 @@ DEPENDENCIES: - SignalCoreKit (from `https://github.com/signalapp/SignalCoreKit.git`) - Sodium (~> 0.8.0) - SwiftProtobuf (~> 1.5.0) + - WebRTC (~> 63.11) - YapDatabase/SQLCipher (from `https://github.com/loki-project/session-ios-yap-database.git`, branch `signal-release`) - YYImage (from `https://github.com/signalapp/YYImage`) - ZXingObjC @@ -154,6 +156,7 @@ SPEC REPOS: - Sodium - SQLCipher - SwiftProtobuf + - WebRTC - ZXingObjC EXTERNAL SOURCES: @@ -204,10 +207,11 @@ SPEC CHECKSUMS: Sodium: 63c0ca312a932e6da481689537d4b35568841bdc SQLCipher: e434ed542b24f38ea7b36468a13f9765e1b5c072 SwiftProtobuf: 241400280f912735c1e1b9fe675fdd2c6c4d42e2 + WebRTC: f2a6203584745fe53532633397557876b5d71640 YapDatabase: b418a4baa6906e8028748938f9159807fd039af4 YYImage: 6db68da66f20d9f169ceb94dfb9947c3867b9665 ZXingObjC: fdbb269f25dd2032da343e06f10224d62f537bdb -PODFILE CHECKSUM: 50e6a35c838ba28d2ee02bc6018fdd297c04e55f +PODFILE CHECKSUM: 15bcb2aeee31dc86a3a9febc85208ba890b0dddf COCOAPODS: 1.10.1 diff --git a/Session.xcodeproj/project.pbxproj b/Session.xcodeproj/project.pbxproj index 6facfea31..8823383d9 100644 --- a/Session.xcodeproj/project.pbxproj +++ b/Session.xcodeproj/project.pbxproj @@ -266,6 +266,8 @@ B8D64FCB25BA78A90029CFC0 /* SignalUtilitiesKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C33FD9AB255A548A00E217F9 /* SignalUtilitiesKit.framework */; }; B8D84EA325DF745A005A043E /* LinkPreviewState.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8D84EA225DF745A005A043E /* LinkPreviewState.swift */; }; B8D84ECF25E3108A005A043E /* ExpandingAttachmentsButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8D84ECE25E3108A005A043E /* ExpandingAttachmentsButton.swift */; }; + B8DE1FB426C22F2F0079C9CE /* File.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8DE1FB326C22F2F0079C9CE /* File.swift */; }; + B8DE1FB626C22FCB0079C9CE /* CallMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8DE1FB526C22FCB0079C9CE /* CallMessage.swift */; }; B8EB20EE2640F28000773E52 /* VisibleMessage+OpenGroupInvitation.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8EB20ED2640F28000773E52 /* VisibleMessage+OpenGroupInvitation.swift */; }; B8EB20F02640F7F000773E52 /* OpenGroupInvitationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8EB20EF2640F7F000773E52 /* OpenGroupInvitationView.swift */; }; B8F5F52925EC4F8A003BF8D4 /* BlockListUIUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = B8F5F52825EC4F8A003BF8D4 /* BlockListUIUtils.m */; }; @@ -1245,6 +1247,9 @@ B8D8F19225661BF80092EF10 /* Storage+Messaging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Storage+Messaging.swift"; sourceTree = ""; }; B8D8F1BC25661C6F0092EF10 /* Storage+OnionRequests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Storage+OnionRequests.swift"; sourceTree = ""; }; B8D8F1EF256621180092EF10 /* MessageSender+Convenience.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = "MessageSender+Convenience.swift"; path = "../../SignalUtilitiesKit/Messaging/Sending & Receiving/MessageSender+Convenience.swift"; sourceTree = ""; }; + B8DE1FAF26C228780079C9CE /* SignalRingRTC.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SignalRingRTC.framework; path = Dependencies/SignalRingRTC.framework; sourceTree = ""; }; + B8DE1FB326C22F2F0079C9CE /* File.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = File.swift; sourceTree = ""; }; + B8DE1FB526C22FCB0079C9CE /* CallMessage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CallMessage.swift; sourceTree = ""; }; B8EB20E6263F7E4B00773E52 /* sk */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sk; path = sk.lproj/Localizable.strings; sourceTree = ""; }; B8EB20ED2640F28000773E52 /* VisibleMessage+OpenGroupInvitation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "VisibleMessage+OpenGroupInvitation.swift"; sourceTree = ""; }; B8EB20EF2640F7F000773E52 /* OpenGroupInvitationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenGroupInvitationView.swift; sourceTree = ""; }; @@ -2329,6 +2334,21 @@ path = Shared; sourceTree = ""; }; + B8DE1FB126C22AF20079C9CE /* Calls */ = { + isa = PBXGroup; + children = ( + ); + path = Calls; + sourceTree = ""; + }; + B8DE1FB226C22F1F0079C9CE /* Calls */ = { + isa = PBXGroup; + children = ( + B8DE1FB326C22F2F0079C9CE /* File.swift */, + ); + path = Calls; + sourceTree = ""; + }; B8F5F61925EDE4B0003BF8D4 /* Data Extraction */ = { isa = PBXGroup; children = ( @@ -2376,6 +2396,7 @@ isa = PBXGroup; children = ( C3C2A7702553A41E00C340D1 /* ControlMessage.swift */, + B8DE1FB526C22FCB0079C9CE /* CallMessage.swift */, C300A5BC2554B00D00555489 /* ReadReceipt.swift */, C300A5D22554B05A00555489 /* TypingIndicator.swift */, C34A977325A3E34A00852C71 /* ClosedGroupControlMessage.swift */, @@ -3239,6 +3260,7 @@ C32C5BB9256DC7C4003C73A2 /* To Do */, C3BBE0752554CDA60050F1E3 /* Configuration.swift */, C3BBE07F2554CDD70050F1E3 /* Storage.swift */, + B8DE1FB226C22F1F0079C9CE /* Calls */, B8B3201F258B1A540020074B /* Contacts */, C32C5BCB256DC818003C73A2 /* Database */, C300A5BB2554AFFB00555489 /* Messages */, @@ -3457,6 +3479,7 @@ D221A08C169C9E5E00537ABF /* Frameworks */ = { isa = PBXGroup; children = ( + B8DE1FAF26C228780079C9CE /* SignalRingRTC.framework */, C35E8AA22485C72300ACB629 /* SwiftCSV.framework */, B847570023D568EB00759540 /* SignalServiceKit.framework */, 3496955F21A2FC8100DCFE74 /* CloudKit.framework */, @@ -3511,6 +3534,7 @@ children = ( C3F0A58F255C8E3D007BE2A3 /* Meta */, C36096BC25AD1C3E008B62B2 /* Backups */, + B8DE1FB126C22AF20079C9CE /* Calls */, C360969C25AD18BA008B62B2 /* Closed Groups */, B835246C25C38AA20089A44F /* Conversations */, C32B405424A961E1001117B5 /* Dependencies */, @@ -4204,6 +4228,7 @@ "${BUILT_PRODUCTS_DIR}/Reachability/Reachability.framework", "${BUILT_PRODUCTS_DIR}/SQLCipher/SQLCipher.framework", "${BUILT_PRODUCTS_DIR}/Sodium/Sodium.framework", + "${PODS_ROOT}/WebRTC/WebRTC.framework", "${BUILT_PRODUCTS_DIR}/YYImage/YYImage.framework", "${BUILT_PRODUCTS_DIR}/YapDatabase/YapDatabase.framework", "${BUILT_PRODUCTS_DIR}/ZXingObjC/ZXingObjC.framework", @@ -4226,6 +4251,7 @@ "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Reachability.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SQLCipher.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Sodium.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/WebRTC.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/YYImage.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/YapDatabase.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ZXingObjC.framework", @@ -4667,8 +4693,10 @@ B8856ECE256F1E58001CE70E /* OWSPreferences.m in Sources */, C3C2A7842553AAF300C340D1 /* SNProto.swift in Sources */, C32C5DC0256DD743003C73A2 /* Poller.swift in Sources */, + B8DE1FB426C22F2F0079C9CE /* File.swift in Sources */, C3C2A7682553A3D900C340D1 /* VisibleMessage+Contact.swift in Sources */, C3A3A171256E1D25004D228D /* SSKReachabilityManager.swift in Sources */, + B8DE1FB626C22FCB0079C9CE /* CallMessage.swift in Sources */, C3A71D0B2558989C0043A11F /* MessageWrapper.swift in Sources */, B8F5F60325EDE16F003BF8D4 /* DataExtractionNotification.swift in Sources */, C32C5D24256DD4C0003C73A2 /* MentionsManager.swift in Sources */, @@ -6165,6 +6193,7 @@ FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(SRCROOT)", + "$(PROJECT_DIR)/Dependencies", ); GCC_OPTIMIZATION_LEVEL = 0; GCC_PRECOMPILE_PREFIX_HEADER = YES; @@ -6233,6 +6262,7 @@ FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(SRCROOT)", + "$(PROJECT_DIR)/Dependencies", ); GCC_OPTIMIZATION_LEVEL = 3; GCC_PRECOMPILE_PREFIX_HEADER = YES; diff --git a/SessionMessagingKit/Calls/File.swift b/SessionMessagingKit/Calls/File.swift new file mode 100644 index 000000000..16c7be30c --- /dev/null +++ b/SessionMessagingKit/Calls/File.swift @@ -0,0 +1,16 @@ +// +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. +// + +import WebRTC + +//The RTCSessionDescription interface describes one end of a connection—or potential connection—and how it's configured. Each RTCSessionDescription consists of a description type indicating which part of the offer/answer negotiation process it describes and of the SDP descriptor of the session. + +enum Foo { + + func bar() { + + + RTCSessionDescription(type: .answer, sdp: "") + } +} diff --git a/SessionMessagingKit/Messages/Control Messages/CallMessage.swift b/SessionMessagingKit/Messages/Control Messages/CallMessage.swift new file mode 100644 index 000000000..4b35f08e9 --- /dev/null +++ b/SessionMessagingKit/Messages/Control Messages/CallMessage.swift @@ -0,0 +1,101 @@ +import WebRTC + +/// See https://developer.mozilla.org/en-US/docs/Web/API/RTCSessionDescription for more information. +@objc(SNCallMessage) +public final class CallMessage : ControlMessage { + public var type: RTCSdpType? + /// See https://developer.mozilla.org/en-US/docs/Glossary/SDP for more information. + public var sdp: String? + + // MARK: Initialization + public override init() { super.init() } + + internal init(type: RTCSdpType, sdp: String) { + super.init() + self.type = type + self.sdp = sdp + } + + // MARK: Validation + public override var isValid: Bool { + guard super.isValid else { return false } + return type != nil && sdp != nil + } + + // MARK: Coding + public required init?(coder: NSCoder) { + super.init(coder: coder) + if let type = coder.decodeObject(forKey: "type") as! RTCSdpType? { self.type = type } + if let sdp = coder.decodeObject(forKey: "sdp") as! String? { self.sdp = sdp } + } + + public override func encode(with coder: NSCoder) { + super.encode(with: coder) + coder.encode(type, forKey: "type") + coder.encode(sdp, forKey: "sdp") + } + + // MARK: Proto Conversion + public override class func fromProto(_ proto: SNProtoContent) -> CallMessage? { + guard let callMessageProto = proto.callMessage else { return nil } + let type = callMessageProto.type + let sdp = callMessageProto.sdp + return CallMessage(type: RTCSdpType.from(type), sdp: sdp) + } + + public override func toProto(using transaction: YapDatabaseReadWriteTransaction) -> SNProtoContent? { + guard let type = type, let sdp = sdp else { + SNLog("Couldn't construct call message proto from: \(self).") + return nil + } + let callMessageProto = SNProtoCallMessage.builder(type: type.toProto(), sdp: sdp) + let contentProto = SNProtoContent.builder() + do { + contentProto.setCallMessage(try callMessageProto.build()) + return try contentProto.build() + } catch { + SNLog("Couldn't construct call message proto from: \(self).") + return nil + } + } + + // MARK: Description + public override var description: String { + """ + CallMessage( + type: \(type?.description ?? "null"), + sdp: \(sdp ?? "null") + ) + """ + } +} + +// MARK: RTCSdpType + Utilities +extension RTCSdpType : CustomStringConvertible { + + public var description: String { + switch self { + case .answer: return "answer" + case .offer: return "offer" + case .prAnswer: return "prAnswer" + default: preconditionFailure() + } + } + + fileprivate static func from(_ type: SNProtoCallMessage.SNProtoCallMessageType) -> RTCSdpType { + switch type { + case .answer: return .answer + case .offer: return .offer + case .provisionalAnswer: return .prAnswer + } + } + + fileprivate func toProto() -> SNProtoCallMessage.SNProtoCallMessageType { + switch self { + case .answer: return .answer + case .offer: return .offer + case .prAnswer: return .provisionalAnswer + default: preconditionFailure() + } + } +} diff --git a/SessionMessagingKit/Protos/Generated/SNProto.swift b/SessionMessagingKit/Protos/Generated/SNProto.swift index 8d4f98a4e..8da553d2b 100644 --- a/SessionMessagingKit/Protos/Generated/SNProto.swift +++ b/SessionMessagingKit/Protos/Generated/SNProto.swift @@ -466,6 +466,9 @@ extension SNProtoUnsendRequest.SNProtoUnsendRequestBuilder { if let _value = dataMessage { builder.setDataMessage(_value) } + if let _value = callMessage { + builder.setCallMessage(_value) + } if let _value = receiptMessage { builder.setReceiptMessage(_value) } @@ -494,6 +497,10 @@ extension SNProtoUnsendRequest.SNProtoUnsendRequestBuilder { proto.dataMessage = valueParam.proto } + @objc public func setCallMessage(_ valueParam: SNProtoCallMessage) { + proto.callMessage = valueParam.proto + } + @objc public func setReceiptMessage(_ valueParam: SNProtoReceiptMessage) { proto.receiptMessage = valueParam.proto } @@ -527,6 +534,8 @@ extension SNProtoUnsendRequest.SNProtoUnsendRequestBuilder { @objc public let dataMessage: SNProtoDataMessage? + @objc public let callMessage: SNProtoCallMessage? + @objc public let receiptMessage: SNProtoReceiptMessage? @objc public let typingMessage: SNProtoTypingMessage? @@ -539,6 +548,7 @@ extension SNProtoUnsendRequest.SNProtoUnsendRequestBuilder { private init(proto: SessionProtos_Content, dataMessage: SNProtoDataMessage?, + callMessage: SNProtoCallMessage?, receiptMessage: SNProtoReceiptMessage?, typingMessage: SNProtoTypingMessage?, configurationMessage: SNProtoConfigurationMessage?, @@ -546,6 +556,7 @@ extension SNProtoUnsendRequest.SNProtoUnsendRequestBuilder { unsendRequest: SNProtoUnsendRequest?) { self.proto = proto self.dataMessage = dataMessage + self.callMessage = callMessage self.receiptMessage = receiptMessage self.typingMessage = typingMessage self.configurationMessage = configurationMessage @@ -569,6 +580,11 @@ extension SNProtoUnsendRequest.SNProtoUnsendRequestBuilder { dataMessage = try SNProtoDataMessage.parseProto(proto.dataMessage) } + var callMessage: SNProtoCallMessage? = nil + if proto.hasCallMessage { + callMessage = try SNProtoCallMessage.parseProto(proto.callMessage) + } + var receiptMessage: SNProtoReceiptMessage? = nil if proto.hasReceiptMessage { receiptMessage = try SNProtoReceiptMessage.parseProto(proto.receiptMessage) @@ -600,6 +616,7 @@ extension SNProtoUnsendRequest.SNProtoUnsendRequestBuilder { let result = SNProtoContent(proto: proto, dataMessage: dataMessage, + callMessage: callMessage, receiptMessage: receiptMessage, typingMessage: typingMessage, configurationMessage: configurationMessage, @@ -629,6 +646,142 @@ extension SNProtoContent.SNProtoContentBuilder { #endif +// MARK: - SNProtoCallMessage + +@objc public class SNProtoCallMessage: NSObject { + + // MARK: - SNProtoCallMessageType + + @objc public enum SNProtoCallMessageType: Int32 { + case offer = 1 + case answer = 2 + case provisionalAnswer = 3 + } + + private class func SNProtoCallMessageTypeWrap(_ value: SessionProtos_CallMessage.TypeEnum) -> SNProtoCallMessageType { + switch value { + case .offer: return .offer + case .answer: return .answer + case .provisionalAnswer: return .provisionalAnswer + } + } + + private class func SNProtoCallMessageTypeUnwrap(_ value: SNProtoCallMessageType) -> SessionProtos_CallMessage.TypeEnum { + switch value { + case .offer: return .offer + case .answer: return .answer + case .provisionalAnswer: return .provisionalAnswer + } + } + + // MARK: - SNProtoCallMessageBuilder + + @objc public class func builder(type: SNProtoCallMessageType, sdp: String) -> SNProtoCallMessageBuilder { + return SNProtoCallMessageBuilder(type: type, sdp: sdp) + } + + // asBuilder() constructs a builder that reflects the proto's contents. + @objc public func asBuilder() -> SNProtoCallMessageBuilder { + let builder = SNProtoCallMessageBuilder(type: type, sdp: sdp) + return builder + } + + @objc public class SNProtoCallMessageBuilder: NSObject { + + private var proto = SessionProtos_CallMessage() + + @objc fileprivate override init() {} + + @objc fileprivate init(type: SNProtoCallMessageType, sdp: String) { + super.init() + + setType(type) + setSdp(sdp) + } + + @objc public func setType(_ valueParam: SNProtoCallMessageType) { + proto.type = SNProtoCallMessageTypeUnwrap(valueParam) + } + + @objc public func setSdp(_ valueParam: String) { + proto.sdp = valueParam + } + + @objc public func build() throws -> SNProtoCallMessage { + return try SNProtoCallMessage.parseProto(proto) + } + + @objc public func buildSerializedData() throws -> Data { + return try SNProtoCallMessage.parseProto(proto).serializedData() + } + } + + fileprivate let proto: SessionProtos_CallMessage + + @objc public let type: SNProtoCallMessageType + + @objc public let sdp: String + + private init(proto: SessionProtos_CallMessage, + type: SNProtoCallMessageType, + sdp: String) { + self.proto = proto + self.type = type + self.sdp = sdp + } + + @objc + public func serializedData() throws -> Data { + return try self.proto.serializedData() + } + + @objc public class func parseData(_ serializedData: Data) throws -> SNProtoCallMessage { + let proto = try SessionProtos_CallMessage(serializedData: serializedData) + return try parseProto(proto) + } + + fileprivate class func parseProto(_ proto: SessionProtos_CallMessage) throws -> SNProtoCallMessage { + guard proto.hasType else { + throw SNProtoError.invalidProtobuf(description: "\(logTag) missing required field: type") + } + let type = SNProtoCallMessageTypeWrap(proto.type) + + guard proto.hasSdp else { + throw SNProtoError.invalidProtobuf(description: "\(logTag) missing required field: sdp") + } + let sdp = proto.sdp + + // MARK: - Begin Validation Logic for SNProtoCallMessage - + + // MARK: - End Validation Logic for SNProtoCallMessage - + + let result = SNProtoCallMessage(proto: proto, + type: type, + sdp: sdp) + return result + } + + @objc public override var debugDescription: String { + return "\(proto)" + } +} + +#if DEBUG + +extension SNProtoCallMessage { + @objc public func serializedDataIgnoringErrors() -> Data? { + return try! self.serializedData() + } +} + +extension SNProtoCallMessage.SNProtoCallMessageBuilder { + @objc public func buildIgnoringErrors() -> SNProtoCallMessage? { + return try! self.build() + } +} + +#endif + // MARK: - SNProtoKeyPair @objc public class SNProtoKeyPair: NSObject { diff --git a/SessionMessagingKit/Protos/Generated/SessionProtos.pb.swift b/SessionMessagingKit/Protos/Generated/SessionProtos.pb.swift index ea16218a6..1114aba7e 100644 --- a/SessionMessagingKit/Protos/Generated/SessionProtos.pb.swift +++ b/SessionMessagingKit/Protos/Generated/SessionProtos.pb.swift @@ -235,71 +235,145 @@ struct SessionProtos_Content { // methods supported on all messages. var dataMessage: SessionProtos_DataMessage { - get {return _dataMessage ?? SessionProtos_DataMessage()} - set {_dataMessage = newValue} + get {return _storage._dataMessage ?? SessionProtos_DataMessage()} + set {_uniqueStorage()._dataMessage = newValue} } /// Returns true if `dataMessage` has been explicitly set. - var hasDataMessage: Bool {return self._dataMessage != nil} + var hasDataMessage: Bool {return _storage._dataMessage != nil} /// Clears the value of `dataMessage`. Subsequent reads from it will return its default value. - mutating func clearDataMessage() {self._dataMessage = nil} + mutating func clearDataMessage() {_uniqueStorage()._dataMessage = nil} + + var callMessage: SessionProtos_CallMessage { + get {return _storage._callMessage ?? SessionProtos_CallMessage()} + set {_uniqueStorage()._callMessage = newValue} + } + /// Returns true if `callMessage` has been explicitly set. + var hasCallMessage: Bool {return _storage._callMessage != nil} + /// Clears the value of `callMessage`. Subsequent reads from it will return its default value. + mutating func clearCallMessage() {_uniqueStorage()._callMessage = nil} var receiptMessage: SessionProtos_ReceiptMessage { - get {return _receiptMessage ?? SessionProtos_ReceiptMessage()} - set {_receiptMessage = newValue} + get {return _storage._receiptMessage ?? SessionProtos_ReceiptMessage()} + set {_uniqueStorage()._receiptMessage = newValue} } /// Returns true if `receiptMessage` has been explicitly set. - var hasReceiptMessage: Bool {return self._receiptMessage != nil} + var hasReceiptMessage: Bool {return _storage._receiptMessage != nil} /// Clears the value of `receiptMessage`. Subsequent reads from it will return its default value. - mutating func clearReceiptMessage() {self._receiptMessage = nil} + mutating func clearReceiptMessage() {_uniqueStorage()._receiptMessage = nil} var typingMessage: SessionProtos_TypingMessage { - get {return _typingMessage ?? SessionProtos_TypingMessage()} - set {_typingMessage = newValue} + get {return _storage._typingMessage ?? SessionProtos_TypingMessage()} + set {_uniqueStorage()._typingMessage = newValue} } /// Returns true if `typingMessage` has been explicitly set. - var hasTypingMessage: Bool {return self._typingMessage != nil} + var hasTypingMessage: Bool {return _storage._typingMessage != nil} /// Clears the value of `typingMessage`. Subsequent reads from it will return its default value. - mutating func clearTypingMessage() {self._typingMessage = nil} + mutating func clearTypingMessage() {_uniqueStorage()._typingMessage = nil} var configurationMessage: SessionProtos_ConfigurationMessage { - get {return _configurationMessage ?? SessionProtos_ConfigurationMessage()} - set {_configurationMessage = newValue} + get {return _storage._configurationMessage ?? SessionProtos_ConfigurationMessage()} + set {_uniqueStorage()._configurationMessage = newValue} } /// Returns true if `configurationMessage` has been explicitly set. - var hasConfigurationMessage: Bool {return self._configurationMessage != nil} + var hasConfigurationMessage: Bool {return _storage._configurationMessage != nil} /// Clears the value of `configurationMessage`. Subsequent reads from it will return its default value. - mutating func clearConfigurationMessage() {self._configurationMessage = nil} + mutating func clearConfigurationMessage() {_uniqueStorage()._configurationMessage = nil} var dataExtractionNotification: SessionProtos_DataExtractionNotification { - get {return _dataExtractionNotification ?? SessionProtos_DataExtractionNotification()} - set {_dataExtractionNotification = newValue} + get {return _storage._dataExtractionNotification ?? SessionProtos_DataExtractionNotification()} + set {_uniqueStorage()._dataExtractionNotification = newValue} } /// Returns true if `dataExtractionNotification` has been explicitly set. - var hasDataExtractionNotification: Bool {return self._dataExtractionNotification != nil} + var hasDataExtractionNotification: Bool {return _storage._dataExtractionNotification != nil} /// Clears the value of `dataExtractionNotification`. Subsequent reads from it will return its default value. - mutating func clearDataExtractionNotification() {self._dataExtractionNotification = nil} + mutating func clearDataExtractionNotification() {_uniqueStorage()._dataExtractionNotification = nil} var unsendRequest: SessionProtos_UnsendRequest { - get {return _unsendRequest ?? SessionProtos_UnsendRequest()} - set {_unsendRequest = newValue} + get {return _storage._unsendRequest ?? SessionProtos_UnsendRequest()} + set {_uniqueStorage()._unsendRequest = newValue} } /// Returns true if `unsendRequest` has been explicitly set. - var hasUnsendRequest: Bool {return self._unsendRequest != nil} + var hasUnsendRequest: Bool {return _storage._unsendRequest != nil} /// Clears the value of `unsendRequest`. Subsequent reads from it will return its default value. - mutating func clearUnsendRequest() {self._unsendRequest = nil} + mutating func clearUnsendRequest() {_uniqueStorage()._unsendRequest = nil} + + var unknownFields = SwiftProtobuf.UnknownStorage() + + init() {} + + fileprivate var _storage = _StorageClass.defaultInstance +} + +struct SessionProtos_CallMessage { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// @required + var type: SessionProtos_CallMessage.TypeEnum { + get {return _type ?? .offer} + set {_type = newValue} + } + /// Returns true if `type` has been explicitly set. + var hasType: Bool {return self._type != nil} + /// Clears the value of `type`. Subsequent reads from it will return its default value. + mutating func clearType() {self._type = nil} + + /// @required + var sdp: String { + get {return _sdp ?? String()} + set {_sdp = newValue} + } + /// Returns true if `sdp` has been explicitly set. + var hasSdp: Bool {return self._sdp != nil} + /// Clears the value of `sdp`. Subsequent reads from it will return its default value. + mutating func clearSdp() {self._sdp = nil} var unknownFields = SwiftProtobuf.UnknownStorage() + enum TypeEnum: SwiftProtobuf.Enum { + typealias RawValue = Int + case offer // = 1 + case answer // = 2 + case provisionalAnswer // = 3 + + init() { + self = .offer + } + + init?(rawValue: Int) { + switch rawValue { + case 1: self = .offer + case 2: self = .answer + case 3: self = .provisionalAnswer + default: return nil + } + } + + var rawValue: Int { + switch self { + case .offer: return 1 + case .answer: return 2 + case .provisionalAnswer: return 3 + } + } + + } + init() {} - fileprivate var _dataMessage: SessionProtos_DataMessage? = nil - fileprivate var _receiptMessage: SessionProtos_ReceiptMessage? = nil - fileprivate var _typingMessage: SessionProtos_TypingMessage? = nil - fileprivate var _configurationMessage: SessionProtos_ConfigurationMessage? = nil - fileprivate var _dataExtractionNotification: SessionProtos_DataExtractionNotification? = nil - fileprivate var _unsendRequest: SessionProtos_UnsendRequest? = nil + fileprivate var _type: SessionProtos_CallMessage.TypeEnum? = nil + fileprivate var _sdp: String? = nil } +#if swift(>=4.2) + +extension SessionProtos_CallMessage.TypeEnum: CaseIterable { + // Support synthesized by the compiler. +} + +#endif // swift(>=4.2) + struct SessionProtos_KeyPair { // SwiftProtobuf.Message conformance is added in an extension below. See the // `Message` and `Message+*Additions` files in the SwiftProtobuf library for @@ -1595,6 +1669,7 @@ extension SessionProtos_Content: SwiftProtobuf.Message, SwiftProtobuf._MessageIm static let protoMessageName: String = _protobuf_package + ".Content" static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ 1: .same(proto: "dataMessage"), + 3: .same(proto: "callMessage"), 5: .same(proto: "receiptMessage"), 6: .same(proto: "typingMessage"), 7: .same(proto: "configurationMessage"), @@ -1602,13 +1677,129 @@ extension SessionProtos_Content: SwiftProtobuf.Message, SwiftProtobuf._MessageIm 9: .same(proto: "unsendRequest"), ] + fileprivate class _StorageClass { + var _dataMessage: SessionProtos_DataMessage? = nil + var _callMessage: SessionProtos_CallMessage? = nil + var _receiptMessage: SessionProtos_ReceiptMessage? = nil + var _typingMessage: SessionProtos_TypingMessage? = nil + var _configurationMessage: SessionProtos_ConfigurationMessage? = nil + var _dataExtractionNotification: SessionProtos_DataExtractionNotification? = nil + var _unsendRequest: SessionProtos_UnsendRequest? = nil + + static let defaultInstance = _StorageClass() + + private init() {} + + init(copying source: _StorageClass) { + _dataMessage = source._dataMessage + _callMessage = source._callMessage + _receiptMessage = source._receiptMessage + _typingMessage = source._typingMessage + _configurationMessage = source._configurationMessage + _dataExtractionNotification = source._dataExtractionNotification + _unsendRequest = source._unsendRequest + } + } + + fileprivate mutating func _uniqueStorage() -> _StorageClass { + if !isKnownUniquelyReferenced(&_storage) { + _storage = _StorageClass(copying: _storage) + } + return _storage + } + + public var isInitialized: Bool { + return withExtendedLifetime(_storage) { (_storage: _StorageClass) in + if let v = _storage._dataMessage, !v.isInitialized {return false} + if let v = _storage._callMessage, !v.isInitialized {return false} + if let v = _storage._receiptMessage, !v.isInitialized {return false} + if let v = _storage._typingMessage, !v.isInitialized {return false} + if let v = _storage._configurationMessage, !v.isInitialized {return false} + if let v = _storage._dataExtractionNotification, !v.isInitialized {return false} + if let v = _storage._unsendRequest, !v.isInitialized {return false} + return true + } + } + + mutating func decodeMessage(decoder: inout D) throws { + _ = _uniqueStorage() + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &_storage._dataMessage) }() + case 3: try { try decoder.decodeSingularMessageField(value: &_storage._callMessage) }() + case 5: try { try decoder.decodeSingularMessageField(value: &_storage._receiptMessage) }() + case 6: try { try decoder.decodeSingularMessageField(value: &_storage._typingMessage) }() + case 7: try { try decoder.decodeSingularMessageField(value: &_storage._configurationMessage) }() + case 8: try { try decoder.decodeSingularMessageField(value: &_storage._dataExtractionNotification) }() + case 9: try { try decoder.decodeSingularMessageField(value: &_storage._unsendRequest) }() + default: break + } + } + } + } + + func traverse(visitor: inout V) throws { + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + if let v = _storage._dataMessage { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } + if let v = _storage._callMessage { + try visitor.visitSingularMessageField(value: v, fieldNumber: 3) + } + if let v = _storage._receiptMessage { + try visitor.visitSingularMessageField(value: v, fieldNumber: 5) + } + if let v = _storage._typingMessage { + try visitor.visitSingularMessageField(value: v, fieldNumber: 6) + } + if let v = _storage._configurationMessage { + try visitor.visitSingularMessageField(value: v, fieldNumber: 7) + } + if let v = _storage._dataExtractionNotification { + try visitor.visitSingularMessageField(value: v, fieldNumber: 8) + } + if let v = _storage._unsendRequest { + try visitor.visitSingularMessageField(value: v, fieldNumber: 9) + } + } + try unknownFields.traverse(visitor: &visitor) + } + + static func ==(lhs: SessionProtos_Content, rhs: SessionProtos_Content) -> Bool { + if lhs._storage !== rhs._storage { + let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in + let _storage = _args.0 + let rhs_storage = _args.1 + if _storage._dataMessage != rhs_storage._dataMessage {return false} + if _storage._callMessage != rhs_storage._callMessage {return false} + if _storage._receiptMessage != rhs_storage._receiptMessage {return false} + if _storage._typingMessage != rhs_storage._typingMessage {return false} + if _storage._configurationMessage != rhs_storage._configurationMessage {return false} + if _storage._dataExtractionNotification != rhs_storage._dataExtractionNotification {return false} + if _storage._unsendRequest != rhs_storage._unsendRequest {return false} + return true + } + if !storagesAreEqual {return false} + } + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension SessionProtos_CallMessage: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + static let protoMessageName: String = _protobuf_package + ".CallMessage" + static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "type"), + 2: .same(proto: "sdp"), + ] + public var isInitialized: Bool { - if let v = self._dataMessage, !v.isInitialized {return false} - if let v = self._receiptMessage, !v.isInitialized {return false} - if let v = self._typingMessage, !v.isInitialized {return false} - if let v = self._configurationMessage, !v.isInitialized {return false} - if let v = self._dataExtractionNotification, !v.isInitialized {return false} - if let v = self._unsendRequest, !v.isInitialized {return false} + if self._type == nil {return false} + if self._sdp == nil {return false} return true } @@ -1618,51 +1809,39 @@ extension SessionProtos_Content: SwiftProtobuf.Message, SwiftProtobuf._MessageIm // allocates stack space for every case branch when no optimizations are // enabled. https://github.com/apple/swift-protobuf/issues/1034 switch fieldNumber { - case 1: try { try decoder.decodeSingularMessageField(value: &self._dataMessage) }() - case 5: try { try decoder.decodeSingularMessageField(value: &self._receiptMessage) }() - case 6: try { try decoder.decodeSingularMessageField(value: &self._typingMessage) }() - case 7: try { try decoder.decodeSingularMessageField(value: &self._configurationMessage) }() - case 8: try { try decoder.decodeSingularMessageField(value: &self._dataExtractionNotification) }() - case 9: try { try decoder.decodeSingularMessageField(value: &self._unsendRequest) }() + case 1: try { try decoder.decodeSingularEnumField(value: &self._type) }() + case 2: try { try decoder.decodeSingularStringField(value: &self._sdp) }() default: break } } } func traverse(visitor: inout V) throws { - if let v = self._dataMessage { - try visitor.visitSingularMessageField(value: v, fieldNumber: 1) - } - if let v = self._receiptMessage { - try visitor.visitSingularMessageField(value: v, fieldNumber: 5) - } - if let v = self._typingMessage { - try visitor.visitSingularMessageField(value: v, fieldNumber: 6) - } - if let v = self._configurationMessage { - try visitor.visitSingularMessageField(value: v, fieldNumber: 7) - } - if let v = self._dataExtractionNotification { - try visitor.visitSingularMessageField(value: v, fieldNumber: 8) + if let v = self._type { + try visitor.visitSingularEnumField(value: v, fieldNumber: 1) } - if let v = self._unsendRequest { - try visitor.visitSingularMessageField(value: v, fieldNumber: 9) + if let v = self._sdp { + try visitor.visitSingularStringField(value: v, fieldNumber: 2) } try unknownFields.traverse(visitor: &visitor) } - static func ==(lhs: SessionProtos_Content, rhs: SessionProtos_Content) -> Bool { - if lhs._dataMessage != rhs._dataMessage {return false} - if lhs._receiptMessage != rhs._receiptMessage {return false} - if lhs._typingMessage != rhs._typingMessage {return false} - if lhs._configurationMessage != rhs._configurationMessage {return false} - if lhs._dataExtractionNotification != rhs._dataExtractionNotification {return false} - if lhs._unsendRequest != rhs._unsendRequest {return false} + static func ==(lhs: SessionProtos_CallMessage, rhs: SessionProtos_CallMessage) -> Bool { + if lhs._type != rhs._type {return false} + if lhs._sdp != rhs._sdp {return false} if lhs.unknownFields != rhs.unknownFields {return false} return true } } +extension SessionProtos_CallMessage.TypeEnum: SwiftProtobuf._ProtoNameProviding { + static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "OFFER"), + 2: .same(proto: "ANSWER"), + 3: .same(proto: "PROVISIONAL_ANSWER"), + ] +} + extension SessionProtos_KeyPair: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { static let protoMessageName: String = _protobuf_package + ".KeyPair" static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ diff --git a/SessionMessagingKit/Protos/SessionProtos.proto b/SessionMessagingKit/Protos/SessionProtos.proto index 5b1999255..76995d94a 100644 --- a/SessionMessagingKit/Protos/SessionProtos.proto +++ b/SessionMessagingKit/Protos/SessionProtos.proto @@ -39,15 +39,30 @@ message UnsendRequest { required uint64 timestamp = 1; // @required required string author = 2; -} +} message Content { optional DataMessage dataMessage = 1; + optional CallMessage callMessage = 3; optional ReceiptMessage receiptMessage = 5; optional TypingMessage typingMessage = 6; optional ConfigurationMessage configurationMessage = 7; optional DataExtractionNotification dataExtractionNotification = 8; - optional UnsendRequest unsendRequest = 9; + optional UnsendRequest unsendRequest = 9; +} + +message CallMessage { + + enum Type { + OFFER = 1; + ANSWER = 2; + PROVISIONAL_ANSWER = 3; + } + + // @required + required Type type = 1; + // @required + required string sdp = 2; } message KeyPair {