Skip to content

Commit

Permalink
Dev/prettier3 (#1794)
Browse files Browse the repository at this point in the history
* Update Prettier to 3

* Add eslint-config-prettier
  • Loading branch information
whitphx authored Sep 14, 2024
1 parent cb5fa88 commit a7c3756
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 29 deletions.
1 change: 1 addition & 0 deletions streamlit_webrtc/frontend/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = {
"plugin:react/recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:storybook/recommended",
"prettier",
],
globals: {
Atomics: "readonly",
Expand Down
40 changes: 31 additions & 9 deletions streamlit_webrtc/frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion streamlit_webrtc/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@
"@storybook/react": "^8.3.0",
"@storybook/react-webpack5": "^8.3.0",
"@storybook/test": "^8.3.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-storybook": "^0.8.0",
"prettier": "^2.7.1",
"prettier": "^3.3.3",
"storybook": "^8.3.0"
},
"jest": {
Expand Down
6 changes: 3 additions & 3 deletions streamlit_webrtc/frontend/src/DeviceSelect/DeviceSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { stopAllTracks } from "./utils";

function ensureValidSelection(
devices: MediaDeviceInfo[],
selectedDeviceId: MediaDeviceInfo["deviceId"] | undefined
selectedDeviceId: MediaDeviceInfo["deviceId"] | undefined,
): MediaDeviceInfo["deviceId"] | undefined {
const deviceIds = devices.map((d) => d.deviceId);
if (selectedDeviceId && deviceIds.includes(selectedDeviceId)) {
Expand Down Expand Up @@ -93,11 +93,11 @@ const deviceSelectionReducer: Reducer<

const selectedVideoInputDeviceId = ensureValidSelection(
videoInputs,
state.selectedVideoInputDeviceId
state.selectedVideoInputDeviceId,
);
const selectedAudioInputDeviceId = ensureValidSelection(
audioInputs,
state.selectedAudioInputDeviceId
state.selectedAudioInputDeviceId,
);

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface DeviceSelectContainerProps {
children: React.ReactNode;
}
const DeviceSelectContainer: React.VFC<DeviceSelectContainerProps> = (
props
props,
) => {
const theme = useTheme();
const isSmallViewport = useMediaQuery(theme.breakpoints.down("sm"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface DeviceNotAvailableMessageProps {
error: Error;
}
const DeviceNotAvailableMessage: React.VFC<DeviceNotAvailableMessageProps> = (
props
props,
) => {
return (
<Message>
Expand Down
2 changes: 1 addition & 1 deletion streamlit_webrtc/frontend/src/MediaStreamPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const MediaStreamPlayer: React.VFC<MediaStreamPlayerProps> = (props) => {
node.srcObject = props.stream;
}
},
[props.stream]
[props.stream],
);

const refreshFrameHeight = useCallback(() => Streamlit.setFrameHeight(), []);
Expand Down
4 changes: 2 additions & 2 deletions streamlit_webrtc/frontend/src/WebRtcStreamer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const WebRtcStreamerInner: React.VFC<WebRtcStreamerInnerProps> = (props) => {
deviceIds.video,
deviceIds.audio,
props.onComponentValueChange,
setDeviceIds
setDeviceIds,
);

const mode = props.mode;
Expand All @@ -50,7 +50,7 @@ const WebRtcStreamerInner: React.VFC<WebRtcStreamerInnerProps> = (props) => {
const receivable = isWebRtcMode(mode) && isReceivable(mode);
const transmittable = isWebRtcMode(mode) && isTransmittable(mode);
const { videoEnabled, audioEnabled } = getMediaUsage(
props.mediaStreamConstraints
props.mediaStreamConstraints,
);

const [deviceSelectOpen, setDeviceSelectOpen] = useState(false);
Expand Down
2 changes: 1 addition & 1 deletion streamlit_webrtc/frontend/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ ReactDOM.render(
</TranslationProvider>
</StreamlitProvider>
</React.StrictMode>,
document.getElementById("root")
document.getElementById("root"),
);
2 changes: 1 addition & 1 deletion streamlit_webrtc/frontend/src/media-constraint.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export function compileMediaConstraints(
src: MediaStreamConstraints | undefined,
videoDeviceId: string | undefined,
audioDeviceId: string | undefined
audioDeviceId: string | undefined,
): MediaStreamConstraints {
const constraints = src || {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useRenderData } from "streamlit-component-lib-react-hooks";
import { Translations } from "./types";

const translationContext = React.createContext<Translations | undefined>(
undefined
undefined,
);

export const useTranslation = (key: keyof Translations) => {
Expand Down Expand Up @@ -47,7 +47,7 @@ const TranslationProvider: React.VFC<TranslationProviderProps> = (props) => {
device_not_available,
device_access_denied,
media_api_not_available,
]
],
);
return (
<translationContext.Provider value={value}>
Expand Down
15 changes: 9 additions & 6 deletions streamlit_webrtc/frontend/src/webrtc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const isTransmittable = (mode: WebRtcMode): boolean =>
mode === "SENDRECV" || mode === "SENDONLY";

const setupOffer = (
pc: RTCPeerConnection
pc: RTCPeerConnection,
): Promise<RTCSessionDescription | null> => {
return pc
.createOffer()
Expand Down Expand Up @@ -60,7 +60,10 @@ export const useWebRtc = (
videoDeviceIdRequest: MediaDeviceInfo["deviceId"] | undefined,
audioDeviceIdRequest: MediaDeviceInfo["deviceId"] | undefined,
onComponentValueChange: (newComponentValue: ComponentValue) => void,
onDevicesOpened: (openedDeviceIds: { video?: string; audio?: string }) => void
onDevicesOpened: (openedDeviceIds: {
video?: string;
audio?: string;
}) => void,
) => {
// Initialize component value
useEffect(() => {
Expand All @@ -74,7 +77,7 @@ export const useWebRtc = (
const pcRef = useRef<RTCPeerConnection>();
const reducer = useMemo(
() => connectReducer(onComponentValueChange),
[onComponentValueChange]
[onComponentValueChange],
);
const [state, dispatch] = useReducer(reducer, initialState);

Expand Down Expand Up @@ -156,7 +159,7 @@ export const useWebRtc = (
const constraints = compileMediaConstraints(
props.mediaStreamConstraints,
videoDeviceIdRequest,
audioDeviceIdRequest
audioDeviceIdRequest,
);
console.log("MediaStreamConstraints:", constraints);

Expand All @@ -165,7 +168,7 @@ export const useWebRtc = (
// Ref: https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia#privacy_and_security
// > A secure context is, in short, a page loaded using HTTPS or the file:/// URL scheme, or a page loaded from localhost.
throw new Error(
"navigator.mediaDevices is undefined. It seems the current document is not loaded securely."
"navigator.mediaDevices is undefined. It seems the current document is not loaded securely.",
);
}
if (navigator.mediaDevices.getUserMedia == null) {
Expand Down Expand Up @@ -232,7 +235,7 @@ export const useWebRtc = (
dispatch({
type: "ERROR",
error,
})
}),
);
}, [
audioDeviceIdRequest,
Expand Down
2 changes: 1 addition & 1 deletion streamlit_webrtc/frontend/src/webrtc/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const reducer: React.Reducer<State, Action> = (state, action) => {
};

export const connectReducer = (
onComponentValueChange: (newComponentValue: ComponentValue) => void
onComponentValueChange: (newComponentValue: ComponentValue) => void,
): React.Reducer<State, Action> => {
const connectedReducer: React.Reducer<State, Action> = (state, action) => {
const nextState = reducer(state, action);
Expand Down

0 comments on commit a7c3756

Please sign in to comment.