iOS的licode_APP简单分析

iOS的licode分析
viewDidLoad
	//创建本地视频流
	initLocalStream
		initWithLocalStreamWithMediaConstraints:nil
			_peerFactory = [[RTCPeerConnectionFactory alloc] init];
			_mediaConstraints = mediaConstraints; //这里是nil
			createLocalStream
				_mediaStream = [_peerFactory mediaStreamWithLabel:@"LCMS"];
				//将视频和音频添加到流轨迹中
				generateVideoTracks
					[_mediaStream removeVideoTrack:localVideoTrack];
					RTCVideoTrack *localVideoTrack = [self createLocalVideoTrack];
					[_mediaStream addVideoTrack:localVideoTrack];
				[_mediaStream addAudioTrack:[_peerFactory audioTrackWithID:@"LCMSa0"]];
	//添加渲染
	RTCVideoTrack *videoTrack = [localStream.mediaStream.videoTracks objectAtIndex:0];
    [videoTrack addRenderer:_localView];

	remoteRoom = [[ECRoom alloc] initWithDelegate:self andPeerFactory:localStream.peerFactory];

//connect按钮
obtainMultiVideoConferenceToken
	[self buildRequest:kLicodeServerURLString method:@"POST" postData:postData];
	[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
	[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue]
	—>completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) 
		token = [self parseResponse:data];
		completion(TRUE, token);

obtainMultiVideoConferenceToken
—>completion:^(BOOL result, NSString *token) 
	[remoteRoom createSignalingChannelWithEncodedToken:token];
		signalingChannel = [[ECSignalingChannel alloc] initWithEncodedToken:encodedToken roomDelegate:self];
    	[signalingChannel connect];
			socketIO = [[SocketIO alloc] initWithDelegate:self];
			socketIO.useSecure = [decodedToken objectForKey:@"secure"]==@"1"?YES:NO;
			socketIO.returnAllDataFromAck = TRUE;
			NSString *hostURLString = decodedToken[@"host"];
			hostURLString = [NSString stringWithFormat:@"http://%@", hostURLString];  
			NSURL *url = [NSURL URLWithString:hostURLString];
			[socketIO connectToHost:[url host] onPort:[[url port] intValue]];

socketIODidConnect
	[socketIO sendEvent:@"token" withData:decodedToken
         andAcknowledge:[self onSendTokenCallback]];

onSendTokenCallback
	if ([status isEqualToString:@"success"]) 
		[_roomDelegate signalingChannel:self didConnectToRoom:roomMetadata];
			[_delegate room:self didConnect:roomMeta];
				[remoteRoom publish:localStream withOptions:…];
					NSMutableDictionary *opts = [options mutableCopy];
					opts[@"video"] = videoCount > 0 ? @"true" : @"false";
					opts[@"audio"] = audioCount > 0 ? @"true" : @"false”;
					if (!opts[@"data"]) {
						opts[@"data"] = @{};
					}
					if (!opts[@"attributes"]) {
						opts[@"attributes"] = @"false";
					}
					[signalingChannel publish:opts signalingChannelDelegate:publishClient];
						attributes[@"state"] = @"erizo";
						[socketIO sendEvent:@"publish" withData:dataToSend
												andAcknowledge:[self onPublishCallback:delegate]];
			[_delegate room:self didReceiveStreamsList:streamIds];
				for (id item in list) {
					[remoteRoom subscribe:[item valueForKey:@"id"]];
						[signalingChannel subscribe:streamId signalingChannelDelegate:subscribeClient];
							streamId = [NSString stringWithFormat:@"%@", streamId];
							NSDictionary *attributes = @{
                                 @"streamId": streamId,
                             };
							NSArray *dataToSend = [[NSArray alloc] initWithObjects: attributes, @"null", nil];
							[socketIO sendEvent:@"subscribe" withData:dataToSend
										andAcknowledge:[self onSubscribeCallback:streamId signalingChannelDelegate:delegate]];
				}

