Skip to content

Commit

Permalink
Revert "Add header-based access control (#421)"
Browse files Browse the repository at this point in the history
This reverts commit f056bc3.
  • Loading branch information
0xcadams committed Dec 11, 2023
1 parent 2bc7c9f commit 8a60e2d
Show file tree
Hide file tree
Showing 16 changed files with 36 additions and 283 deletions.
16 changes: 0 additions & 16 deletions .changeset/beige-countries-warn.md

This file was deleted.

8 changes: 0 additions & 8 deletions .changeset/quiet-peaches-smash.md

This file was deleted.

1 change: 0 additions & 1 deletion examples/_next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"lint": "next lint"
},
"dependencies": {
"@livepeer/core": "^2.0.10",
"@livepeer/react": "^3.0.10",
"@rainbow-me/rainbowkit": "^0.8.0",
"ethers": "^5.7.2",
Expand Down
77 changes: 0 additions & 77 deletions examples/_next/src/pages/api/jwt.ts

This file was deleted.

29 changes: 12 additions & 17 deletions packages/core-react/src/components/media/player/usePlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,19 +238,18 @@ export const usePlayer = <
) => {
const [mediaElement, setMediaElement] = React.useState<TElement | null>(null);

const { source, uploadStatus, jwtResolved, accessKeyResolved } =
useSourceMimeTyped({
src,
playbackId,
jwt,
refetchPlaybackInfoInterval,
autoUrlUpload,
screenWidth: _screenWidth,
playbackInfo,
accessKey,
onAccessKeyRequest,
playRecording,
});
const { source, uploadStatus } = useSourceMimeTyped({
src,
playbackId,
jwt,
refetchPlaybackInfoInterval,
autoUrlUpload,
screenWidth: _screenWidth,
playbackInfo,
accessKey,
onAccessKeyRequest,
playRecording,
});

const [playbackError, setPlaybackError] =
React.useState<PlaybackError | null>(null);
Expand Down Expand Up @@ -369,8 +368,6 @@ export const usePlayer = <
viewerId,
onPlaybackStatusUpdate,
playbackStatusSelector,
jwt: jwtResolved,
accessKey: accessKeyResolved,
}),
[
playerRef,
Expand All @@ -388,8 +385,6 @@ export const usePlayer = <
viewerId,
onPlaybackStatusUpdate,
playbackStatusSelector,
jwtResolved,
accessKeyResolved,
],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,57 +274,46 @@ export const useSourceMimeTyped = <
return defaultValue;
}

const mediaSourceTypes = sources
.map((s) => (typeof s === 'string' ? getMediaSourceType(s) : null))
.filter((s) => s) as Src[];

const authenticatedSources = mediaSourceTypes.map((source) => {
// we use headers for HLS and WebRTC for auth
if (source.type === 'hls' || source.type === 'webrtc') {
return source;
}

const authenticatedSources = sources.map((source) => {
// append the JWT to the query params
if (jwt && source) {
const url = new URL(source.src);
const url = new URL(source);
url.searchParams.append('jwt', jwt);
return {
...source,
src: url.toString(),
};
return url.toString();
}

// append the access key to the query params
if (accessKeyResolved && source) {
const url = new URL(source.src);
const url = new URL(source);
url.searchParams.append('accessKey', accessKeyResolved);
return {
...source,
src: url.toString(),
};
return url.toString();
}

return source;
});

const mediaSourceTypes = authenticatedSources
.map((s) => (typeof s === 'string' ? getMediaSourceType(s) : null))
.filter((s) => s) as Src[];

// we filter by either audio or video/hls
return authenticatedSources?.[0]?.type === 'audio'
return mediaSourceTypes?.[0]?.type === 'audio'
? ([
'audio',
authenticatedSources.filter((s) => s.type === 'audio') as AudioSrc[],
mediaSourceTypes.filter((s) => s.type === 'audio') as AudioSrc[],
] as const)
: authenticatedSources?.[0]?.type === 'video' ||
authenticatedSources?.[0]?.type === 'hls' ||
authenticatedSources?.[0]?.type === 'webrtc'
: mediaSourceTypes?.[0]?.type === 'video' ||
mediaSourceTypes?.[0]?.type === 'hls' ||
mediaSourceTypes?.[0]?.type === 'webrtc'
? ([
'video',
authenticatedSources.filter(
mediaSourceTypes.filter(
(s) =>
s.type === 'video' || s.type === 'hls' || s.type === 'webrtc',
) as (VideoSrc | HlsSrc | WebRTCSrc)[],
] as const)
: defaultValue;
}, [playbackUrls, src, playRecording]);
}, [playbackUrls, src, jwt, accessKeyResolved, playRecording]);

