-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathStringeeManager.m
More file actions
82 lines (65 loc) · 2.23 KB
/
StringeeManager.m
File metadata and controls
82 lines (65 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//
// StringeeManager.m
// stringee_flutter_plugin
//
// Created by HoangDuoc on 1/8/21.
//
#import "StringeeManager.h"
@implementation StringeeManager
static StringeeManager *stringeeManager = nil;
+ (StringeeManager *)instance {
@synchronized(self) {
if (stringeeManager == nil) {
stringeeManager = [[self alloc] init];
}
}
return stringeeManager;
}
- (id)init {
self = [super init];
if (self) {
self.calls = [[NSMutableDictionary alloc] init];
self.call2s = [[NSMutableDictionary alloc] init];
self.call2VideoTracks = [[NSMutableDictionary alloc] init];
}
return self;
}
- (void)addTrackForCall2:(StringeeVideoTrack *)track callId:(NSString *)callId {
NSMutableDictionary *nestedDic = [self.call2VideoTracks objectForKey:callId];
if (nestedDic == nil) {
nestedDic = [[NSMutableDictionary alloc] init];
[self.call2VideoTracks setObject:nestedDic forKey:callId];
}
NSString *trackId = track.isLocal ? track.localId : track.serverId;
[nestedDic setObject:track forKey:trackId];
}
- (void)removeTrackForCall2:(NSString *)callId {
[self.call2VideoTracks removeObjectForKey:callId];
}
- (void)removeTrackForCall2:(NSString *)callId trackId:(NSString *)trackId {
NSMutableDictionary *nestedDic = [self.call2VideoTracks objectForKey:callId];
if (nestedDic != nil) {
[nestedDic removeObjectForKey:trackId];
}
}
- (StringeeVideoTrack *)getVideoTrackForCall2:(NSString *)callId trackId:(NSString*)trackId {
NSMutableDictionary *nestedDic = [self.call2VideoTracks objectForKey:callId];
if (nestedDic == nil) {
return nil;
}
if ((trackId == nil || trackId.length == 0) && nestedDic.allValues.count > 0) {
return nestedDic.allValues.lastObject;
}
return [nestedDic objectForKey:trackId];
}
- (StringeeVideoTrack *)getVideoTrackForCall2ByTracKId:(NSString*)trackId {
for (NSDictionary *tracks in self.call2VideoTracks.allValues) {
for (StringeeVideoTrack *track in tracks.allValues) {
if ([track.localId isEqualToString:trackId] || [track.serverId isEqualToString:trackId]) {
return track;
}
}
}
return nil;
}
@end