23 lines
460 B
JavaScript
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();
|
||
|
}
|