frontend/services/socket.js

23 lines
460 B
JavaScript
Raw Normal View History

2024-02-08 14:10:53 +00:00
import io from 'socket.io-client';
import {Toast} from 'react-native-toast-message'
let socket;
export const connectSocket = (userId) => {
socket = io('http://localhost:1989', {
query: { userId },
transports: ['websocket']
});
socket.on('notification', (notification) => {
Toast.show({
type: 'info',
text1: notification.message,
});
});
}
export const disconnectSocket = () => {
if (socket) socket.disconnect();
}