You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.9 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. #import "ARDJoinResponse+Internal.h"
  11. #import "ARDSignalingMessage.h"
  12. #import "ARDUtilities.h"
  13. #import "RTCIceServer+JSON.h"
  14. static NSString const *kARDJoinResultKey = @"result";
  15. static NSString const *kARDJoinResultParamsKey = @"params";
  16. static NSString const *kARDJoinInitiatorKey = @"is_initiator";
  17. static NSString const *kARDJoinRoomIdKey = @"room_id";
  18. static NSString const *kARDJoinClientIdKey = @"client_id";
  19. static NSString const *kARDJoinMessagesKey = @"messages";
  20. static NSString const *kARDJoinWebSocketURLKey = @"wss_url";
  21. static NSString const *kARDJoinWebSocketRestURLKey = @"wss_post_url";
  22. @implementation ARDJoinResponse
  23. @synthesize result = _result;
  24. @synthesize isInitiator = _isInitiator;
  25. @synthesize roomId = _roomId;
  26. @synthesize clientId = _clientId;
  27. @synthesize messages = _messages;
  28. @synthesize webSocketURL = _webSocketURL;
  29. @synthesize webSocketRestURL = _webSocketRestURL;
  30. + (ARDJoinResponse *)responseFromJSONData:(NSData *)data {
  31. NSDictionary *responseJSON = [NSDictionary dictionaryWithJSONData:data];
  32. if (!responseJSON) {
  33. return nil;
  34. }
  35. ARDJoinResponse *response = [[ARDJoinResponse alloc] init];
  36. NSString *resultString = responseJSON[kARDJoinResultKey];
  37. response.result = [[self class] resultTypeFromString:resultString];
  38. NSDictionary *params = responseJSON[kARDJoinResultParamsKey];
  39. response.isInitiator = [params[kARDJoinInitiatorKey] boolValue];
  40. response.roomId = params[kARDJoinRoomIdKey];
  41. response.clientId = params[kARDJoinClientIdKey];
  42. // Parse messages.
  43. NSArray *messages = params[kARDJoinMessagesKey];
  44. NSMutableArray *signalingMessages =
  45. [NSMutableArray arrayWithCapacity:messages.count];
  46. for (NSString *message in messages) {
  47. ARDSignalingMessage *signalingMessage =
  48. [ARDSignalingMessage messageFromJSONString:message];
  49. [signalingMessages addObject:signalingMessage];
  50. }
  51. response.messages = signalingMessages;
  52. // Parse websocket urls.
  53. NSString *webSocketURLString = params[kARDJoinWebSocketURLKey];
  54. response.webSocketURL = [NSURL URLWithString:webSocketURLString];
  55. NSString *webSocketRestURLString = params[kARDJoinWebSocketRestURLKey];
  56. response.webSocketRestURL = [NSURL URLWithString:webSocketRestURLString];
  57. return response;
  58. }
  59. #pragma mark - Private
  60. + (ARDJoinResultType)resultTypeFromString:(NSString *)resultString {
  61. ARDJoinResultType result = kARDJoinResultTypeUnknown;
  62. if ([resultString isEqualToString:@"SUCCESS"]) {
  63. result = kARDJoinResultTypeSuccess;
  64. } else if ([resultString isEqualToString:@"FULL"]) {
  65. result = kARDJoinResultTypeFull;
  66. }
  67. return result;
  68. }
  69. @end