Migrate call proto wrappers.

pull/1/head
Matthew Chen 7 years ago
parent 94675e880a
commit 32d0f23b22

@ -84,7 +84,6 @@
#import <SignalServiceKit/OWSBackgroundTask.h>
#import <SignalServiceKit/OWSCallBusyMessage.h>
#import <SignalServiceKit/OWSCallHangupMessage.h>
#import <SignalServiceKit/OWSCallIceUpdateMessage.h>
#import <SignalServiceKit/OWSCallMessageHandler.h>
#import <SignalServiceKit/OWSContactsOutputStream.h>
#import <SignalServiceKit/OWSDispatch.h>

@ -78,7 +78,7 @@ public enum CallError: Error {
case externalError(underlyingError: Error)
case timeout(description: String)
case obsoleteCall(description: String)
case protoErro(description: String)
case fatalError(description: String)
}
// Should be roughly synced with Android client for consistency
@ -417,7 +417,7 @@ private class SignalCallData: NSObject {
return self.messageSender.sendPromise(message: callMessage)
} catch {
owsFail("Couldn't build proto in \(#function)")
throw CallError.protoErro(description: "Couldn't build proto in \(#function)")
throw CallError.fatalError(description: "Couldn't build proto in \(#function)")
}
}
}.then {
@ -722,7 +722,7 @@ private class SignalCallData: NSObject {
return self.messageSender.sendPromise(message: callAnswerMessage)
} catch {
owsFail("Couldn't build proto in \(#function)")
throw CallError.protoErro(description: "Couldn't build proto in \(#function)")
throw CallError.fatalError(description: "Couldn't build proto in \(#function)")
}
}.then {
guard self.call == newCall else {
@ -841,12 +841,38 @@ private class SignalCallData: NSObject {
return
}
let iceUpdateMessage = OWSCallIceUpdateMessage(callId: call.signalingId, sdp: iceCandidate.sdp, sdpMLineIndex: iceCandidate.sdpMLineIndex, sdpMid: iceCandidate.sdpMid)
guard let sdpMid = iceCandidate.sdpMid else {
owsFail("Missing sdpMid in \(#function)")
throw CallError.fatalError(description: "Missing sdpMid in \(#function)")
}
guard iceCandidate.sdpMLineIndex < UINT32_MAX else {
owsFail("Invalid sdpMLineIndex in \(#function)")
throw CallError.fatalError(description: "Invalid sdpMLineIndex in \(#function)")
}
Logger.info("\(self.logTag) in \(#function) sending ICE Candidate \(call.identifiersForLogs).")
let callMessage = OWSOutgoingCallMessage(thread: call.thread, iceUpdateMessage: iceUpdateMessage)
let sendPromise = self.messageSender.sendPromise(message: callMessage)
sendPromise.retainUntilComplete()
/**
* Sent by both parties out of band of the RTC calling channels, as part of setting up those channels. The messages
* include network accessibility information from the perspective of each client. Once compatible ICEUpdates have been
* exchanged, the clients can connect directly.
*/
let iceUpdateBuilder = SSKProtoCallMessageIceUpdate.SSKProtoCallMessageIceUpdateBuilder()
iceUpdateBuilder.setId(call.signalingId)
iceUpdateBuilder.setSdp(iceCandidate.sdp)
iceUpdateBuilder.setSdpMlineIndex(UInt32(iceCandidate.sdpMLineIndex))
iceUpdateBuilder.setSdpMid(sdpMid)
do {
let iceUpdate = try iceUpdateBuilder.build()
let callMessage = OWSOutgoingCallMessage(thread: call.thread, iceUpdateMessage: iceUpdate)
let sendPromise = self.messageSender.sendPromise(message: callMessage)
sendPromise.retainUntilComplete()
} catch {
owsFail("Couldn't build proto in \(#function)")
throw CallError.fatalError(description: "Couldn't build proto in \(#function)")
}
}.catch { error in
OWSProdInfo(OWSAnalyticsEvents.callServiceErrorHandleLocalAddedIceCandidate(), file: #file, function: #function, line: #line)
Logger.error("\(self.logTag) in \(#function) waitUntilReadyToSendIceUpdates failed with error: \(error)")

@ -1,30 +0,0 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
NS_ASSUME_NONNULL_BEGIN
@class SSKProtoCallMessageIceUpdate;
/**
* Sent by both parties out of band of the RTC calling channels, as part of setting up those channels. The messages
* include network accessability information from the perspective of each client. Once compatible ICEUpdates have been
* exchanged, the clients can connect directly.
*/
@interface OWSCallIceUpdateMessage : NSObject
- (instancetype)initWithCallId:(UInt64)callId
sdp:(NSString *)sdp
sdpMLineIndex:(SInt32)sdpMLineIndex
sdpMid:(nullable NSString *)sdpMid;
@property (nonatomic, readonly) UInt64 callId;
@property (nonatomic, readonly, copy) NSString *sdp;
@property (nonatomic, readonly) SInt32 sdpMLineIndex;
@property (nullable, nonatomic, readonly, copy) NSString *sdpMid;
- (nullable SSKProtoCallMessageIceUpdate *)asProtobuf;
@end
NS_ASSUME_NONNULL_END

@ -1,47 +0,0 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSCallIceUpdateMessage.h"
#import <SignalServiceKit/SignalServiceKit-Swift.h>
@implementation OWSCallIceUpdateMessage
- (instancetype)initWithCallId:(UInt64)callId
sdp:(NSString *)sdp
sdpMLineIndex:(SInt32)sdpMLineIndex
sdpMid:(nullable NSString *)sdpMid
{
self = [super init];
if (!self) {
return self;
}
_callId = callId;
_sdp = sdp;
_sdpMLineIndex = sdpMLineIndex;
_sdpMid = sdpMid;
return self;
}
- (nullable SSKProtoCallMessageIceUpdate *)asProtobuf
{
SSKProtoCallMessageIceUpdateBuilder *builder =
[SSKProtoCallMessageIceUpdateBuilder new];
[builder setId:self.callId];
[builder setSdp:self.sdp];
[builder setSdpMlineIndex:self.sdpMLineIndex];
[builder setSdpMid:self.sdpMid];
NSError *error;
SSKProtoCallMessageIceUpdate *_Nullable result = [builder buildAndReturnError:&error];
if (error || !result) {
OWSFail(@"%@ could not build protobuf: %@", self.logTag, error);
return nil;
}
return result;
}
@end

@ -8,8 +8,8 @@ NS_ASSUME_NONNULL_BEGIN
@class OWSCallBusyMessage;
@class OWSCallHangupMessage;
@class OWSCallIceUpdateMessage;
@class SSKProtoCallMessageAnswer;
@class SSKProtoCallMessageIceUpdate;
@class SSKProtoCallMessageOffer;
@class TSThread;
@ -31,15 +31,15 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithThread:(TSThread *)thread offerMessage:(SSKProtoCallMessageOffer *)offerMessage;
- (instancetype)initWithThread:(TSThread *)thread answerMessage:(SSKProtoCallMessageAnswer *)answerMessage;
- (instancetype)initWithThread:(TSThread *)thread iceUpdateMessage:(OWSCallIceUpdateMessage *)iceUpdateMessage;
- (instancetype)initWithThread:(TSThread *)thread iceUpdateMessage:(SSKProtoCallMessageIceUpdate *)iceUpdateMessage;
- (instancetype)initWithThread:(TSThread *)thread
iceUpdateMessages:(NSArray<OWSCallIceUpdateMessage *> *)iceUpdateMessage;
iceUpdateMessages:(NSArray<SSKProtoCallMessageIceUpdate *> *)iceUpdateMessage;
- (instancetype)initWithThread:(TSThread *)thread hangupMessage:(OWSCallHangupMessage *)hangupMessage;
- (instancetype)initWithThread:(TSThread *)thread busyMessage:(OWSCallBusyMessage *)busyMessage;
@property (nullable, nonatomic, readonly) SSKProtoCallMessageOffer *offerMessage;
@property (nullable, nonatomic, readonly) SSKProtoCallMessageAnswer *answerMessage;
@property (nullable, nonatomic, readonly) NSArray<OWSCallIceUpdateMessage *> *iceUpdateMessages;
@property (nullable, nonatomic, readonly) NSArray<SSKProtoCallMessageIceUpdate *> *iceUpdateMessages;
@property (nullable, nonatomic, readonly) OWSCallHangupMessage *hangupMessage;
@property (nullable, nonatomic, readonly) OWSCallBusyMessage *busyMessage;

@ -6,7 +6,6 @@
#import "NSDate+OWS.h"
#import "OWSCallBusyMessage.h"
#import "OWSCallHangupMessage.h"
#import "OWSCallIceUpdateMessage.h"
#import "ProtoUtils.h"
#import "SignalRecipient.h"
#import "TSContactThread.h"
@ -61,7 +60,7 @@ NS_ASSUME_NONNULL_BEGIN
return self;
}
- (instancetype)initWithThread:(TSThread *)thread iceUpdateMessage:(OWSCallIceUpdateMessage *)iceUpdateMessage
- (instancetype)initWithThread:(TSThread *)thread iceUpdateMessage:(SSKProtoCallMessageIceUpdate *)iceUpdateMessage
{
self = [self initWithThread:thread];
if (!self) {
@ -74,7 +73,7 @@ NS_ASSUME_NONNULL_BEGIN
}
- (instancetype)initWithThread:(TSThread *)thread
iceUpdateMessages:(NSArray<OWSCallIceUpdateMessage *> *)iceUpdateMessages
iceUpdateMessages:(NSArray<SSKProtoCallMessageIceUpdate *> *)iceUpdateMessages
{
self = [self initWithThread:thread];
if (!self) {
@ -152,14 +151,8 @@ NS_ASSUME_NONNULL_BEGIN
[builder setAnswer:self.answerMessage];
}
if (self.iceUpdateMessages) {
for (OWSCallIceUpdateMessage *iceUpdateMessage in self.iceUpdateMessages) {
SSKProtoCallMessageIceUpdate *_Nullable proto = [iceUpdateMessage asProtobuf];
if (!proto) {
return nil;
}
[builder addIceUpdate:proto];
}
if (self.iceUpdateMessages.count > 0) {
[builder setIceUpdate:self.iceUpdateMessages];
}
if (self.hangupMessage) {

Loading…
Cancel
Save