Donald E Curtis | a873644 | 2015-08-05 15:48:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
hjon | 79858f8 | 2016-03-13 22:08:26 -0700 | [diff] [blame] | 11 | #import "RTCIceServer+JSON.h" |
Donald E Curtis | a873644 | 2015-08-05 15:48:13 -0700 | [diff] [blame] | 12 | |
| 13 | static NSString const *kRTCICEServerUsernameKey = @"username"; |
| 14 | static NSString const *kRTCICEServerPasswordKey = @"password"; |
| 15 | static NSString const *kRTCICEServerUrisKey = @"uris"; |
| 16 | static NSString const *kRTCICEServerUrlKey = @"urls"; |
| 17 | static NSString const *kRTCICEServerCredentialKey = @"credential"; |
| 18 | |
hjon | 79858f8 | 2016-03-13 22:08:26 -0700 | [diff] [blame] | 19 | @implementation RTCIceServer (JSON) |
Donald E Curtis | a873644 | 2015-08-05 15:48:13 -0700 | [diff] [blame] | 20 | |
hjon | 79858f8 | 2016-03-13 22:08:26 -0700 | [diff] [blame] | 21 | + (RTCIceServer *)serverFromJSONDictionary:(NSDictionary *)dictionary { |
Donald E Curtis | a873644 | 2015-08-05 15:48:13 -0700 | [diff] [blame] | 22 | NSString *url = dictionary[kRTCICEServerUrlKey]; |
| 23 | NSString *username = dictionary[kRTCICEServerUsernameKey]; |
| 24 | NSString *credential = dictionary[kRTCICEServerCredentialKey]; |
| 25 | username = username ? username : @""; |
| 26 | credential = credential ? credential : @""; |
hjon | 79858f8 | 2016-03-13 22:08:26 -0700 | [diff] [blame] | 27 | return [[RTCIceServer alloc] initWithURLStrings:@[url] |
| 28 | username:username |
| 29 | credential:credential]; |
Donald E Curtis | a873644 | 2015-08-05 15:48:13 -0700 | [diff] [blame] | 30 | } |
| 31 | |
hjon | 79858f8 | 2016-03-13 22:08:26 -0700 | [diff] [blame] | 32 | + (RTCIceServer *)serverFromCEODJSONDictionary:(NSDictionary *)dictionary { |
Donald E Curtis | a873644 | 2015-08-05 15:48:13 -0700 | [diff] [blame] | 33 | NSString *username = dictionary[kRTCICEServerUsernameKey]; |
| 34 | NSString *password = dictionary[kRTCICEServerPasswordKey]; |
| 35 | NSArray *uris = dictionary[kRTCICEServerUrisKey]; |
hjon | 79858f8 | 2016-03-13 22:08:26 -0700 | [diff] [blame] | 36 | RTCIceServer *server = |
| 37 | [[RTCIceServer alloc] initWithURLStrings:uris |
| 38 | username:username |
| 39 | credential:password]; |
| 40 | return server; |
Donald E Curtis | a873644 | 2015-08-05 15:48:13 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | @end |