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

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

Issue 1235563006: Move talk/examples/* to webrtc/examples. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: 201508051337 Created 5 years, 4 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
(Empty)
1 /*
2 * libjingle
3 * Copyright 2014 Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #import "ARDSignalingMessage.h"
29
30 #import "RTCLogging.h"
31
32 #import "ARDUtilities.h"
33 #import "RTCICECandidate+JSON.h"
34 #import "RTCSessionDescription+JSON.h"
35
36 static NSString const *kARDSignalingMessageTypeKey = @"type";
37
38 @implementation ARDSignalingMessage
39
40 @synthesize type = _type;
41
42 - (instancetype)initWithType:(ARDSignalingMessageType)type {
43 if (self = [super init]) {
44 _type = type;
45 }
46 return self;
47 }
48
49 - (NSString *)description {
50 return [[NSString alloc] initWithData:[self JSONData]
51 encoding:NSUTF8StringEncoding];
52 }
53
54 + (ARDSignalingMessage *)messageFromJSONString:(NSString *)jsonString {
55 NSDictionary *values = [NSDictionary dictionaryWithJSONString:jsonString];
56 if (!values) {
57 RTCLogError(@"Error parsing signaling message JSON.");
58 return nil;
59 }
60
61 NSString *typeString = values[kARDSignalingMessageTypeKey];
62 ARDSignalingMessage *message = nil;
63 if ([typeString isEqualToString:@"candidate"]) {
64 RTCICECandidate *candidate =
65 [RTCICECandidate candidateFromJSONDictionary:values];
66 message = [[ARDICECandidateMessage alloc] initWithCandidate:candidate];
67 } else if ([typeString isEqualToString:@"offer"] ||
68 [typeString isEqualToString:@"answer"]) {
69 RTCSessionDescription *description =
70 [RTCSessionDescription descriptionFromJSONDictionary:values];
71 message =
72 [[ARDSessionDescriptionMessage alloc] initWithDescription:description];
73 } else if ([typeString isEqualToString:@"bye"]) {
74 message = [[ARDByeMessage alloc] init];
75 } else {
76 RTCLogError(@"Unexpected type: %@", typeString);
77 }
78 return message;
79 }
80
81 - (NSData *)JSONData {
82 return nil;
83 }
84
85 @end
86
87 @implementation ARDICECandidateMessage
88
89 @synthesize candidate = _candidate;
90
91 - (instancetype)initWithCandidate:(RTCICECandidate *)candidate {
92 if (self = [super initWithType:kARDSignalingMessageTypeCandidate]) {
93 _candidate = candidate;
94 }
95 return self;
96 }
97
98 - (NSData *)JSONData {
99 return [_candidate JSONData];
100 }
101
102 @end
103
104 @implementation ARDSessionDescriptionMessage
105
106 @synthesize sessionDescription = _sessionDescription;
107
108 - (instancetype)initWithDescription:(RTCSessionDescription *)description {
109 ARDSignalingMessageType type = kARDSignalingMessageTypeOffer;
110 NSString *typeString = description.type;
111 if ([typeString isEqualToString:@"offer"]) {
112 type = kARDSignalingMessageTypeOffer;
113 } else if ([typeString isEqualToString:@"answer"]) {
114 type = kARDSignalingMessageTypeAnswer;
115 } else {
116 NSAssert(NO, @"Unexpected type: %@", typeString);
117 }
118 if (self = [super initWithType:type]) {
119 _sessionDescription = description;
120 }
121 return self;
122 }
123
124 - (NSData *)JSONData {
125 return [_sessionDescription JSONData];
126 }
127
128 @end
129
130 @implementation ARDByeMessage
131
132 - (instancetype)init {
133 return [super initWithType:kARDSignalingMessageTypeBye];
134 }
135
136 - (NSData *)JSONData {
137 NSDictionary *message = @{
138 @"type": @"bye"
139 };
140 return [NSJSONSerialization dataWithJSONObject:message
141 options:NSJSONWritingPrettyPrinted
142 error:NULL];
143 }
144
145 @end
OLDNEW
« no previous file with comments | « talk/examples/objc/AppRTCDemo/ARDSignalingMessage.h ('k') | talk/examples/objc/AppRTCDemo/ARDTURNClient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698