onPublishCallback:delegate
	NSString *streamId = [(NSNumber*)[argsData objectAtIndex:0] stringValue];
	[self setSignalingDelegateForStreamId:signalingDelegate streamId:streamId];
    [signalingDelegate signalingChannelDidOpenChannel:self];
    [signalingDelegate signalingChannel:self didReceiveServerConfiguration:roomMetadata];
		for (NSDictionary *dict in [_serverConfiguration objectForKey:@"iceServers"]) {
        NSString *username = [dict objectForKey:@"username"] ? [dict objectForKey:@"username"] : @"";
        NSString *password = [dict objectForKey:@"credential"] ? [dict objectForKey:@"credential"] : @"";
        RTCICEServer *iceServer = [[RTCICEServer alloc]
                                    initWithURI:[NSURL URLWithString:[dict objectForKey:@"url"]]
                                    username:username
                                    password:password];
        [_iceServers addObject:iceServer];
    }
    [signalingDelegate signalingChannel:self readyToPublishStreamId:streamId];
		[self startPublishSignaling];
			RTCMediaConstraints *constraints = [self defaultPeerConnectionConstraints];
    			RTCConfiguration *config = [[RTCConfiguration alloc] init];
    			config.iceServers = _iceServers;
    			_peerConnection = [_factory peerConnectionWithConfiguration:config
                                                    constraints:constraints
                                                       delegate:self];
    			_localStream = [self.delegate streamToPublishByAppClient:self];
    			[_peerConnection addStream:_localStream];
    			[_peerConnection createOfferWithDelegate:self
                             constraints:[self defaultOfferConstraints]];	
    [_roomDelegate signalingChannel:self didReceiveStreamIdReadyToPublish:streamId];

(void)socketIO:(SocketIO *)socket didReceiveEvent:(SocketIOPacket *)packet 
	if ([packet.name isEqualToString:kEventOnAddStream]) 
		
	if ([packet.name isEqualToString:kEventOnRemoveStream])
	if ([packet.name isEqualToString:kEventSignalingMessage]) 
	if ([packet.name isEqualToString:kEventPublishMe])
	if ([packet.name isEqualToString:kEventSignalingMsgPeer])

didCreateSessionDescription
	[_peerConnection setLocalDescriptionWithDelegate:self
                                      sessionDescription:newSDP];
	[_signalingChannel sendSignalingMessage:message];

gotICECandidate
	ECICECandidateMessage *message =
        [[ECICECandidateMessage alloc] initWithCandidate:candidate andStreamId:currentStreamId];
    [_signalingChannel enqueueSignalingMessage:message];
		if (message.type == kECSignalingMessageTypeAnswer ||
        		message.type == kECSignalingMessageTypeOffer) {
        		[[outMessagesQueues objectForKey:message.streamId] insertObject:message atIndex:0];
    		} else {
        		[[outMessagesQueues objectForKey:message.streamId] addObject:message];
    		}

iceGatheringChanged
	if (newState == RTCICEGatheringComplete) {
        [_signalingChannel drainMessageQueueForStreamId:currentStreamId];
			for (ECSignalingMessage *message in [outMessagesQueues objectForKey:streamId]) {
        			[self sendSignalingMessage:message];
    			}
    			[[outMessagesQueues objectForKey:streamId] removeAllObjects];
    }
	
peerConnection:(RTCPeerConnection *)peerConnection addedStream:(RTCMediaStream *)stream 
	[self.delegate appClient:self didReceiveRemoteStream:stream withStreamId:currentStreamId];
		ECStream *erizoStream =  [[ECStream alloc] initWithRTCMediaStream:stream
                                                             withStreamId:streamId];
        [_delegate room:self didSubscribeStream:erizoStream];
			[self showCallConnectViews:NO updateStatusMessage:[NSString stringWithFormat:@"Subscribed: %@", stream.streamId]];
			[self watchStream:stream];
				CGRect frame = CGRectMake(0, 0, vWidth, vHeight);
    				ECPlayerView *playerView = [[ECPlayerView alloc] initWithLiveStream:stream frame:frame];
    				[playerViews addObject:playerView];
    				[self.view addSubview:playerView];

================================================================================
================================================================================
================================================================================
@protocol ECClientDelegate <NSObject>  //ECRoom 
…
@end

@interface ECClient : NSObject
@property (strong, nonatomic) id<ECClientDelegate> delegate;//ECClient -> ECRoom 
…
@end

