-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
## Description Remove redundant code and add ComandsQueue to enforce some order in processing webrtc events. ## Motivation and Context There were couple of bugs related to inproper processing of webrtc evets. This is a sollution for it and also simplification for code. ## Types of changes - [x] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [x] Breaking change (fix or feature that would cause existing functionality to not work as expected) ## Checklist: - [x] My code follows the code style of this project. - [ ] My change requires a change to the documentation. - [ ] I have updated the documentation accordingly.
- Loading branch information
Showing
93 changed files
with
2,244 additions
and
3,147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
EXPO_PUBLIC_ROOM_MANAGER_URL=Your Fishjam URL | ||
|
||
EXPO_PUBLIC_FISHJAM_URL=Your fishjam URL for conenct with TOKEN | ||
EXPO_PUBLIC_FISHJAM_TOKEN=Your fishjam TOKEN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"extends": ["../../.eslintrc.js"], | ||
"extends": ["../../.eslintrc.js"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
196 changes: 98 additions & 98 deletions
196
examples/video-chat/ios/FishjamExample.xcodeproj/project.pbxproj
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import Promises | ||
|
||
internal enum CommandName { | ||
case CONNECT, JOIN, ADD_TRACK, REMOVE_TRACK, RENEGOTIATE, LEAVE | ||
} | ||
|
||
internal enum ClientState { | ||
case CREATED, CONNECTED, JOINED | ||
} | ||
|
||
internal class Command { | ||
let commandName: CommandName | ||
let clientStateAfterCommand: ClientState? | ||
let promise: Promise<Void> | ||
let block: () -> Void | ||
|
||
init(commandName: CommandName, clientStateAfterCommand: ClientState?, block: @escaping () -> Void) { | ||
self.commandName = commandName | ||
self.clientStateAfterCommand = clientStateAfterCommand | ||
self.block = block | ||
self.promise = Promise<Void>.pending() | ||
} | ||
|
||
func execute() { | ||
DispatchQueue.fishjam.async { | ||
self.block() | ||
self.promise.fulfill(()) | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
packages/ios-client/Sources/FishjamClient/CommandsQueue.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import Promises | ||
|
||
internal class CommandsQueue { | ||
var clientState: ClientState = ClientState.CREATED | ||
private var commandsQueue: [Command] = [] | ||
|
||
@discardableResult | ||
func addCommand(_ command: Command) -> Promise<Void> { | ||
commandsQueue.append(command) | ||
if commandsQueue.count == 1 { | ||
command.execute() | ||
} | ||
return command.promise | ||
} | ||
|
||
func finishCommand() { | ||
guard let command = commandsQueue.first else { return } | ||
commandsQueue.removeFirst() | ||
if let nextState = command.clientStateAfterCommand { | ||
clientState = nextState | ||
} | ||
if let nextCommand = commandsQueue.first { | ||
nextCommand.execute() | ||
} | ||
|
||
} | ||
|
||
func finishCommand(commandName: CommandName) { | ||
if !commandsQueue.isEmpty && commandsQueue.first!.commandName == commandName { | ||
finishCommand() | ||
} | ||
} | ||
|
||
func finishCommand(commandNames: [CommandName]) { | ||
if !commandsQueue.isEmpty && commandNames.contains(commandsQueue.first!.commandName) { | ||
finishCommand() | ||
} | ||
} | ||
|
||
func clear() { | ||
clientState = .CREATED | ||
commandsQueue.forEach { command in | ||
command.promise.reject("Command queue was cleared") | ||
} | ||
commandsQueue.removeAll() | ||
} | ||
|
||
} |
Oops, something went wrong.