-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheadless.js
More file actions
60 lines (46 loc) · 1.85 KB
/
Copy pathheadless.js
File metadata and controls
60 lines (46 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// import * as clipboard from 'expo-clipboard';
import io from 'socket.io-client';
import { SERVER_URL } from './assets/constants';
import { AppState } from 'react-native';
//local imports
import Clipsync from './clipboardModule';
//create a socket connection
const socket = io.connect(SERVER_URL);
const MyHeadlessTask = async () => {
if (AppState.currentState === 'background') {
console.log('[background] App is Background!');
if (!socket.connected) {
socket.io.on('ping', () => {
console.log('[background] socket is working and receiving packets of data!');
});
socket.io.on('error', (error) => {
console.log('[background] Error in socket connection: ', error);
socket.connect();
});
socket.on('connect', () => {
console.log('[background] successfully connected to socket!');
});
await socket.connect();
}
// clipboard event listener
Clipsync.getClipboardContent(
(content) => {
console.log('Clipboard content:', content);
},
(error) => {
console.error('Error getting clipboard content:', error);
}
);
// console.log("text in clipboard :", text)
// // Stringify the text before storing it in AsyncStorage
// const stringifiedText = JSON.stringify(text);
// const storedClipboard = await AsyncStorage.getItem('clipboard');
// if (stringifiedText !== storedClipboard) {
// // Clipboard has changed
// console.log('Clipboard changed: ', text);
// // Save the new clipboard content as a string
// await AsyncStorage.setItem('clipboard', stringifiedText);
// }
}
};
export default MyHeadlessTask;