Skip to content

Commit

Permalink
refactor: Swap func params in correct order
Browse files Browse the repository at this point in the history
  • Loading branch information
DimaDemchenko committed Sep 6, 2024
1 parent 4c3b74f commit a2d14e8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 21 deletions.
11 changes: 6 additions & 5 deletions packages/p2p-media-loader-core/src/hybrid-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,21 @@ export class HybridLoader {
this.p2pLoaders.changeCurrentLoader(stream);
}
this.lastRequestedSegment = segment;

const swarmId = this.config.swarmId ?? this.streamManifestUrl;
const streamSwarmId = StreamUtils.getStreamSwarmId(swarmId, stream);

this.segmentStorage.onSegmentRequested(
stream.runtimeId,
streamSwarmId,
segment.externalId,
segment.startTime,
segment.endTime,
this.config.swarmId ?? this.streamManifestUrl,
swarmId,
stream.type,
this.streamDetails.isLive,
);
const engineRequest = new EngineRequest(segment, callbacks);

const swarmId = this.config.swarmId ?? this.streamManifestUrl;
const streamSwarmId = StreamUtils.getStreamSwarmId(swarmId, stream);

try {
if (
this.segmentStorage.hasSegment(
Expand Down
7 changes: 2 additions & 5 deletions packages/p2p-media-loader-core/src/p2p/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,11 @@ export class P2PLoader {

private getSegmentsAnnouncement() {
const swarmId = this.config.swarmId ?? this.streamManifestUrl;
const streamSwarmId = StreamUtils.getStreamSwarmId(
this.config.swarmId ?? this.streamManifestUrl,
this.stream,
);
const streamSwarmId = StreamUtils.getStreamSwarmId(swarmId, this.stream);

const loaded: number[] = this.segmentStorage.getStoredSegmentIds(
swarmId,
streamSwarmId,
swarmId,
);
const httpLoading: number[] = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ export class P2PLoadersContainer {
this._currentLoaderItem.stream,
);
const ids = this.segmentStorage.getStoredSegmentIds(
swarmId,
streamSwarmId,
swarmId,
);
if (!ids.length) this.destroyAndRemoveLoader(this._currentLoaderItem);
else this.setLoaderDestroyTimeout(this._currentLoaderItem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,7 @@ export class SegmentsMemoryStorage implements SegmentsStorage {
}

// eslint-disable-next-line @typescript-eslint/require-await
async getSegmentData(
streamId: string,
segmentId: number,
_swarmId: string,
): Promise<ArrayBuffer | undefined> {
async getSegmentData(streamId: string, segmentId: number, _swarmId: string) {
const segmentStorageId = getStorageItemId(streamId, segmentId);
const dataItem = this.cache.get(segmentStorageId);

Expand All @@ -121,26 +117,26 @@ export class SegmentsMemoryStorage implements SegmentsStorage {
return dataItem.data;
}

hasSegment(streamId: string, externalId: number, _swarmId: string): boolean {
hasSegment(streamId: string, externalId: number, _swarmId: string) {
const segmentStorageId = getStorageItemId(streamId, externalId);
const segment = this.cache.get(segmentStorageId);

return segment !== undefined;
}

getStoredSegmentIds(streamSwarm: string) {
getStoredSegmentIds(streamId: string, _swarmId: string) {
const externalIds: number[] = [];

for (const { segmentId, streamId } of this.cache.values()) {
if (streamId !== streamSwarm) continue;
for (const { segmentId, streamId: streamCacheId } of this.cache.values()) {
if (streamCacheId !== streamId) continue;
externalIds.push(segmentId);
}

return externalIds;
}

// eslint-disable-next-line @typescript-eslint/require-await
private async clear(isLiveStream: boolean): Promise<boolean> {
private async clear(isLiveStream: boolean) {
if (
!this.currentPlayback ||
!this.mainStreamConfig ||
Expand Down

0 comments on commit a2d14e8

Please sign in to comment.