RTCSessionDescription+JSON.m 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  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 "RTCSessionDescription+JSON.h"
  11. static NSString const *kRTCSessionDescriptionTypeKey = @"type";
  12. static NSString const *kRTCSessionDescriptionSdpKey = @"sdp";
  13. @implementation RTCSessionDescription (JSON)
  14. + (RTCSessionDescription *)descriptionFromJSONDictionary:
  15. (NSDictionary *)dictionary {
  16. NSString *typeString = dictionary[kRTCSessionDescriptionTypeKey];
  17. RTCSdpType type = [[self class] typeForString:typeString];
  18. NSString *sdp = dictionary[kRTCSessionDescriptionSdpKey];
  19. return [[RTCSessionDescription alloc] initWithType:type sdp:sdp];
  20. }
  21. - (NSData *)JSONData {
  22. NSString *type = [[self class] stringForType:self.type];
  23. NSDictionary *json = @{
  24. kRTCSessionDescriptionTypeKey : type,
  25. kRTCSessionDescriptionSdpKey : self.sdp
  26. };
  27. return [NSJSONSerialization dataWithJSONObject:json options:0 error:nil];
  28. }
  29. @end