WFCCCallStartMessageContent.m 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 = [super encode];
  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.targetIds forKey:@"ts"];
  27. //多人音视频与单人音视频兼容
  28. [dataDict setObject:self.targetIds[0] forKey:@"t"];
  29. [dataDict setValue:@(self.audioOnly?1:0) forKey:@"a"];
  30. payload.binaryContent = [NSJSONSerialization dataWithJSONObject:dataDict
  31. options:kNilOptions
  32. error:nil];
  33. return payload;
  34. }
  35. - (void)decode:(WFCCMessagePayload *)payload {
  36. [super decode:payload];
  37. self.callId = payload.content;
  38. NSError *__error = nil;
  39. NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:payload.binaryContent
  40. options:kNilOptions
  41. error:&__error];
  42. if (!__error) {
  43. self.connectTime = dictionary[@"c"] ? [dictionary[@"c"] longLongValue] : 0;
  44. self.endTime = dictionary[@"e"] ? [dictionary[@"e"] longLongValue] : 0;
  45. self.status = dictionary[@"s"] ? [dictionary[@"s"] intValue] : 0;
  46. self.audioOnly = [dictionary[@"a"] intValue] ? YES : NO;
  47. self.targetIds = dictionary[@"ts"];
  48. if (self.targetIds.count == 0) {
  49. NSString *target = dictionary[@"t"];
  50. NSMutableArray *arr = [[NSMutableArray alloc] init];
  51. [arr addObject:target];
  52. self.targetIds = arr;
  53. }
  54. }
  55. }
  56. + (int)getContentType {
  57. return VOIP_CONTENT_TYPE_START;
  58. }
  59. + (int)getContentFlags {
  60. return WFCCPersistFlag_PERSIST;
  61. }
  62. + (void)load {
  63. [[WFCCIMService sharedWFCIMService] registerMessageContent:self];
  64. }
  65. - (NSString *)digest:(WFCCMessage *)message {
  66. if (_audioOnly) {
  67. return @"[语音通话]";
  68. } else {
  69. return @"[视频通话]";
  70. }
  71. }
  72. @end