frontend/services/socket.js
2024-02-08 09:10:53 -05:00

23 lines
460 B
JavaScript

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();
}