Skip to content

Commit

Permalink
Clean up request params
Browse files Browse the repository at this point in the history
  • Loading branch information
third774 committed Feb 11, 2025
1 parent be41b43 commit 048d7e5
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/partytracks/src/client/PartyTracks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,15 @@ export class PartyTracks {
sessionError$: Observable<string>;
peerConnectionState$: Observable<RTCPeerConnectionState>;
config: PartyTracksConfig;
#params: URLSearchParams;

constructor(config: PartyTracksConfig = {}) {
this.config = {
prefix: "/partytracks",
maxApiHistory: 100,
...config
};
this.#params = new URLSearchParams(config.apiExtraParams);
this.history = new History<ApiHistoryEntry>(config.maxApiHistory);
this.peerConnection$ = new Observable<RTCPeerConnection>((subscribe) => {
let peerConnection: RTCPeerConnection;
Expand Down Expand Up @@ -191,7 +193,7 @@ export class PartyTracks {
async createSession(peerConnection: RTCPeerConnection) {
logger.debug("🆕 creating new session");
const response = await this.fetchWithRecordedHistory(
`${this.config.prefix}/sessions/new?CreatingSession&${this.config.apiExtraParams}`,
`${this.config.prefix}/sessions/new${this.#params}`,
{ method: "POST" }
);
if (response.status > 400) {
Expand Down Expand Up @@ -284,7 +286,7 @@ export class PartyTracks {
}))
};
const response = await this.fetchWithRecordedHistory(
`${this.config.prefix}/sessions/${sessionId}/tracks/new?PushingTrack&${this.config.apiExtraParams}`,
`${this.config.prefix}/sessions/${sessionId}/tracks/new${this.#params}`,
{
method: "POST",
body: JSON.stringify(requestBody)
Expand Down Expand Up @@ -424,7 +426,7 @@ export class PartyTracks {
this.taskScheduler.schedule(async () => {
const newTrackResponse: TracksResponse =
await this.fetchWithRecordedHistory(
`${this.config.prefix}/sessions/${sessionId}/tracks/new?PullingTrack&${this.config.apiExtraParams}`,
`${this.config.prefix}/sessions/${sessionId}/tracks/new${this.#params}`,
{
method: "POST",
body: JSON.stringify({
Expand Down Expand Up @@ -468,7 +470,7 @@ export class PartyTracks {

const renegotiationResponse =
await this.fetchWithRecordedHistory(
`${this.config.prefix}/sessions/${sessionId}/renegotiate?${this.config.apiExtraParams}`,
`${this.config.prefix}/sessions/${sessionId}/renegotiate${this.#params}`,
{
method: "PUT",
body: JSON.stringify({
Expand Down Expand Up @@ -569,7 +571,7 @@ export class PartyTracks {
force: false
};
const response = await this.fetchWithRecordedHistory(
`${this.config.prefix}/sessions/${sessionId}/tracks/close?${this.config.apiExtraParams}`,
`${this.config.prefix}/sessions/${sessionId}/tracks/close${this.#params}`,
{
method: "PUT",
body: JSON.stringify(requestBody)
Expand Down

0 comments on commit 048d7e5

Please sign in to comment.