inital
This commit is contained in:
22
services/socket.js
Normal file
22
services/socket.js
Normal file
@@ -0,0 +1,22 @@
|
||||
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();
|
||||
}
|
||||
Reference in New Issue
Block a user