@interface ECClient () <ECSignalingChannelDelegate, RTCPeerConnectionDelegate, RTCSessionDescriptionDelegate>
//RTCPeerConnectionDelegate and RTCSessionDescriptionDelegate => webrtc interface
…
@end

---------------------------------------------------
@protocol ECSignalingChannelDelegate //ECClient    
…
@end
++++++++++++++++++++++++++++++++++++++++++++++++
//ECClient
- (instancetype)initWithDelegate:(id<ECClientDelegate>)delegate
                  andPeerFactory:(RTCPeerConnectionFactory *)peerFactory {
    if (self = [self init]) {
        _delegate = delegate;
        _factory =  peerFactory;
    }
    return  self;
}
//ECRoom
ECClient *publishClient = [[ECClient alloc] initWithDelegate:self
                                              andPeerFactory:stream.peerFactory];
…
[signalingChannel publish:opts signalingChannelDelegate:publishClient];
…
[streamSignalingDelegates setValue:delegate forKey:streamId];
++++++++++++++++++++++++++++++++++++++++++++++++

@protocol ECSignalingChannelRoomDelegate //ECRoom
…
@end

@interface ECSignalingChannel : NSObject
@property (weak, nonatomic) id<ECSignalingChannelRoomDelegate> roomDelegate; //ECSignalingChannel -> ECRoom
…
@end

@interface ECSignalingChannel () <SocketIODelegate>
@end

---------------------------------------------------
@interface ECSignalingMessage : NSObject
…
@end

---------------------------------------------------
@protocol ECRoomDelegate <NSObject>  //MultiConferenceViewController
…
@end

@interface ECRoom : NSObject <ECSignalingChannelRoomDelegate, ECClientDelegate>
@property (weak, nonatomic, readonly) id <ECRoomDelegate> delegate; //ECRoom -> MultiConferenceViewController
…
@end

---------------------------------------------------
@interface MultiConferenceViewController : UIViewController <ECRoomDelegate>
…
@end


#########################################################################

streamSignalingDelegates  // streamId -> ECRoom

ECRoom{
    ECSignalingChannel *signalingChannel;
    ECClient *publishClient;
    ECClient *subscribeClient;
}

ECClient {
    ECClientState state;
    NSString *currentStreamId;
    NSString *peerSocketValue;
    Boolean setRemoteDesc;
}

ECSignalingChannel {
    SocketIO *socketIO;
    BOOL isConnected;
    NSString *encodedToken;
    NSDictionary *decodedToken;
    NSMutableDictionary *outMessagesQueues;         // for candidate
    NSMutableDictionary *streamSignalingDelegates;  // streamid -> ECRoom
    NSMutableDictionary *peerSignalingDelegates;    // peerSock -> ECRoom
    NSDictionary *roomMetadata;
    NSString *localStreamId;
    ECStream *localStreamMe;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1024app_ios_2.3.4是一款专为iOS设备设计的应用程序,其版本号为2.3.4。该应用程序在功能上提供了丰富的内容和服务,可以满足用户在不同方面的需求。 1024app_ios_2.3.4首先具备了强大的应用市场功能,用户可以通过该应用程序方便地浏览和搜索各种类型的应用,包括游戏、社交媒体、工具类等。用户可以根据自己的兴趣和需求下载和安装这些应用,并在手机上进行使用。 其次,1024app_ios_2.3.4还提供了个性化推荐功能,根据用户的使用习惯和喜好,推荐适合用户的应用程序。这样,用户可以更加高效地发现和使用他们感兴趣的应用,提高了用户体验。 另外,1024app_ios_2.3.4还支持应用的更新和升级。用户可以在应用程序中获得关于已安装应用的最新版本信息,并进行更新。这样,用户可以及时获得应用程序的最新功能和修复bug,提高了应用的稳定性和安全性。 最后,1024app_ios_2.3.4还具备了一些额外的功能,例如用户可以在应用中进行应用评分和评论,与其他用户交流和分享使用心得。此外,用户还可以通过该应用程序获取关于应用的详细信息,如应用的大小、开发者介绍等。 综上所述,1024app_ios_2.3.4是一款功能强大的iOS应用程序,用户可以在其中浏览和下载各种类型的应用,享受个性化推荐、应用更新和升级等服务。同时,用户还可以与其他用户互动交流,获取应用的详细信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值