-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FCE-205 Refactor into smaller files #7
Merged
Merged
Changes from all commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
fc5ca0a
Extract `createVideoTransceiverConfig` to separate file
kamil-stasiak 5700fe3
Extract `createAudioTransceiverConfig` to separate file
kamil-stasiak 60870c6
Remove `createVideoTransceiverConfig` private function
kamil-stasiak 934e78c
Move `createTransceiverConfig` to separate file
kamil-stasiak a30b60e
Move `addTrackToConnection` to separate file
kamil-stasiak 34d7517
Extract `setTransceiverDirection` function
kamil-stasiak eb38b61
Move `addTransceiversIfNeeded` to a separate file
kamil-stasiak 0121d8f
Extract `setTransceiversToReadOnly` function to a separate file
kamil-stasiak c323afd
Move `getMidToTrackId` function to a separate file
kamil-stasiak 83faa65
Extract `findSenderByTrack` function to a separate file
kamil-stasiak 1d30724
Extract `isTrackInUse` function to a separate file
kamil-stasiak 0f95ae5
Use already existing `findSenderByTrack` function
kamil-stasiak 7d53c21
Use already existing `findSender` function
kamil-stasiak b887386
Extract `createSdpOfferEvent` to a separte file
kamil-stasiak 6be7d60
Merge main
kamil-stasiak 4eb6603
Merge main
kamil-stasiak 54fe6ea
Merge branch 'main' of github.com:fishjam-cloud/web-client-sdk into r…
kamil-stasiak 28b8871
Merge
kamil-stasiak f67e25d
Format
kamil-stasiak fd09728
WIP
kamil-stasiak 6e0a853
Merge branch 'main' of github.com:fishjam-cloud/web-client-sdk into r…
kamil-stasiak fd42d83
Extract turn to the separate file
kamil-stasiak 1e4893c
Extract `mapMediaEventTracksToTrackContextImpl` to `./internals.ts`
kamil-stasiak 5905851
Extract State manager to the separate file
kamil-stasiak ee09df5
Extract `onAnswer`, `disableTrackEncoding`, `onTrack`, `checkIfTrackB…
kamil-stasiak 02e5f47
Extract `onTracksAdded` to `StateManager.ts`
kamil-stasiak 007ae8a
Extract `onTracksRemoved` and `eraseTrack` to `StateManager.ts`
kamil-stasiak 7476c29
Extract `onSdpAnswer` to `StateManager.ts`
kamil-stasiak 2c556b0
Extract `onEndpointAdded`, `onEndpointUpdated` and `addEndpoint` to `…
kamil-stasiak 214f2dd
Extract `onEndpointRemoved` and `eraseEndpoint` to `StateManager.ts`
kamil-stasiak a201025
Extract `onTrackUpdated` to `StateManager.ts`
kamil-stasiak 0e92000
Extract `onTrackEncodingDisabled` to `StateManager.ts`
kamil-stasiak c0e6b5b
Extract `onTrackEncodingEnabled` to `StateManager.ts`
kamil-stasiak bc52948
Add comment to `tracksPriority`
kamil-stasiak 203fc80
Extract `onEncodingSwitched` to `StateManager.ts`
kamil-stasiak ca5533f
Move `onVadNotification` to `StateManager.ts`
kamil-stasiak 96bc569
Extract `onBandwidthEstimation` to `StateManager.ts`
kamil-stasiak 2e1091a
Extract `NegotiationManager` to `StateManager.ts`
kamil-stasiak 42cd9dd
Extract `CommandsQueue` to the separate file
kamil-stasiak 96db590
Move CommandsQueue.ts listener logic to CommandsQueue
kamil-stasiak aa41395
Fix format
kamil-stasiak d2d288e
Move `removeTrackHandler` to StateManager.ts
kamil-stasiak 8c2a66d
Move `replaceTrackHandler` to StateManager.ts
kamil-stasiak e558f79
Move `addTrackHandler` to StateManager.ts
kamil-stasiak e1408e0
Fix format and lint
kamil-stasiak f7df3a3
Revert e2e test file
kamil-stasiak 34e58f0
Remove commendType
kamil-stasiak 266f6d0
Apply PR suggestions
kamil-stasiak a450586
Apply PR suggestions
kamil-stasiak 65d36ea
Add readonly to CommandQueue field
kamil-stasiak adbab5a
Apply PR suggestions
kamil-stasiak 6f7d020
Fix lint and format
kamil-stasiak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,156 @@ | ||
import type { Command } from './commands'; | ||
import type { Deferred } from './deferred'; | ||
import type { StateManager } from './StateManager'; | ||
import type { NegotiationManager } from './NegotiationManager'; | ||
|
||
export class CommandsQueue<EndpointMetadata, TrackMetadata> { | ||
private readonly stateManager: StateManager<EndpointMetadata, TrackMetadata>; | ||
private readonly negotiationManager: NegotiationManager; | ||
|
||
private clearConnectionCallbacks: (() => void) | null = null; | ||
|
||
constructor( | ||
stateManager: StateManager<EndpointMetadata, TrackMetadata>, | ||
negotiationManager: NegotiationManager, | ||
) { | ||
this.stateManager = stateManager; | ||
this.negotiationManager = negotiationManager; | ||
} | ||
|
||
public setupEventListeners = (connection: RTCPeerConnection) => { | ||
const onSignalingStateChange = () => { | ||
switch (this.stateManager.connection?.signalingState) { | ||
case 'stable': | ||
this.processNextCommand(); | ||
break; | ||
} | ||
}; | ||
|
||
const onIceGatheringStateChange = () => { | ||
switch (this.stateManager.connection?.iceGatheringState) { | ||
case 'complete': | ||
this.processNextCommand(); | ||
break; | ||
} | ||
}; | ||
|
||
const onConnectionStateChange = () => { | ||
switch (connection.connectionState) { | ||
case 'connected': | ||
this.processNextCommand(); | ||
break; | ||
} | ||
}; | ||
const onIceConnectionStateChange = () => { | ||
switch (this.stateManager.connection?.iceConnectionState) { | ||
case 'connected': | ||
this.processNextCommand(); | ||
break; | ||
} | ||
}; | ||
|
||
this.clearConnectionCallbacks = () => { | ||
connection.removeEventListener( | ||
'signalingstatechange', | ||
onSignalingStateChange, | ||
); | ||
connection.removeEventListener( | ||
'icegatheringstatechange', | ||
onIceGatheringStateChange, | ||
); | ||
connection.removeEventListener( | ||
'connectionstatechange', | ||
onConnectionStateChange, | ||
); | ||
connection.removeEventListener( | ||
'iceconnectionstatechange', | ||
onIceConnectionStateChange, | ||
); | ||
}; | ||
|
||
connection.addEventListener( | ||
'icegatheringstatechange', | ||
onIceConnectionStateChange, | ||
); | ||
connection.addEventListener( | ||
'connectionstatechange', | ||
onConnectionStateChange, | ||
); | ||
connection.addEventListener( | ||
'iceconnectionstatechange', | ||
onIceConnectionStateChange, | ||
); | ||
connection.addEventListener('signalingstatechange', onSignalingStateChange); | ||
}; | ||
|
||
private commandsQueue: Command[] = []; | ||
private commandResolutionNotifier: Deferred<void> | null = null; | ||
|
||
public pushCommand = (command: Command) => { | ||
this.commandsQueue.push(command); | ||
this.processNextCommand(); | ||
}; | ||
|
||
private isConnectionUnstable = () => { | ||
const connection = this.stateManager.connection; | ||
if (connection === undefined) return false; | ||
|
||
const isSignalingUnstable = connection.signalingState !== 'stable'; | ||
const isConnectionNotConnected = connection.connectionState !== 'connected'; | ||
const isIceNotConnected = connection.iceConnectionState !== 'connected'; | ||
|
||
return isSignalingUnstable && isConnectionNotConnected && isIceNotConnected; | ||
}; | ||
|
||
private isNegotiationInProgress = () => { | ||
return ( | ||
this.negotiationManager.ongoingRenegotiation || | ||
this.stateManager.ongoingTrackReplacement | ||
); | ||
}; | ||
|
||
public processNextCommand = () => { | ||
if (this.isNegotiationInProgress()) return; | ||
if (this.isConnectionUnstable()) return; | ||
|
||
this.resolvePreviousCommand(); | ||
|
||
const command = this.commandsQueue.shift(); | ||
|
||
if (!command) return; | ||
|
||
this.commandResolutionNotifier = command.resolutionNotifier; | ||
this.handleCommand(command); | ||
}; | ||
|
||
private handleCommand = (command: Command) => { | ||
const error = command.validate?.(); | ||
|
||
if (error) { | ||
this.commandResolutionNotifier?.reject(error); | ||
this.commandResolutionNotifier = null; | ||
this.processNextCommand(); | ||
} else { | ||
command.handler(); | ||
|
||
if (command.resolve === 'immediately') { | ||
this.resolvePreviousCommand(); | ||
this.processNextCommand(); | ||
} | ||
} | ||
}; | ||
|
||
private resolvePreviousCommand = () => { | ||
if (!this.commandResolutionNotifier) return; | ||
|
||
this.commandResolutionNotifier.resolve(); | ||
this.commandResolutionNotifier = null; | ||
}; | ||
|
||
public cleanUp = () => { | ||
this.commandResolutionNotifier?.reject('Disconnected'); | ||
this.commandResolutionNotifier = null; | ||
this.commandsQueue = []; | ||
this.clearConnectionCallbacks?.(); | ||
}; | ||
} |
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,7 @@ | ||
export class NegotiationManager { | ||
/** | ||
* Indicates if an ongoing renegotiation is active. | ||
* During renegotiation, both parties are expected to actively exchange events: renegotiateTracks, offerData, sdpOffer, sdpAnswer. | ||
*/ | ||
public ongoingRenegotiation: boolean = false; | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WDYT about having two functions
renegotationStarted()
andrenegotationCompleted()
with private variable?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. That's why I created this class. I will do it in future PRs