const sourceMimeTypedSorted = React.useMemo(() => {
// if there is no source mime type and the Player has dstorage fallback enabled,
Expand Down Expand Up @@ -372,7 +361,5 @@ export const useSourceMimeTyped = <
return {
source: sourceMimeTypedSorted,
uploadStatus,
accessKeyResolved,
jwtResolved: jwt,
} as const;
};
31 changes: 2 additions & 29 deletions packages/core-web/src/media/browser/webrtc/shared.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
AccessControlParams,
NOT_ACCEPTABLE_ERROR_MESSAGE,
} from '@livepeer/core';
import { NOT_ACCEPTABLE_ERROR_MESSAGE } from '@livepeer/core';
import fetch from 'cross-fetch';

import { isClient } from '../utils';
Expand Down Expand Up @@ -75,12 +72,6 @@ export type WebRTCVideoConfig = {
* @default 20000
*/
sdpTimeout?: number;
/**
* The timeout of the time to wait for ICE candidates, in ms.
*
* @default 5000
*/
iceCandidateTimeout?: number;
/**
* Disables the speedup/slowdown mechanic in WebRTC, to allow for non-distorted audio.
*/
Expand All @@ -106,21 +97,14 @@ export async function negotiateConnectionWithClientOffer(
ofr: RTCSessionDescription | null,
controller: AbortController,
config?: WebRTCVideoConfig,
accessControl?: AccessControlParams,
): Promise<Date> {
if (peerConnection && endpoint && ofr) {
/**
* This response contains the server's SDP offer.
* This specifies how the client should communicate,
* and what kind of media client and server have negotiated to exchange.
*/
const response = await postSDPOffer(
endpoint,
ofr.sdp,
controller,
config,
accessControl,
);
const response = await postSDPOffer(endpoint, ofr.sdp, controller, config);
if (response.ok) {
const answerSDP = await response.text();
await peerConnection.setRemoteDescription(
Expand Down Expand Up @@ -176,7 +160,6 @@ async function postSDPOffer(
data: string,
controller: AbortController,
config?: WebRTCVideoConfig,
accessControl?: AccessControlParams,
) {
const id = setTimeout(
() => controller.abort(),
Expand All @@ -194,16 +177,6 @@ async function postSDPOffer(
mode: 'cors',
headers: {
'content-type': 'application/sdp',
...(accessControl?.accessKey
? {
'Livepeer-Access-Key': accessControl.accessKey,
}
: {}),
...(accessControl?.jwt
? {
'Livepeer-Jwt': accessControl.jwt,
}
: {}),
},
body: data,
signal: controller.signal,
Expand Down
35 changes: 0 additions & 35 deletions packages/core-web/src/media/browser/webrtc/whep.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { AccessControlParams } from '@livepeer/core';

import {
WebRTCVideoConfig,
constructClientOffer,
Expand All @@ -23,7 +21,6 @@ export const createNewWHEP = <TElement extends HTMLMediaElement>(
onRedirect?: (url: string | null) => void;
},
config?: WebRTCVideoConfig,
accessControl?: AccessControlParams,
): {
destroy: () => void;
} => {
Expand Down Expand Up @@ -140,7 +137,6 @@ export const createNewWHEP = <TElement extends HTMLMediaElement>(
ofr,
abortController,
config,
accessControl,
);

const currentDate = Date.now();
Expand All @@ -154,37 +150,6 @@ export const createNewWHEP = <TElement extends HTMLMediaElement>(
errorComposed(e as Error);
}
});

let iceCandidatesGenerated = false;

const iceCandidateTimeout = setTimeout(() => {
if (!iceCandidatesGenerated) {
errorComposed(new Error('Failed to generate any ICE candidates'));
}
}, config?.iceCandidateTimeout ?? 5000);

peerConnection?.addEventListener('icecandidate', (event) => {
if (event.candidate) {
clearTimeout(iceCandidateTimeout);
iceCandidatesGenerated = true;
}
});

peerConnection.addEventListener('iceconnectionstatechange', (_e) => {
if (peerConnection?.iceConnectionState === 'failed') {
errorComposed(new Error('ICE Connection Failed'));
}
});

peerConnection.addEventListener('icecandidateerror', (e) => {
errorComposed(
new Error(
`ICE Candidate Error: ${
(e as RTCPeerConnectionIceErrorEvent)?.errorText
}`,
),
);
});
}
})
.catch((e) => errorComposed(e as Error));
Expand Down
Loading

2 comments on commit 8a60e2d

@vercel
Copy link

@vercel vercel bot commented on 8a60e2d Dec 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 8a60e2d Dec 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.