Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
Update sockets for new server (#132)
Browse files Browse the repository at this point in the history
* Remove user status global client side handling

* Update for new server changes

* Revert URLs
  • Loading branch information
celian-rib authored Jul 18, 2022
1 parent 718b004 commit 400e569
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/components/DropyMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import MapLoadingOverlay from './overlays/MapLoadingOverlay';
import Sonar from './Sonar';
import DropyMapMarker from './DropyMapMarker';

const DropyMap = ({ dropiesAround, retreiveDropy }) => {
const DropyMap = ({ dropiesAround, retrieveDropy }) => {

const navigation = useNavigation();

Expand All @@ -34,7 +34,7 @@ const DropyMap = ({ dropiesAround, retreiveDropy }) => {
if (userCoordinates == null) return;
if (dropy?.isUserDropy) return;

const response = await retreiveDropy(dropy.id);
const response = await retrieveDropy(dropy.id);
if(response.error != null) {
throw response.error;
}
Expand Down
5 changes: 4 additions & 1 deletion src/hooks/useChatSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ const useChatSocket = (conversationId) => {
});

return () => {
Socket.chatSocket.emit('leave_conversation', conversationId);
Socket.chatSocket.emit('leave_conversation', conversationId, (response) => {
if(response.error != null)
console.error('Error leaving conversation', response.error);
});

Socket.chatSocket.off('connect');
Socket.chatSocket.off('message_sent');
Expand Down
14 changes: 8 additions & 6 deletions src/hooks/useDropiesAroundSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const useDropiesAroundSocket = () => {

useEffect(() => {
if (Socket.dropySocket == null) return;

updateAllDropiesAround();
Socket.dropySocket.on('connect', updateAllDropiesAround);

Expand All @@ -26,9 +27,9 @@ const useDropiesAroundSocket = () => {
setDropiesAround(olds => [...olds, response.data]);
});

Socket.dropySocket.on('dropy_retreived', (response) => {
Socket.dropySocket.on('dropy_retrieved', (response) => {
if (response.error != null) {
console.error('Error getting retreived dropy', response.error);
console.error('Error getting retrieved dropy', response.error);
return;
}

Expand All @@ -38,13 +39,14 @@ const useDropiesAroundSocket = () => {
return () => {
Socket.dropySocket.off('connect');
Socket.dropySocket.off('dropy_created');
Socket.dropySocket.off('dropy_retreived');
Socket.dropySocket.off('dropy_retrieved');
};
}, []);

const updateAllDropiesAround = () => {
if (Socket.dropySocket == null) return;
if (Socket.dropySocket.connected === false) return;

Socket.dropySocket.emit('all_dropies_around', (response) => {
if(response.error != null) {
console.error('Error getting dropies around', response.error);
Expand All @@ -64,13 +66,13 @@ const useDropiesAroundSocket = () => {
});
};

const retreiveDropy = (dropyId) => {
const retrieveDropy = (dropyId) => {
return new Promise((resolve) => {
Socket.dropySocket.emit('dropy_retreived', { dropyId }, resolve);
Socket.dropySocket.emit('dropy_retrieved', { dropyId }, resolve);
});
};

return { dropiesAround, createDropy, retreiveDropy };
return { dropiesAround, createDropy, retrieveDropy };
};

export default useDropiesAroundSocket;
4 changes: 2 additions & 2 deletions src/screens/HomeScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const HomeScreen = ({ navigation, route }) => {
const { dropyCreateParams = null } = route.params || {};

const [confirmDropOverlayVisible, setConfirmDropOverlayVisible] = useState(false);
const { dropiesAround, createDropy, retreiveDropy } = useDropiesAroundSocket();
const { dropiesAround, createDropy, retrieveDropy } = useDropiesAroundSocket();

useEffect(() => {
if(dropyCreateParams != null) {
Expand All @@ -30,7 +30,7 @@ const HomeScreen = ({ navigation, route }) => {
return (
<View style={styles.container}>
<StatusBar barStyle='dark-content' />
<DropyMap dropiesAround={dropiesAround} retreiveDropy={retreiveDropy} />
<DropyMap dropiesAround={dropiesAround} retrieveDropy={retrieveDropy} />
<SafeAreaView style={styles.avatarContainer}>
<TouchableOpacity onPress={() => navigation.navigate('Profile')}>
<ProfileAvatar
Expand Down
14 changes: 0 additions & 14 deletions src/states/SocketContextProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,14 @@ const SocketProvider = ({ children }) => {

Socket.initSockets();

handleUserStatus();

log('Sockets initilized');

return () => {
Socket.chatSocket?.emit('user_status', false);

Socket.destroySockets();
log('Sockets destroyed');
};
}, [user]);

const handleUserStatus = () => {
if(Socket.chatSocket == null) return;

Socket.chatSocket.emit('user_status', true);

Socket.chatSocket.on('request_status', () => {
Socket.chatSocket.emit('user_status', true);
});
};

useEffect(() => {
const appStateListener = AppState.addEventListener('change', (nextAppState) => {
if (nextAppState === 'active') {
Expand Down

0 comments on commit 400e569

Please sign in to comment.