This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed connection model to peer-to-peer (#25)
- Loading branch information
Showing
15 changed files
with
595 additions
and
336 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
APP_NAME=concerto | ||
PACKAGE_NAME=com.spietras.concerto | ||
SERVER_URL=http://localhost:80 | ||
THEATRE_ADDRESS=localhost:54321 | ||
GRUPPETTO_ADDRESS=localhost:3478 | ||
GRUPPETTO_USER=user | ||
GRUPPETTO_PASSWORD=password |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,50 @@ | ||
export const defaultMidiInput = "none"; | ||
export const baseMidiInputs = [{ label: "None", value: defaultMidiInput }]; | ||
import Constants from "expo-constants"; | ||
import { Nunito_700Bold, Nunito_800ExtraBold } from "@expo-google-fonts/nunito"; | ||
|
||
export const defaultInstrument = "electric_piano_1"; | ||
export const baseInstruments = [ | ||
export const fonts = { | ||
Nunito_700Bold, | ||
Nunito_800ExtraBold, | ||
}; | ||
|
||
export const config = { | ||
theatreAddress: Constants.manifest?.extra?.theatreAddress, | ||
gruppettoAddress: Constants.manifest?.extra?.gruppettoAddress, | ||
gruppettoUser: Constants.manifest?.extra?.gruppettoUser, | ||
gruppettoPassword: Constants.manifest?.extra?.gruppettoPassword, | ||
}; | ||
|
||
export const urls = { | ||
entries: `http://${config.theatreAddress}/entries`, | ||
connect: `ws://${config.theatreAddress}/connect`, | ||
}; | ||
|
||
export const iceServers = [ | ||
{ | ||
urls: "stun:stun.l.google.com:19302", | ||
}, | ||
{ | ||
label: "Electric Piano 1", | ||
value: defaultInstrument, | ||
urls: `turn:${config.gruppettoAddress}`, | ||
username: config.gruppettoUser, | ||
credential: config.gruppettoPassword, | ||
}, | ||
]; | ||
|
||
const defaultMidiInput = { | ||
value: "none", | ||
label: "None", | ||
}; | ||
|
||
export const midiInputs = { | ||
default: defaultMidiInput.value, | ||
base: [defaultMidiInput], | ||
}; | ||
|
||
const defaultInstrument = { | ||
value: "electric_piano_1", | ||
label: "Electric Piano 1", | ||
}; | ||
|
||
export const instruments = { | ||
default: defaultInstrument.value, | ||
base: [defaultInstrument], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import useCancellable from "./useCancellable"; | ||
import React from "react"; | ||
import axios from "axios"; | ||
|
||
export type FetchState = "idle" | "fetching" | "fetched" | "error"; | ||
|
||
export default function useFetch<T>(url: string) { | ||
const cache = React.useRef<Record<string, T>>({}).current; | ||
const [status, setStatus] = React.useState<FetchState>("idle"); | ||
const [data, setData] = React.useState<T>(); | ||
const [error, setError] = React.useState<any>(); | ||
|
||
useCancellable( | ||
(cancelInfo) => { | ||
if (!url) return; | ||
|
||
const controller = new AbortController(); | ||
|
||
const fetchData = async () => { | ||
if (cancelInfo.cancelled) return; | ||
|
||
setStatus("fetching"); | ||
if (cache[url]) { | ||
if (cancelInfo.cancelled) return; | ||
setData(cache[url]); | ||
setStatus("fetched"); | ||
} else { | ||
try { | ||
const response = await axios.get<T>(url, { | ||
signal: controller.signal, | ||
}); | ||
if (cancelInfo.cancelled) return; | ||
const newData = response.data; | ||
cache[url] = newData; | ||
setData(newData); | ||
setStatus("fetched"); | ||
} catch (e) { | ||
if (cancelInfo.cancelled) return; | ||
setError(e); | ||
setStatus("error"); | ||
} | ||
} | ||
}; | ||
|
||
fetchData().then(); | ||
|
||
return () => controller.abort(); | ||
}, | ||
[url] | ||
); | ||
|
||
return { | ||
status: status, | ||
data: data, | ||
error: error, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.