This commit is contained in:
Marks Polakovs 2020-04-13 13:22:38 +02:00
parent 7be882acbd
commit c3b0f5675b
4 changed files with 757 additions and 730 deletions

View file

@ -190,7 +190,7 @@ class Session(object):
await notify_mattserver_about_sessions() await notify_mattserver_about_sessions()
print(self.connection_id, "bye bye") print(self.connection_id, "bye bye")
self.ended = True self.ended = True
def create_peerconnection(self) -> None: def create_peerconnection(self) -> None:
self.pc = RTCPeerConnection() self.pc = RTCPeerConnection()
@ -240,6 +240,7 @@ class Session(object):
except MediaStreamError as e: except MediaStreamError as e:
print(self.connection_id, e) print(self.connection_id, e)
await self.end() await self.end()
raise e
if self.running: if self.running:
# Right, depending on the format, we may need to do some fuckery. # Right, depending on the format, we may need to do some fuckery.
# Jack expects all audio to be 32 bit floating point # Jack expects all audio to be 32 bit floating point

View file

@ -21,6 +21,7 @@ export class WebRTCStreamer extends Streamer {
} }
async start(): Promise<void> { async start(): Promise<void> {
console.log("RTCStreamer start");
this.pc = new RTCPeerConnection({ this.pc = new RTCPeerConnection({
iceServers: [ iceServers: [
{ {
@ -52,6 +53,7 @@ export class WebRTCStreamer extends Streamer {
}; };
this.stream.getAudioTracks().forEach(track => this.pc!.addTrack(track)); this.stream.getAudioTracks().forEach(track => this.pc!.addTrack(track));
console.log("PC created");
this.ws = new WebSocket(process.env.REACT_APP_WS_URL!); this.ws = new WebSocket(process.env.REACT_APP_WS_URL!);
this.ws.onopen = e => { this.ws.onopen = e => {
console.log("WS open"); console.log("WS open");
@ -62,6 +64,7 @@ export class WebRTCStreamer extends Streamer {
this.onStateChange(this.mapStateToConnectionState()); this.onStateChange(this.mapStateToConnectionState());
}; };
this.ws.addEventListener("message", this.onMessage.bind(this)); this.ws.addEventListener("message", this.onMessage.bind(this));
console.log("WS created");
} }
async stop(): Promise<void> { async stop(): Promise<void> {

View file

@ -87,6 +87,16 @@ export const changeBroadcastSetting = <K extends keyof BroadcastState>(
}; };
export const registerTimeslot = (): AppThunk => async (dispatch, getState) => { export const registerTimeslot = (): AppThunk => async (dispatch, getState) => {
if (!getState().session.userCanBroadcast) {
dispatch(
NavbarState.showAlert({
color: "warning",
content: "You are not WebStudio Trained and cannot go live.",
closure: 7000
})
);
return;
}
if (getState().broadcast.stage === "NOT_REGISTERED") { if (getState().broadcast.stage === "NOT_REGISTERED") {
var state = getState().session; var state = getState().session;
const memberid = state.currentUser?.memberid; const memberid = state.currentUser?.memberid;
@ -95,6 +105,7 @@ export const registerTimeslot = (): AppThunk => async (dispatch, getState) => {
var sourceid = getState().broadcast.sourceID; var sourceid = getState().broadcast.sourceID;
try { try {
var connID = await sendBroadcastRegister(timeslotid, memberid, sourceid); var connID = await sendBroadcastRegister(timeslotid, memberid, sourceid);
console.log(connID);
if (connID !== undefined) { if (connID !== undefined) {
dispatch(broadcastState.actions.setConnID(connID["connid"])); dispatch(broadcastState.actions.setConnID(connID["connid"]));
dispatch(startStreaming()); dispatch(startStreaming());
@ -227,19 +238,14 @@ export function sendTracklistStart(trackid: number): Promise<TrackListItem> {
} }
export const startStreaming = (): AppThunk => async (dispatch, getState) => { export const startStreaming = (): AppThunk => async (dispatch, getState) => {
if (!getState().session.userCanBroadcast) { console.log("starting streamer.");
dispatch(
NavbarState.showAlert({
color: "warning",
content: "You are not WebStudio Trained and cannot go live.",
closure: 7000
})
);
return;
}
streamer = new WebRTCStreamer(MixerState.destination.stream); streamer = new WebRTCStreamer(MixerState.destination.stream);
streamer.addConnectionStateListener(state => { streamer.addConnectionStateListener(state => {
dispatch(broadcastState.actions.setConnectionState(state)); dispatch(broadcastState.actions.setConnectionState(state));
if (state === "CONNECTION_LOST") {
// un-register if we drop, let the user manually reconnect
dispatch(broadcastState.actions.setConnID(null));
}
}); });
await streamer.start(); await streamer.start();
}; };

File diff suppressed because it is too large Load diff