Skip to content
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

V2 ws store wss #309

Merged
merged 21 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions apps/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
"axios": "^1.2.0",
"color": "^4.2.3",
"csv-stringify": "^6.2.3",
"deepmerge": "^4.3.0",
"framer-motion": "^8.0.2",
"jotai": "^1.10.0",
"luxon": "^3.1.0",
"luxon": "^3.3.0",
"react": "^18.2.0",
"react-beautiful-dnd": "^13.1.1",
"react-dom": "^18.2.0",
Expand All @@ -29,9 +30,10 @@
"react-qr-code": "^2.0.11",
"react-router-dom": "^6.3.0",
"react-table": "^7.7.0",
"socket.io-client": "^4.5.4",
"react-use-websocket": "^4.3.1",
"typeface-open-sans": "^1.1.13",
"web-vitals": "^3.1.1"
"web-vitals": "^3.1.1",
"zustand": "^4.3.6"
},
"scripts": {
"addversion": "node -p \"'export const ONTIME_VERSION = ' + JSON.stringify(require('../../package.json').version) + ';'\" > src/ONTIME_VERSION.js",
Expand Down Expand Up @@ -63,6 +65,7 @@
"@testing-library/react": "^13.1.1",
"@testing-library/user-event": "^14.1.1",
"@types/color": "^3.0.3",
"@types/luxon": "^3.2.0",
"@types/prop-types": "^15.7.5",
"@types/react": "^18.0.26",
"@types/react-beautiful-dnd": "^13.1.3",
Expand Down
54 changes: 27 additions & 27 deletions apps/client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,32 @@ import { ReactQueryDevtools } from '@tanstack/react-query-devtools';

import ErrorBoundary from './common/components/error-boundary/ErrorBoundary';
import { AppContextProvider } from './common/context/AppContext';
import { LoggingProvider } from './common/context/LoggingContext';
import useElectronEvent from './common/hooks/useElectronEvent';
import { ontimeQueryClient } from './common/queryClient';
import { connectSocket } from './common/utils/socket';
import theme from './theme/theme';
import AppRouter from './AppRouter';

// Load Open Sans typeface
// @ts-expect-error no types from font import
import('typeface-open-sans');

connectSocket();

function App() {
const { isElectron, sendToElectron } = useElectronEvent();

const handleKeyPress = (event:KeyboardEvent) => {
// handle held key
if (event.repeat) return;
// check if the alt key is pressed
if (event.altKey) {
if (event.code === 'KeyT') {
// ask to see debug
sendToElectron('set-window', 'show-dev');
}
const handleKeyPress = (event: KeyboardEvent) => {
// handle held key
if (event.repeat) return;
// check if the alt key is pressed
if (event.altKey) {
if (event.code === 'KeyT') {
// ask to see debug
sendToElectron('set-window', 'show-dev');
}
};
}
};

useEffect(() => {
if (isElectron) {
Expand All @@ -44,22 +46,20 @@ function App() {

return (
<ChakraProvider resetCSS theme={theme}>
<LoggingProvider>
<QueryClientProvider client={ontimeQueryClient}>
<AppContextProvider>
<BrowserRouter>
<div className='App'>
<ErrorBoundary>
<Suspense fallback={null}>
<AppRouter />
</Suspense>
</ErrorBoundary>
<ReactQueryDevtools initialIsOpen={false} />
</div>
</BrowserRouter>
</AppContextProvider>
</QueryClientProvider>
</LoggingProvider>
<QueryClientProvider client={ontimeQueryClient}>
<AppContextProvider>
<BrowserRouter>
<div className='App'>
<ErrorBoundary>
<Suspense fallback={null}>
<AppRouter />
</Suspense>
</ErrorBoundary>
<ReactQueryDevtools initialIsOpen={false} />
</div>
</BrowserRouter>
</AppContextProvider>
</QueryClientProvider>
</ChakraProvider>
);
}
Expand Down
18 changes: 9 additions & 9 deletions apps/client/src/AppRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { lazy, useEffect } from 'react';
import { Navigate, Route, Routes, useLocation, useNavigate } from 'react-router-dom';

import useAliases from './common/hooks-query/useAliases';
import withSocket from './features/viewers/ViewWrapper';
import withData from './features/viewers/ViewWrapper';

const Editor = lazy(() => import('./features/editors/ProtectedEditor'));
const Table = lazy(() => import('./features/table/ProtectedTable'));
Expand All @@ -17,14 +17,14 @@ const Public = lazy(() => import('./features/viewers/public/Public'));
const Lower = lazy(() => import('./features/viewers/lower-thirds/LowerWrapper'));
const StudioClock = lazy(() => import('./features/viewers/studio/StudioClock'));

const STimer = withSocket(TimerView);
const SMinimalTimer = withSocket(MinimalTimerView);
const SClock = withSocket(ClockView);
const SCountdown = withSocket(Countdown);
const SBackstage = withSocket(Backstage);
const SPublic = withSocket(Public);
const SLowerThird = withSocket(Lower);
const SStudio = withSocket(StudioClock);
const STimer = withData(TimerView);
const SMinimalTimer = withData(MinimalTimerView);
const SClock = withData(ClockView);
const SCountdown = withData(Countdown);
const SBackstage = withData(Backstage);
const SPublic = withData(Public);
const SLowerThird = withData(Lower);
const SStudio = withData(StudioClock);

const FeatureWrapper = lazy(() => import('./features/FeatureWrapper'));
const RundownPanel = lazy(() => import('./features/rundown/RundownExport'));
Expand Down
12 changes: 5 additions & 7 deletions apps/client/src/common/api/apiConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@ export const APP_INFO = ['appinfo'];
export const OSC_SETTINGS = ['oscSettings'];
export const APP_SETTINGS = ['appSettings'];
export const VIEW_SETTINGS = ['viewSettings'];
export const RUNTIME = ['runtimeStore'];

// websocket stuff
export const FEAT_CUESHEET = 'feat-cuesheet';
export const FEAT_INFO = 'feat-info';
export const FEAT_MESSAGECONTROL = 'feat-messagecontrol';
export const FEAT_PLAYBACKCONTROL = 'feat-playbackcontrol';
export const FEAT_RUNDOWN = 'feat-rundown';
export const TIMER = 'timer';
// external stuff
export const githubURL = 'https://api.github.com/repos/cpvalente/ontime/releases/latest';

/**
* @description finds server path given the current location, it
Expand All @@ -26,6 +22,8 @@ export const TIMER = 'timer';
export const calculateServer = () => (import.meta.env.DEV ? `http://localhost:${STATIC_PORT}` : window.location.origin);

export const serverURL = calculateServer();
export const websocketUrl = `ws://${window.location.hostname}:${STATIC_PORT}/ws`;

export const eventURL = `${serverURL}/eventdata`;
export const rundownURL = `${serverURL}/eventlist`;
export const ontimeURL = `${serverURL}/ontime`;
Expand Down
11 changes: 10 additions & 1 deletion apps/client/src/common/api/ontimeApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Alias, OSCSettings, Settings, UserFields, ViewSettings } from 'ontime-t

import { InfoType } from '../models/Info';

import { ontimeURL } from './apiConstants';
import { githubURL, ontimeURL } from './apiConstants';

/**
* @description HTTP request to retrieve application settings
Expand Down Expand Up @@ -151,3 +151,12 @@ export const uploadData = async (file: string, setProgress: (value: number) => v
})
.then((response) => response.data.id);
};

/**
* @description HTTP request to get the latest version and url from github
* @return {Promise}
*/
export async function getLatestVersion(): Promise<object> {
const res = await axios.get(`${githubURL}`);
return { url: res.data.html_url, version: res.data.tag_name };
}
6 changes: 3 additions & 3 deletions apps/client/src/common/components/buttons/QuitIconBtn.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useContext, useEffect, useRef, useState } from 'react';
import { useCallback, useEffect, useRef, useState } from 'react';
import {
AlertDialog,
AlertDialogBody,
Expand All @@ -12,8 +12,8 @@ import {
} from '@chakra-ui/react';
import { FiPower } from '@react-icons/all-files/fi/FiPower';

import { LoggingContext } from '../../context/LoggingContext';
import { Size } from '../../models/Util.type';
import { useEmitLog } from '../../stores/logger';

interface QuitIconBtnProps {
clickHandler: () => void;
Expand All @@ -39,7 +39,7 @@ const quitBtnStyle = {
export default function QuitIconBtn(props: QuitIconBtnProps) {
const { clickHandler, size = 'lg', ...rest } = props;
const [isOpen, setIsOpen] = useState(false);
const { emitInfo } = useContext(LoggingContext);
const { emitInfo } = useEmitLog();
const onClose = () => setIsOpen(false);
const cancelRef = useRef<HTMLButtonElement | null>(null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
import React from 'react';
import * as Sentry from '@sentry/react';

import { LoggingContext } from '../../context/LoggingContext';

import style from './ErrorBoundary.module.scss';

class ErrorBoundary extends React.Component {
static contextType = LoggingContext;
reportContent = '';

constructor(props) {
Expand Down
12 changes: 6 additions & 6 deletions apps/client/src/common/components/input/time-input/TimeInput.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { KeyboardEvent, useCallback, useContext, useEffect, useRef, useState } from 'react';
import { KeyboardEvent, useCallback, useEffect, useRef, useState } from 'react';
import { Button, Input, InputGroup, InputLeftElement, Tooltip } from '@chakra-ui/react';
import { millisToString } from 'ontime-utils';

import { EventEditorSubmitActions } from '../../../../features/event-editor/EventEditor';
import { tooltipDelayFast } from '../../../../ontimeConfig';
import { LoggingContext } from '../../../context/LoggingContext';
import { useEmitLog } from '../../../stores/logger';
import { forgivingStringToMillis } from '../../../utils/dateConfig';
import { stringFromMillis } from '../../../utils/time';
import { TimeEntryField } from '../../../utils/timesManager';

import style from './TimeInput.module.scss';
Expand All @@ -24,7 +24,7 @@ export default function TimeInput(props: TimeInputProps) {
const {
name, submitHandler, time = 0, delay = 0, placeholder, validationHandler, previousEnd = 0,
} = props;
const { emitError } = useContext(LoggingContext);
const { emitError } = useEmitLog();
const inputRef = useRef<HTMLInputElement | null>(null);
const [value, setValue] = useState('');

Expand All @@ -34,7 +34,7 @@ export default function TimeInput(props: TimeInputProps) {
const resetValue = useCallback(() => {
// Todo: check if change is necessary
try {
setValue(stringFromMillis(time + delay));
setValue(millisToString(time + delay));
} catch (error) {
emitError(`Unable to parse date: ${error}`);
}
Expand Down Expand Up @@ -97,7 +97,7 @@ export default function TimeInput(props: TimeInputProps) {
const success = handleSubmit(newValue);
if (success) {
const ms = forgivingStringToMillis(newValue);
setValue(stringFromMillis(ms + delay));
setValue(millisToString(ms + delay));
} else {
resetValue();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeEvent, useCallback, useContext, useRef, useState } from 'react';
import { ChangeEvent, useCallback, useRef, useState } from 'react';
import {
Button,
Checkbox,
Expand All @@ -21,7 +21,7 @@ import { useQueryClient } from '@tanstack/react-query';

import { RUNDOWN_TABLE } from '../../api/apiConstants';
import { uploadData } from '../../api/ontimeApi';
import { LoggingContext } from '../../context/LoggingContext';
import { useEmitLog } from '../../stores/logger';
import TooltipActionBtn from '../buttons/TooltipActionBtn';

import { validateFile } from './utils';
Expand All @@ -35,7 +35,7 @@ interface UploadModalProps {

export default function UploadModal({ onClose, isOpen }: UploadModalProps) {
const queryClient = useQueryClient();
const { emitError } = useContext(LoggingContext);
const { emitError } = useEmitLog();
const [errors, setErrors] = useState<string[]>([]);
const [file, setFile] = useState<File | null>(null);
const [progress, setProgress] = useState(0);
Expand Down
Loading