Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Side by Side Diff: webrtc/examples/objc/AppRTCDemo/ARDSignalingMessage.m

Issue 1972483002: Pass around the candidate removals events in IOS clients Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2014 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2014 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #import "ARDSignalingMessage.h" 11 #import "ARDSignalingMessage.h"
12 12
13 #import "WebRTC/RTCLogging.h" 13 #import "WebRTC/RTCLogging.h"
14 14
15 #import "ARDUtilities.h" 15 #import "ARDUtilities.h"
16 #import "RTCIceCandidate+JSON.h" 16 #import "RTCIceCandidate+JSON.h"
17 #import "RTCSessionDescription+JSON.h" 17 #import "RTCSessionDescription+JSON.h"
18 18
19 static NSString const *kARDSignalingMessageTypeKey = @"type"; 19 static NSString const *kARDSignalingMessageTypeKey = @"type";
20 static NSString const *kARDSignalingMessageCandidatesKey = @"candidates";
20 21
21 @implementation ARDSignalingMessage 22 @implementation ARDSignalingMessage
22 23
23 @synthesize type = _type; 24 @synthesize type = _type;
24 25
25 - (instancetype)initWithType:(ARDSignalingMessageType)type { 26 - (instancetype)initWithType:(ARDSignalingMessageType)type {
26 if (self = [super init]) { 27 if (self = [super init]) {
27 _type = type; 28 _type = type;
28 } 29 }
29 return self; 30 return self;
(...skipping 10 matching lines...) Expand all
40 RTCLogError(@"Error parsing signaling message JSON."); 41 RTCLogError(@"Error parsing signaling message JSON.");
41 return nil; 42 return nil;
42 } 43 }
43 44
44 NSString *typeString = values[kARDSignalingMessageTypeKey]; 45 NSString *typeString = values[kARDSignalingMessageTypeKey];
45 ARDSignalingMessage *message = nil; 46 ARDSignalingMessage *message = nil;
46 if ([typeString isEqualToString:@"candidate"]) { 47 if ([typeString isEqualToString:@"candidate"]) {
47 RTCIceCandidate *candidate = 48 RTCIceCandidate *candidate =
48 [RTCIceCandidate candidateFromJSONDictionary:values]; 49 [RTCIceCandidate candidateFromJSONDictionary:values];
49 message = [[ARDICECandidateMessage alloc] initWithCandidate:candidate]; 50 message = [[ARDICECandidateMessage alloc] initWithCandidate:candidate];
51 } else if ([typeString isEqualToString:@"remove-candidates"]) {
52 RTCLogInfo(@"Received remove-candidates message");
53 NSArray *jsonCandidates = values[kARDSignalingMessageCandidatesKey];
54 NSMutableArray<RTCIceCandidate *> *candidates =
55 [NSMutableArray arrayWithCapacity:jsonCandidates.count];
56 for (NSDictionary *jsonCandidate in jsonCandidates) {
57 RTCIceCandidate *candidate =
58 [RTCIceCandidate candidateFromJSONDictionary:jsonCandidate];
59 [candidates addObject:candidate];
60 }
61 message = [[ARDICECandidatesRemovalMessage alloc]
62 initWithRemovedCandidates:candidates];
50 } else if ([typeString isEqualToString:@"offer"] || 63 } else if ([typeString isEqualToString:@"offer"] ||
51 [typeString isEqualToString:@"answer"]) { 64 [typeString isEqualToString:@"answer"]) {
52 RTCSessionDescription *description = 65 RTCSessionDescription *description =
53 [RTCSessionDescription descriptionFromJSONDictionary:values]; 66 [RTCSessionDescription descriptionFromJSONDictionary:values];
54 message = 67 message =
55 [[ARDSessionDescriptionMessage alloc] initWithDescription:description]; 68 [[ARDSessionDescriptionMessage alloc] initWithDescription:description];
56 } else if ([typeString isEqualToString:@"bye"]) { 69 } else if ([typeString isEqualToString:@"bye"]) {
57 message = [[ARDByeMessage alloc] init]; 70 message = [[ARDByeMessage alloc] init];
58 } else { 71 } else {
59 RTCLogError(@"Unexpected type: %@", typeString); 72 RTCLogError(@"Unexpected type: %@", typeString);
(...skipping 17 matching lines...) Expand all
77 } 90 }
78 return self; 91 return self;
79 } 92 }
80 93
81 - (NSData *)JSONData { 94 - (NSData *)JSONData {
82 return [_candidate JSONData]; 95 return [_candidate JSONData];
83 } 96 }
84 97
85 @end 98 @end
86 99
100 @implementation ARDICECandidatesRemovalMessage
101
102 @synthesize candidates = _candidates;
103
104 - (instancetype)initWithRemovedCandidates:(
105 NSArray<RTCIceCandidate *> *)candidates {
106 NSParameterAssert(candidates.count);
107 if (self = [super initWithType:kARDSignalingMessageTypeCandidatesRemoval]) {
108 _candidates = candidates;
109 }
110 return self;
111 }
112
113 - (NSData *)JSONData {
114 NSMutableArray *jsonCandidates =
115 [NSMutableArray arrayWithCapacity:_candidates.count];
116 for (RTCIceCandidate *candidate in _candidates) {
117 NSDictionary *jsonCandidate = [candidate JSONDictionary];
118 [jsonCandidates addObject:jsonCandidate];
119 }
120 NSDictionary *json = @{
121 kARDSignalingMessageTypeKey : @"remove-candidates",
122 kARDSignalingMessageCandidatesKey : jsonCandidates
123 };
124 NSError *error = nil;
125 NSData *data =
126 [NSJSONSerialization dataWithJSONObject:json
127 options:NSJSONWritingPrettyPrinted
128 error:&error];
129 if (error) {
130 RTCLogError(@"Error serializing JSON: %@", error);
131 return nil;
132 }
133 return data;
134 }
135
136 @end
137
87 @implementation ARDSessionDescriptionMessage 138 @implementation ARDSessionDescriptionMessage
88 139
89 @synthesize sessionDescription = _sessionDescription; 140 @synthesize sessionDescription = _sessionDescription;
90 141
91 - (instancetype)initWithDescription:(RTCSessionDescription *)description { 142 - (instancetype)initWithDescription:(RTCSessionDescription *)description {
92 ARDSignalingMessageType messageType = kARDSignalingMessageTypeOffer; 143 ARDSignalingMessageType messageType = kARDSignalingMessageTypeOffer;
93 RTCSdpType sdpType = description.type; 144 RTCSdpType sdpType = description.type;
94 switch (sdpType) { 145 switch (sdpType) {
95 case RTCSdpTypeOffer: 146 case RTCSdpTypeOffer:
96 messageType = kARDSignalingMessageTypeOffer; 147 messageType = kARDSignalingMessageTypeOffer;
(...skipping 27 matching lines...) Expand all
124 - (NSData *)JSONData { 175 - (NSData *)JSONData {
125 NSDictionary *message = @{ 176 NSDictionary *message = @{
126 @"type": @"bye" 177 @"type": @"bye"
127 }; 178 };
128 return [NSJSONSerialization dataWithJSONObject:message 179 return [NSJSONSerialization dataWithJSONObject:message
129 options:NSJSONWritingPrettyPrinted 180 options:NSJSONWritingPrettyPrinted
130 error:NULL]; 181 error:NULL];
131 } 182 }
132 183
133 @end 184 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698