Skip to content

Commit

Permalink
Initiate multiple requests when websocket is connected
Browse files Browse the repository at this point in the history
  • Loading branch information
mekya committed Apr 7, 2024
1 parent 8caca5c commit 952ca6c
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions WebRTCiOSSDK/api/AntMediaClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ open class AntMediaClient: NSObject, AntMediaClientProtocol {
private var useExternalCameraSource: Bool = false

private var isWebSocketConnected: Bool = false;
private var isWebSocketConnecting: Bool = false;

private var externalAudioEnabled: Bool = false;

Expand Down Expand Up @@ -447,7 +448,8 @@ open class AntMediaClient: NSObject, AntMediaClientProtocol {
AntMediaClient.dispatchQueue.async
{
AntMediaClient.printf("Connect websocket to \(self.getWsUrl())")
if (!self.isWebSocketConnected) { //provides backward compatibility
if (!self.isWebSocketConnected && !self.isWebSocketConnecting) { //provides backward compatibility
self.isWebSocketConnecting = true;
self.streamsInTheRoom.removeAll();
AntMediaClient.printf("Will connect to: \(self.getWsUrl()) for stream: \(self.getStreamId())")

Expand All @@ -457,7 +459,12 @@ open class AntMediaClient: NSObject, AntMediaClientProtocol {

}
else {
AntMediaClient.printf("WebSocket is already connected to: \(self.getWsUrl())")
if (self.isWebSocketConnected) {
AntMediaClient.printf("WebSocket is already connected to: \(self.getWsUrl())")
}
if (self.isWebSocketConnecting) {
AntMediaClient.printf("WebSocket is connecting to: \(self.getWsUrl())")
}
}
}
}
Expand Down Expand Up @@ -788,13 +795,14 @@ open class AntMediaClient: NSObject, AntMediaClientProtocol {
if mode == AntMediaClientMode.conference {
sendJoinConferenceCommand();
}
else if let streamId = self.publisherStreamId {
//multiple modes can be active at a time so they are "if" statement
if let streamId = self.publisherStreamId {
sendPublishCommand(streamId)
}
else if let streamId = self.playerStreamId {
if let streamId = self.playerStreamId {
sendPlayCommand(streamId)
}
else if let streamId = self.p2pStreamId {
if let streamId = self.p2pStreamId {
sendJoinCommand(streamId)
}
}
Expand Down Expand Up @@ -1269,6 +1277,7 @@ extension AntMediaClient: WebSocketDelegate {
switch event {
case .connected(let headers):
isWebSocketConnected = true;
isWebSocketConnecting = false;
AntMediaClient.printf("websocket is connected: \(headers)")
self.websocketConnected()
self.delegate?.clientDidConnect(self)
Expand All @@ -1281,6 +1290,7 @@ extension AntMediaClient: WebSocketDelegate {
break;
case .disconnected(let reason, let code):
isWebSocketConnected = false;
isWebSocketConnecting = false;
AntMediaClient.printf("websocket is disconnected: \(reason) with code: \(code)")
pingTimer?.invalidate()
self.websocketDisconnected(message:reason, code:code)
Expand All @@ -1303,13 +1313,15 @@ extension AntMediaClient: WebSocketDelegate {
break
case .cancelled:
isWebSocketConnected = false;
isWebSocketConnecting = false;
pingTimer?.invalidate()
webSocket?.disconnect();

AntMediaClient.printf("Websocket is cancelled");
break;
case .error(let error):
isWebSocketConnected = false;
isWebSocketConnecting = false;
pingTimer?.invalidate()
webSocket?.disconnect();
self.websocketDisconnected(message: String(describing: error), code:0);
Expand Down

0 comments on commit 952ca6c

Please sign in to comment.