Last active
October 7, 2021 22:11
-
-
Save wedgemartin/6c2c2d4c6471ac77ecbe691dcbf6bb42 to your computer and use it in GitHub Desktop.
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
const App: () => React$Node = (props) => { | |
const [ players, setPlayers ] = useState([]); | |
useEffect(() => { | |
AsyncStorage.getItem('@maddness_user').then((userData) => { | |
getNearbyPlayers(); | |
performStompConnect(); | |
} | |
}); | |
}, []); | |
const getNearbyPlayers = () => { | |
fetch(`${url}/v1/users`).then((data) => data.json()).then((json) => { | |
if (json) { | |
if (json && json['users']) { | |
setPlayers(json['users']); | |
} | |
} | |
}).catch(e => { | |
console.log(e); | |
}); | |
} | |
const performStompConnect = (user) => { | |
client.onConnect = (frame) => { | |
console.log('STOMP: Got connect: ' + JSON.stringify(frame)); | |
let stompTopics = [ `/exchange/users/${user['username']}`, '/exchange/global/global' ]; | |
for (let i = 0; i < stompTopics.length; i++) { | |
client.subscribe(stompTopics[i], function(message) { handleMessage(message, user) }); | |
} | |
}; | |
} | |
const handleMessage = (msg, user) => { | |
// >>> 'players' here is EMPTY.. even though in the render prior to this I saw that it had 4 players << | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment