-
-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Relocating stream checkbox to Outputs panel
- Making it easier to switch current device streaming on/off - Refactor `Stream` to functional component
- Loading branch information
Showing
6 changed files
with
76 additions
and
96 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
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,85 +1,43 @@ | ||
import React from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { bindActionCreators } from 'redux'; | ||
import * as coreActions from '../services/core/actions'; | ||
import { useEffect, useState } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { SnapStream } from './SnapStream.tsx'; | ||
|
||
class Stream extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
if (props.enabled && props.streaming_enabled) { | ||
this.start(); | ||
} | ||
} | ||
|
||
start = () => { | ||
const { | ||
host, | ||
port, | ||
ssl, | ||
} = this.props; | ||
const Stream = () => { | ||
const [stream, setStream] = useState(null); | ||
const { | ||
enabled, | ||
streaming_enabled, | ||
host, | ||
port, | ||
ssl, | ||
} = useSelector((state) => state?.snapcast || {}); | ||
|
||
if (this.snapstream) { | ||
this.snapstream.play(); | ||
const start = () => { | ||
if (stream) { | ||
stream.play(); | ||
} else { | ||
const baseUrl = `${ssl ? 'wss' : 'ws'}://${host}:${port}`; | ||
this.snapstream = new SnapStream(baseUrl); | ||
} | ||
} | ||
|
||
stop = () => { | ||
if (this.snapstream) { | ||
this.snapstream.stop(); | ||
this.snapstream = null; | ||
setStream(new SnapStream(`${ssl ? 'wss' : 'ws'}://${host}:${port}`)); | ||
} | ||
} | ||
|
||
componentDidUpdate = ({ | ||
streaming_enabled: prevStreamingEnabled, | ||
}) => { | ||
const { | ||
enabled, | ||
streaming_enabled, | ||
} = this.props; | ||
|
||
if (!prevStreamingEnabled && enabled && streaming_enabled) { | ||
this.start(); | ||
} | ||
if (!enabled || !streaming_enabled) { | ||
this.stop(); | ||
const stop = () => { | ||
if (stream) { | ||
stream.stop(); | ||
setStream(null); | ||
} | ||
} | ||
|
||
render = () => null; | ||
useEffect( | ||
() => { | ||
if (enabled && streaming_enabled) { | ||
start(); | ||
} else { | ||
stop(); | ||
} | ||
}, [enabled, streaming_enabled], | ||
); | ||
|
||
return null; | ||
} | ||
|
||
const mapStateToProps = (state) => { | ||
const { | ||
snapcast: { | ||
enabled, | ||
streaming_enabled, | ||
host, | ||
port, | ||
ssl, | ||
}, | ||
pusher: { | ||
username, | ||
}, | ||
} = state; | ||
|
||
return { | ||
enabled, | ||
streaming_enabled, | ||
host, | ||
port, | ||
ssl, | ||
username, | ||
}; | ||
}; | ||
|
||
const mapDispatchToProps = (dispatch) => ({ | ||
coreActions: bindActionCreators(coreActions, dispatch), | ||
}); | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(Stream); | ||
export default Stream; |
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