Skip to content

Commit 95f5917

Browse files
committed
Use configurable BAPSicle server info.
1 parent 3895ea2 commit 95f5917

File tree

8 files changed

+55
-32
lines changed

8 files changed

+55
-32
lines changed

.env.baps-development

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
HTTPS=false
2+
HOST=localhost
3+
REACT_APP_BAPSICLE_INTERFACE=true
4+
# Fill the below if using custom BAPSicle server settings
5+
#REACT_APP_BAPSICLE_PROTOCOL=https
6+
#REACT_APP_BAPSICLE_HOST=localhost
7+
REACT_APP_BAPSICLE_PORT=13500
8+
#REACT_APP_WEBSOCKET_PORT=13501
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
HTTPS=false
21
REACT_APP_BAPSICLE_INTERFACE=true
3-
HOST=localhost

scripts/build.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ process.env.NODE_ENV = "production";
77
// If we want BAPS, specify it as the first command line argument.
88
var args = process.argv.slice(2); // Remove node start.js
99
if (args.length > 0 && args[0] === "baps") {
10-
process.env.NODE_ENV = "baps";
10+
process.env.NODE_ENV = "baps-production";
1111
}
1212

1313
// Makes the script crash on unhandled rejections instead of silently

scripts/start.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ process.env.NODE_ENV = "development";
77
// If we want BAPS, specify it as the first command line argument.
88
var args = process.argv.slice(2); // Remove node start.js
99
if (args.length > 0 && args[0] === "baps") {
10-
process.env.NODE_ENV = "baps";
10+
process.env.NODE_ENV = "baps-development";
1111
}
1212

1313
// Makes the script crash on unhandled rejections instead of silently

src/api.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,13 @@ export async function bapsicleApiRequest(
6060
method: "GET" | "POST" | "PUT",
6161
params: any
6262
): Promise<any> {
63-
const res = await apiRequest(
64-
"http://" + window.location.hostname + ":13500" + endpoint,
65-
method,
66-
params
67-
);
63+
let server = store.getState().bapsSession.currentServer;
64+
65+
if (!server) {
66+
throw new Error("Trying to call BAPSicle server without connection.");
67+
}
68+
const url = `${server.ui_protocol}://${server.hostname}:${server.ui_port}${endpoint}`;
69+
const res = await apiRequest(url, method, params);
6870
const json = await res.json();
6971
return json;
7072
}

src/bapsiclesession/state.ts

+19-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import { connectBAPSicle } from "../bapsicle";
55

66
interface bapsServer {
77
hostname: String | null;
8-
port: Number | null;
8+
ui_port: Number | null;
9+
ui_protocol: String | null;
10+
ws_port: Number | null;
911
name: String | null;
1012
}
1113

@@ -52,12 +54,24 @@ export const getCurrentServer = (): AppThunk => async (dispatch, getState) => {
5254
};
5355

5456
export const getServer = (): AppThunk => async (dispatch) => {
55-
// TODO Server Details Configurable
57+
// Since BAPS Presenter is served by the BAPSicle web server, use the current window path unless custom defined.
5658
let bapsServer: bapsServer = {
57-
hostname: window.location.hostname,
58-
port: 13501,
59+
hostname: process.env.REACT_APP_BAPSICLE_HOST
60+
? process.env.REACT_APP_BAPSICLE_HOST
61+
: window.location.hostname,
62+
ws_port: process.env.REACT_APP_WEBSOCKET_PORT
63+
? parseInt(process.env.REACT_APP_WEBSOCKET_PORT)
64+
: 13501,
65+
ui_protocol: process.env.REACT_APP_BAPSICLE_PROTOCOL
66+
? process.env.REACT_APP_BAPSICLE_PROTOCOL
67+
: "http",
68+
ui_port: process.env.REACT_APP_BAPSICLE_PORT
69+
? parseInt(process.env.REACT_APP_BAPSICLE_PORT)
70+
: parseInt(window.location.port),
5971
name: "Connecting...",
6072
};
6173
dispatch(sessionState.actions.setCurrentServer({ server: bapsServer }));
62-
dispatch(connectBAPSicle("ws://" + window.location.hostname + ":13501"));
74+
dispatch(
75+
connectBAPSicle("ws://" + bapsServer.hostname + ":" + bapsServer.ws_port)
76+
);
6377
};

src/mixer/state.ts

+19-17
Original file line numberDiff line numberDiff line change
@@ -475,31 +475,33 @@ export const load = (
475475

476476
let url;
477477

478+
if (process.env.REACT_APP_BAPSICLE_INTERFACE) {
479+
let server = getState().bapsSession.currentServer;
480+
481+
if (!server) {
482+
throw new Error(
483+
"Trying to load audio file without BAPSicle server connection."
484+
);
485+
}
486+
// If bapsicle, override the Myradio.
487+
url = `${server.ui_protocol}://${server.hostname}:${server.ui_port}`;
488+
} else {
489+
url = MYRADIO_NON_API_BASE;
490+
}
491+
478492
if (item.type === "central") {
479493
// track
480494

481495
if (process.env.REACT_APP_BAPSICLE_INTERFACE) {
482-
url =
483-
"http://" +
484-
getState().bapsSession.currentServer?.hostname +
485-
":13500/audiofile/track/" +
486-
item.trackid;
496+
url += "/audiofile/track/" + item.trackid;
487497
} else {
488-
url =
489-
MYRADIO_NON_API_BASE + "/NIPSWeb/secure_play?trackid=" + item.trackid;
498+
url += "/NIPSWeb/secure_play?trackid=" + item.trackid;
490499
}
491500
} else if ("managedid" in item) {
492501
if (process.env.REACT_APP_BAPSICLE_INTERFACE) {
493-
url =
494-
"http://" +
495-
getState().bapsSession.currentServer?.hostname +
496-
":13500/audiofile/managed/" +
497-
item.managedid;
502+
url += "/audiofile/managed/" + item.managedid;
498503
} else {
499-
url =
500-
MYRADIO_NON_API_BASE +
501-
"/NIPSWeb/managed_play?managedid=" +
502-
item.managedid;
504+
url += "/NIPSWeb/managed_play?managedid=" + item.managedid;
503505
}
504506
} else {
505507
throw new Error(
@@ -511,7 +513,7 @@ export const load = (
511513

512514
let waveform = document.getElementById("waveform-" + player.toString());
513515
if (waveform == null) {
514-
throw new Error();
516+
throw new Error("No waveform element found for player.");
515517
}
516518
audioEngine.destroyPlayerIfExists(player); // clear previous (ghost) wavesurfer and it's media elements.
517519
// wavesurfer also sets the background white, remove for progress bar to work.

src/showplanner/state.ts

-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ const showplan = createSlice({
102102
action: PayloadAction<{ channel: Number; planItems: PlanItem[] }>
103103
) {
104104
// This is used for BAPSicle only to read in individual channels of show plan into the show state from the server.
105-
// TODO: Does this need to be this complicated?
106105
var newItems = state.plan?.filter(
107106
(item) => item.channel !== action.payload.channel
108107
);

0 commit comments

Comments
 (0)