WFCCCallStartMessageContent.m 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //
  2. // WFCCTextMessageContent.m
  3. // WFChatClient
  4. //
  5. // Created by heavyrain on 2017/8/16.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCCCallStartMessageContent.h"
  9. #import "WFCCIMService.h"
  10. #import "Common.h"
  11. @implementation WFCCCallStartMessageContent
  12. - (WFCCMessagePayload *)encode {
  13. WFCCMessagePayload *payload = [[WFCCMessagePayload alloc] init];
  14. payload.contentType = [self.class getContentType];
  15. payload.content = self.callId;
  16. NSMutableDictionary *dataDict = [NSMutableDictionary dictionary];
  17. if (self.connectTime) {
  18. [dataDict setObject:@(self.connectTime) forKey:@"c"];
  19. }
  20. if (self.endTime) {
  21. [dataDict setObject:@(self.endTime) forKey:@"e"];
  22. }
  23. if (self.status) {
  24. [dataDict setObject:@(self.status) forKey:@"s"];
  25. }
  26. [dataDict setObject:self.targetId forKey:@"t"];
  27. [dataDict setValue:@(self.audioOnly?1:0) forKey:@"a"];
  28. payload.binaryContent = [NSJSONSerialization dataWithJSONObject:dataDict
  29. options:kNilOptions
  30. error:nil];
  31. return payload;
  32. }
  33. - (void)decode:(WFCCMessagePayload *)payload {
  34. self.callId = payload.content;
  35. NSError *__error = nil;
  36. NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:payload.binaryContent
  37. options:kNilOptions
  38. error:&__error];
  39. if (!__error) {
  40. self.connectTime = dictionary[@"c"] ? [dictionary[@"c"] longLongValue] : 0;
  41. self.endTime = dictionary[@"e"] ? [dictionary[@"e"] longLongValue] : 0;
  42. self.status = dictionary[@"s"] ? [dictionary[@"s"] intValue] : 0;
  43. self.audioOnly = [dictionary[@"a"] intValue] ? YES : NO;
  44. self.targetId = dictionary[@"t"];
  45. }
  46. }
  47. + (int)getContentType {
  48. return VOIP_CONTENT_TYPE_START;
  49. }
  50. + (int)getContentFlags {
  51. return WFCCPersistFlag_PERSIST;
  52. }
  53. + (void)load {
  54. [[WFCCIMService sharedWFCIMService] registerMessageContent:self];
  55. }
  56. - (NSString *)digest {
  57. if (_audioOnly) {
  58. return @"[语音通话]";
  59. } else {
  60. return @"[视频通话]";
  61. }
  62. }
  63. @end