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

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: Fix a type conversion in RTCPeerConnection.mm 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]];
tkchin_webrtc 2016/05/16 20:48:58 dot syntax for properties. jsonCandidates.count
honghaiz3 2016/05/17 00:46:53 Done.
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];
tkchin_webrtc 2016/05/16 20:48:58 nit: Just move the entire thing to next line if it
honghaiz3 2016/05/17 00:46:53 It does not fit even if I move the entire thing to
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 {
tkchin_webrtc 2016/05/16 20:48:58 nit: indent 4 from leftmost margin (so remove two
honghaiz3 2016/05/17 00:46:53 Done.
106 if (self = [super initWithType:kARDSignalingMessageTypeCandidatesRemoval]) {
tkchin_webrtc 2016/05/16 20:48:58 May be worth tossing an assertion here. NSParamete
honghaiz3 2016/05/17 00:46:53 Done.
107 _candidates = candidates;
108 }
109 return self;
110 }
111
112 - (NSData *)JSONData {
113 NSMutableArray *jsonCandidates =
114 [NSMutableArray arrayWithCapacity:[_candidates count]];
tkchin_webrtc 2016/05/16 20:48:58 dot syntax for count
honghaiz3 2016/05/17 00:46:52 Done.
115 for (const RTCIceCandidate *candidate in _candidates) {
tkchin_webrtc 2016/05/16 20:48:58 const qualifier not necessary
honghaiz3 2016/05/17 00:46:52 Done.
116 NSDictionary *jsonCandidate = [candidate JSONDictionary];
117 [jsonCandidates addObject:jsonCandidate];
118 }
119 NSDictionary * json = @{
tkchin_webrtc 2016/05/16 20:48:58 *json
honghaiz3 2016/05/17 00:46:53 Done.
120 kARDSignalingMessageTypeKey : @"remove-candidates",
121 kARDSignalingMessageCandidatesKey : jsonCandidates
122 };
123 NSError *error = nil;
124 NSData *data =
125 [NSJSONSerialization dataWithJSONObject:json
126 options:NSJSONWritingPrettyPrinted
127 error:&error];
128 if (error) {
129 RTCLogError(@"Error serializing JSON: %@", error);
130 return nil;
131 }
132 return data;
133 }
134
135 @end
136
87 @implementation ARDSessionDescriptionMessage 137 @implementation ARDSessionDescriptionMessage
88 138
89 @synthesize sessionDescription = _sessionDescription; 139 @synthesize sessionDescription = _sessionDescription;
90 140
91 - (instancetype)initWithDescription:(RTCSessionDescription *)description { 141 - (instancetype)initWithDescription:(RTCSessionDescription *)description {
92 ARDSignalingMessageType messageType = kARDSignalingMessageTypeOffer; 142 ARDSignalingMessageType messageType = kARDSignalingMessageTypeOffer;
93 RTCSdpType sdpType = description.type; 143 RTCSdpType sdpType = description.type;
94 switch (sdpType) { 144 switch (sdpType) {
95 case RTCSdpTypeOffer: 145 case RTCSdpTypeOffer:
96 messageType = kARDSignalingMessageTypeOffer; 146 messageType = kARDSignalingMessageTypeOffer;
(...skipping 27 matching lines...) Expand all
124 - (NSData *)JSONData { 174 - (NSData *)JSONData {
125 NSDictionary *message = @{ 175 NSDictionary *message = @{
126 @"type": @"bye" 176 @"type": @"bye"
127 }; 177 };
128 return [NSJSONSerialization dataWithJSONObject:message 178 return [NSJSONSerialization dataWithJSONObject:message
129 options:NSJSONWritingPrettyPrinted 179 options:NSJSONWritingPrettyPrinted
130 error:NULL]; 180 error:NULL];
131 } 181 }
132 182
133 @end 183 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698