Skip to content
This repository was archived by the owner on Feb 7, 2022. It is now read-only.

Commit 91bee17

Browse files
Merge develop into dev-deploy
2 parents 28aa2d7 + d795911 commit 91bee17

File tree

3 files changed

+32
-25
lines changed

3 files changed

+32
-25
lines changed

src/components/HostPlayer/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ class HostPlayer extends React.Component {
185185
<div className="flexContainer">
186186
<Player isHost />
187187
<div className={`${styles.textWrapper} textAlignCenter`}>
188-
<h2>Hosting to {this.state.connections} listeners.</h2>
188+
<h2>Hosting {SessionManager.SessionCount.get()} listeners.</h2>
189189
<p className="textAlignLeft">
190190
You can continue using Spotify as you normally would. The music is
191191
playing through this browser tab, you can open this tab in a new

src/components/ListenerPlayer/index.jsx

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,12 @@ class ListenerPlayer extends React.Component {
9292
Math.abs(calcPos - data.position) > 2000)
9393
) {
9494
// console.log("not synced");
95-
this.setState({
96-
synced: false,
97-
}, () => this.syncListener(hostUri, calcPos, hostPlaying, true));
95+
this.setState(
96+
{
97+
synced: false,
98+
},
99+
() => this.syncListener(hostUri, calcPos, hostPlaying)
100+
);
98101
} else {
99102
// console.log("synced");
100103
this.setState({
@@ -224,36 +227,33 @@ class ListenerPlayer extends React.Component {
224227
* @param {string} uri spotify track uri
225228
* @param {number} position position in milliseconds
226229
* @param {boolean} playing playing state
227-
* @param {boolean} force whether to force playing
228230
*/
229-
async syncListener(uri, position, playing, force) {
231+
async syncListener(uri, position, playing) {
230232
if (uri !== playerStore.uri) {
231233
await playerStore.newTrack(uri, position);
232234
console.log(playing, position, playerStore.position.value);
233235
// defer setting play/pause till after update
234-
this.setState(
235-
{
236-
changeSongCallback: () => {
237-
if (
238-
playing &&
239-
position > playerStore.position &&
240-
playerStore.position > 0
241-
) {
242-
// if host plays and listener was listening when host paused, then resume and seek. if force then play on force.
243-
playerStore.resume(this.state.parked);
244-
} else if (!playing) {
245-
// if host pauses, pause
246-
playerStore.pause(this.parked);
247-
}
248-
},
249-
}
250-
);
236+
this.setState({
237+
changeSongCallback: () => {
238+
if (
239+
playing &&
240+
position > playerStore.position &&
241+
playerStore.position > 0
242+
) {
243+
// if host plays and listener was listening when host paused, then resume and seek. if force then play on force.
244+
playerStore.resume(this.state.parked);
245+
} else if (!playing) {
246+
// if host pauses, pause
247+
playerStore.pause(this.parked);
248+
}
249+
},
250+
});
251251
} else {
252252
await playerStore.seek(position);
253253
// defer setting play/pause till after update
254254
this.setState({
255255
changeSongCallback: () => {
256-
if (playing || force) {
256+
if (playing) {
257257
// if host plays and listener was listening when host paused, then resume and seek. if force then play on force.
258258
playerStore.resume(this.state.parked);
259259
} else if (!playing) {

src/utils/sessionManager.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import axios from "axios";
22
import urlJoin from "url-join";
3+
import { observable } from "mobx";
34

45
import * as firebase from "firebase/app";
56
import "firebase/auth";
@@ -48,6 +49,11 @@ function initializeApp() {
4849
}
4950
}
5051

52+
/**
53+
* Listener count observable
54+
*/
55+
export const SessionCount = observable.box(0);
56+
5157
/**
5258
* Refresh session token and stick it in localStorage
5359
*/
@@ -129,7 +135,7 @@ export const publishUpdate = async (uri, position, playing, retries = 0) => {
129135
try {
130136
let user = await FBAuth.signInAnonymously();
131137
console.log("publishUpdate", uri, position, playing);
132-
await axios.post(
138+
let res = await axios.post(
133139
cloudFunctions.postUpdate,
134140
{
135141
uri,
@@ -145,6 +151,7 @@ export const publishUpdate = async (uri, position, playing, retries = 0) => {
145151
},
146152
}
147153
);
154+
SessionCount.set(res.data.subscribers);
148155
} catch (e) {
149156
if (e.response) {
150157
if (e.response.status === 401) {

0 commit comments

Comments
 (0)