refract: playback api

This commit is contained in:
cv
2021-04-10 11:38:32 +02:00
parent d289a5b918
commit e2561bcd54
2 changed files with 40 additions and 14 deletions
+27
View File
@@ -0,0 +1,27 @@
import { serverURL } from './apiConstants';
const playbackURL = serverURL + 'playback/';
export const getStart = async () => {
const res = await fetch(playbackURL + 'start');
return res;
};
export const getPause = async () => {
const res = await fetch(playbackURL + 'pause');
return res;
};
export const getRoll = async () => {
const res = await fetch(playbackURL + 'roll');
return res;
};
export const getPrevious = async () => {
const res = await fetch(playbackURL + 'previous');
return res;
};
export const getNext = async () => {
const res = await fetch(playbackURL + 'next');
return res;
};
+13 -14
View File
@@ -12,6 +12,14 @@ import { format } from 'date-fns';
import { timeFormatSeconds } from '../../common/dateConfig'; import { timeFormatSeconds } from '../../common/dateConfig';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { io } from 'socket.io-client'; import { io } from 'socket.io-client';
import { serverURL } from '../../app/api/apiConstants';
import {
getStart,
getPause,
getRoll,
getPrevious,
getNext,
} from '../../app/api/playbackApi';
// BUTTON DEFINITION // BUTTON DEFINITION
const defProps = { const defProps = {
@@ -33,9 +41,6 @@ export default function PlaybackControl(props) {
const updateTimer = (vals) => { const updateTimer = (vals) => {
setTimer({ ...timer, ...vals }); setTimer({ ...timer, ...vals });
}; };
// TODO: Move to config file
const serverURL = 'http://localhost:4001/';
const playbackURL = serverURL + 'playback/';
// WEBSOCKETZ // WEBSOCKETZ
useEffect(() => { useEffect(() => {
@@ -54,29 +59,23 @@ export default function PlaybackControl(props) {
const playbackControl = async (action, payload) => { const playbackControl = async (action, payload) => {
switch (action) { switch (action) {
case 'start': { case 'start': {
await fetch(playbackURL + 'start').then( await getStart().then((res) => res.ok && setPlayback('start'));
(res) => res.ok && setPlayback('start')
);
break; break;
} }
case 'pause': { case 'pause': {
await fetch(playbackURL + 'pause').then( await getPause().then((res) => res.ok && setPlayback('pause'));
(res) => res.ok && setPlayback('pause')
);
break; break;
} }
case 'roll': { case 'roll': {
await fetch(playbackURL + 'roll').then( await getRoll().then((res) => res.ok && setPlayback('roll'));
(res) => res.ok && setPlayback('roll')
);
break; break;
} }
case 'previous': { case 'previous': {
await fetch(playbackURL + 'previous').then((res) => console.log(res)); await getPrevious().then((res) => console.log(res));
break; break;
} }
case 'next': { case 'next': {
await fetch(playbackURL + 'next').then((res) => console.log(res)); await getNext().then((res) => console.log(res));
break; break;
} }
default: default: