OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
11 * this list of conditions and the following disclaimer in the documentation | 11 * this list of conditions and the following disclaimer in the documentation |
12 * and/or other materials provided with the distribution. | 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 | 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. | 14 * derived from this software without specific prior written permission. |
15 * | 15 * |
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED | 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 | 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | 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, | 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | 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 | 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 */ | 26 */ |
27 | 27 |
28 #import "ARDSignalingMessage.h" | 28 #import "ARDSignalingMessage.h" |
29 | 29 |
| 30 #import "ARDLogging.h" |
30 #import "ARDUtilities.h" | 31 #import "ARDUtilities.h" |
31 #import "RTCICECandidate+JSON.h" | 32 #import "RTCICECandidate+JSON.h" |
32 #import "RTCSessionDescription+JSON.h" | 33 #import "RTCSessionDescription+JSON.h" |
33 | 34 |
34 static NSString const *kARDSignalingMessageTypeKey = @"type"; | 35 static NSString const *kARDSignalingMessageTypeKey = @"type"; |
35 | 36 |
36 @implementation ARDSignalingMessage | 37 @implementation ARDSignalingMessage |
37 | 38 |
38 @synthesize type = _type; | 39 @synthesize type = _type; |
39 | 40 |
40 - (instancetype)initWithType:(ARDSignalingMessageType)type { | 41 - (instancetype)initWithType:(ARDSignalingMessageType)type { |
41 if (self = [super init]) { | 42 if (self = [super init]) { |
42 _type = type; | 43 _type = type; |
43 } | 44 } |
44 return self; | 45 return self; |
45 } | 46 } |
46 | 47 |
47 - (NSString *)description { | 48 - (NSString *)description { |
48 return [[NSString alloc] initWithData:[self JSONData] | 49 return [[NSString alloc] initWithData:[self JSONData] |
49 encoding:NSUTF8StringEncoding]; | 50 encoding:NSUTF8StringEncoding]; |
50 } | 51 } |
51 | 52 |
52 + (ARDSignalingMessage *)messageFromJSONString:(NSString *)jsonString { | 53 + (ARDSignalingMessage *)messageFromJSONString:(NSString *)jsonString { |
53 NSDictionary *values = [NSDictionary dictionaryWithJSONString:jsonString]; | 54 NSDictionary *values = [NSDictionary dictionaryWithJSONString:jsonString]; |
54 if (!values) { | 55 if (!values) { |
55 NSLog(@"Error parsing signaling message JSON."); | 56 ARDLog(@"Error parsing signaling message JSON."); |
56 return nil; | 57 return nil; |
57 } | 58 } |
58 | 59 |
59 NSString *typeString = values[kARDSignalingMessageTypeKey]; | 60 NSString *typeString = values[kARDSignalingMessageTypeKey]; |
60 ARDSignalingMessage *message = nil; | 61 ARDSignalingMessage *message = nil; |
61 if ([typeString isEqualToString:@"candidate"]) { | 62 if ([typeString isEqualToString:@"candidate"]) { |
62 RTCICECandidate *candidate = | 63 RTCICECandidate *candidate = |
63 [RTCICECandidate candidateFromJSONDictionary:values]; | 64 [RTCICECandidate candidateFromJSONDictionary:values]; |
64 message = [[ARDICECandidateMessage alloc] initWithCandidate:candidate]; | 65 message = [[ARDICECandidateMessage alloc] initWithCandidate:candidate]; |
65 } else if ([typeString isEqualToString:@"offer"] || | 66 } else if ([typeString isEqualToString:@"offer"] || |
66 [typeString isEqualToString:@"answer"]) { | 67 [typeString isEqualToString:@"answer"]) { |
67 RTCSessionDescription *description = | 68 RTCSessionDescription *description = |
68 [RTCSessionDescription descriptionFromJSONDictionary:values]; | 69 [RTCSessionDescription descriptionFromJSONDictionary:values]; |
69 message = | 70 message = |
70 [[ARDSessionDescriptionMessage alloc] initWithDescription:description]; | 71 [[ARDSessionDescriptionMessage alloc] initWithDescription:description]; |
71 } else if ([typeString isEqualToString:@"bye"]) { | 72 } else if ([typeString isEqualToString:@"bye"]) { |
72 message = [[ARDByeMessage alloc] init]; | 73 message = [[ARDByeMessage alloc] init]; |
73 } else { | 74 } else { |
74 NSLog(@"Unexpected type: %@", typeString); | 75 ARDLog(@"Unexpected type: %@", typeString); |
75 } | 76 } |
76 return message; | 77 return message; |
77 } | 78 } |
78 | 79 |
79 - (NSData *)JSONData { | 80 - (NSData *)JSONData { |
80 return nil; | 81 return nil; |
81 } | 82 } |
82 | 83 |
83 @end | 84 @end |
84 | 85 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 - (NSData *)JSONData { | 135 - (NSData *)JSONData { |
135 NSDictionary *message = @{ | 136 NSDictionary *message = @{ |
136 @"type": @"bye" | 137 @"type": @"bye" |
137 }; | 138 }; |
138 return [NSJSONSerialization dataWithJSONObject:message | 139 return [NSJSONSerialization dataWithJSONObject:message |
139 options:NSJSONWritingPrettyPrinted | 140 options:NSJSONWritingPrettyPrinted |
140 error:NULL]; | 141 error:NULL]; |
141 } | 142 } |
142 | 143 |
143 @end | 144 @end |
OLD | NEW |