Browse Source

[RN] Fix running timers in the background

Turns out React Native's timers (setTimeout / setInterval) don't run while the
app is in the background: https://github.com/facebook/react-native/issues/167

This patch replaces the global timer functions with those from the
react-native-background-timer package, which work in the background.

These timers won't magically make an application work in the background, but
they will run if an application already happens to run in the background. That's
our case while in a conference, so these timers will run, allowing XMPP pings to
be sent and the conference to stay up as long as the user desires.
j8
Saúl Ibarra Corretgé 8 years ago
parent
commit
36f5b0218d

+ 1
- 0
android/app/build.gradle View File

139
 }
139
 }
140
 
140
 
141
 dependencies {
141
 dependencies {
142
+    compile project(':react-native-background-timer')
142
     compile project(':react-native-immersive')
143
     compile project(':react-native-immersive')
143
     compile project(':react-native-keep-awake')
144
     compile project(':react-native-keep-awake')
144
     compile project(':react-native-vector-icons')
145
     compile project(':react-native-vector-icons')

+ 1
- 0
android/app/src/main/java/org/jitsi/meet/MainApplication.java View File

29
                 new com.corbt.keepawake.KCKeepAwakePackage(),
29
                 new com.corbt.keepawake.KCKeepAwakePackage(),
30
                 new com.facebook.react.shell.MainReactPackage(),
30
                 new com.facebook.react.shell.MainReactPackage(),
31
                 new com.oblador.vectoricons.VectorIconsPackage(),
31
                 new com.oblador.vectoricons.VectorIconsPackage(),
32
+                new com.ocetnik.timer.BackgroundTimerPackage(),
32
                 new com.oney.WebRTCModule.WebRTCModulePackage(),
33
                 new com.oney.WebRTCModule.WebRTCModulePackage(),
33
                 new com.rnimmersive.RNImmersivePackage(),
34
                 new com.rnimmersive.RNImmersivePackage(),
34
                 new org.jitsi.meet.audiomode.AudioModePackage()
35
                 new org.jitsi.meet.audiomode.AudioModePackage()

+ 2
- 0
android/settings.gradle View File

1
 rootProject.name = 'jitsi-meet-react'
1
 rootProject.name = 'jitsi-meet-react'
2
 
2
 
3
 include ':app'
3
 include ':app'
4
+include ':react-native-background-timer'
5
+project(':react-native-background-timer').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-background-timer/android')
4
 include ':react-native-immersive'
6
 include ':react-native-immersive'
5
 project(':react-native-immersive').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-immersive/android')
7
 project(':react-native-immersive').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-immersive/android')
6
 include ':react-native-keep-awake'
8
 include ':react-native-keep-awake'

+ 12
- 2
ios/jitsi-meet-react.xcodeproj/project.pbxproj View File

5
 	};
5
 	};
6
 	objectVersion = 46;
6
 	objectVersion = 46;
7
 	objects = {
7
 	objects = {
8
-
9
 /* Begin PBXBuildFile section */
8
 /* Begin PBXBuildFile section */
10
 		002AF788986B412780935607 /* FontAwesome.ttf in Resources */ = {isa = PBXBuildFile; fileRef = B96AF9B6FBC0453798399985 /* FontAwesome.ttf */; };
9
 		002AF788986B412780935607 /* FontAwesome.ttf in Resources */ = {isa = PBXBuildFile; fileRef = B96AF9B6FBC0453798399985 /* FontAwesome.ttf */; };
11
 		00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302AC1ABCB8CE00DB3ED1 /* libRCTActionSheet.a */; };
10
 		00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302AC1ABCB8CE00DB3ED1 /* libRCTActionSheet.a */; };
41
 		BF9643921C34FBF100B0BBDF /* libsqlite3.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = BF9643911C34FBF100B0BBDF /* libsqlite3.tbd */; };
40
 		BF9643921C34FBF100B0BBDF /* libsqlite3.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = BF9643911C34FBF100B0BBDF /* libsqlite3.tbd */; };
42
 		BF9643941C34FBF900B0BBDF /* libstdc++.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = BF9643931C34FBF900B0BBDF /* libstdc++.tbd */; };
41
 		BF9643941C34FBF900B0BBDF /* libstdc++.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = BF9643931C34FBF900B0BBDF /* libstdc++.tbd */; };
43
 		BFC745141CB829B300673F38 /* libRCTWebRTC.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BFC745131CB829A700673F38 /* libRCTWebRTC.a */; };
42
 		BFC745141CB829B300673F38 /* libRCTWebRTC.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BFC745131CB829A700673F38 /* libRCTWebRTC.a */; };
43
+		7FAD39BE09A84D6AB0ABACA8 /* libRNBackgroundTimer.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 27A0018BBB2C4FD5A4F9CE71 /* libRNBackgroundTimer.a */; };
44
 /* End PBXBuildFile section */
44
 /* End PBXBuildFile section */
45
 
45
 
46
 /* Begin PBXContainerItemProxy section */
46
 /* Begin PBXContainerItemProxy section */
297
 		BF9643911C34FBF100B0BBDF /* libsqlite3.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libsqlite3.tbd; path = usr/lib/libsqlite3.tbd; sourceTree = SDKROOT; };
297
 		BF9643911C34FBF100B0BBDF /* libsqlite3.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libsqlite3.tbd; path = usr/lib/libsqlite3.tbd; sourceTree = SDKROOT; };
298
 		BF9643931C34FBF900B0BBDF /* libstdc++.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = "libstdc++.tbd"; path = "usr/lib/libstdc++.tbd"; sourceTree = SDKROOT; };
298
 		BF9643931C34FBF900B0BBDF /* libstdc++.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = "libstdc++.tbd"; path = "usr/lib/libstdc++.tbd"; sourceTree = SDKROOT; };
299
 		BFC7450D1CB829A700673F38 /* RCTWebRTC.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTWebRTC.xcodeproj; path = "../node_modules/react-native-webrtc/ios/RCTWebRTC.xcodeproj"; sourceTree = "<group>"; };
299
 		BFC7450D1CB829A700673F38 /* RCTWebRTC.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTWebRTC.xcodeproj; path = "../node_modules/react-native-webrtc/ios/RCTWebRTC.xcodeproj"; sourceTree = "<group>"; };
300
+		0965153BB98645B4A8B6AA10 /* RNBackgroundTimer.xcodeproj */ = {isa = PBXFileReference; name = "RNBackgroundTimer.xcodeproj"; path = "../node_modules/react-native-background-timer/ios/RNBackgroundTimer.xcodeproj"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = wrapper.pb-project; explicitFileType = undefined; includeInIndex = 0; };
301
+		27A0018BBB2C4FD5A4F9CE71 /* libRNBackgroundTimer.a */ = {isa = PBXFileReference; name = "libRNBackgroundTimer.a"; path = "libRNBackgroundTimer.a"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = archive.ar; explicitFileType = undefined; includeInIndex = 0; };
300
 /* End PBXFileReference section */
302
 /* End PBXFileReference section */
301
 
303
 
302
 /* Begin PBXFrameworksBuildPhase section */
304
 /* Begin PBXFrameworksBuildPhase section */
329
 				139FDEF61B0652A700C62182 /* libRCTWebSocket.a in Frameworks */,
331
 				139FDEF61B0652A700C62182 /* libRCTWebSocket.a in Frameworks */,
330
 				3847F11906B4479A9162628F /* libRNVectorIcons.a in Frameworks */,
332
 				3847F11906B4479A9162628F /* libRNVectorIcons.a in Frameworks */,
331
 				901FE90FA5744B5B94DCDC41 /* libKCKeepAwake.a in Frameworks */,
333
 				901FE90FA5744B5B94DCDC41 /* libKCKeepAwake.a in Frameworks */,
334
+				7FAD39BE09A84D6AB0ABACA8 /* libRNBackgroundTimer.a in Frameworks */,
332
 			);
335
 			);
333
 			runOnlyForDeploymentPostprocessing = 0;
336
 			runOnlyForDeploymentPostprocessing = 0;
334
 		};
337
 		};
489
 				139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */,
492
 				139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */,
490
 				146833FF1AC3E56700842450 /* React.xcodeproj */,
493
 				146833FF1AC3E56700842450 /* React.xcodeproj */,
491
 				22418656B14845609F953A42 /* RNVectorIcons.xcodeproj */,
494
 				22418656B14845609F953A42 /* RNVectorIcons.xcodeproj */,
495
+				0965153BB98645B4A8B6AA10 /* RNBackgroundTimer.xcodeproj */,
492
 			);
496
 			);
493
 			name = Libraries;
497
 			name = Libraries;
494
 			sourceTree = "<group>";
498
 			sourceTree = "<group>";
576
 		83CBB9F71A601CBA00E9B192 /* Project object */ = {
580
 		83CBB9F71A601CBA00E9B192 /* Project object */ = {
577
 			isa = PBXProject;
581
 			isa = PBXProject;
578
 			attributes = {
582
 			attributes = {
579
-				LastUpgradeCheck = 0820;
583
+				LastUpgradeCheck = 820;
580
 				ORGANIZATIONNAME = Facebook;
584
 				ORGANIZATIONNAME = Facebook;
581
 				TargetAttributes = {
585
 				TargetAttributes = {
582
 					13B07F861A680F5B00A75B9A = {
586
 					13B07F861A680F5B00A75B9A = {
954
 					"$(SRCROOT)/../node_modules/react-native/Libraries/LinkingIOS/**",
958
 					"$(SRCROOT)/../node_modules/react-native/Libraries/LinkingIOS/**",
955
 					"$(SRCROOT)/../node_modules/react-native-keep-awake/ios",
959
 					"$(SRCROOT)/../node_modules/react-native-keep-awake/ios",
956
 					"$(SRCROOT)/../node_modules/react-native-vector-icons/RNVectorIconsManager",
960
 					"$(SRCROOT)/../node_modules/react-native-vector-icons/RNVectorIconsManager",
961
+					"$(SRCROOT)/../node_modules/react-native-background-timer/ios",
957
 				);
962
 				);
958
 				INFOPLIST_FILE = app/Info.plist;
963
 				INFOPLIST_FILE = app/Info.plist;
959
 				IPHONEOS_DEPLOYMENT_TARGET = 9.0;
964
 				IPHONEOS_DEPLOYMENT_TARGET = 9.0;
961
 				LIBRARY_SEARCH_PATHS = (
966
 				LIBRARY_SEARCH_PATHS = (
962
 					"$(inherited)",
967
 					"$(inherited)",
963
 					"$(SRCROOT)/../node_modules/react-native-webrtc/**",
968
 					"$(SRCROOT)/../node_modules/react-native-webrtc/**",
969
+					"\"$(SRCROOT)/jitsi-meet-react\"",
964
 				);
970
 				);
965
 				OTHER_LDFLAGS = (
971
 				OTHER_LDFLAGS = (
966
 					"$(inherited)",
972
 					"$(inherited)",
990
 					"$(SRCROOT)/../node_modules/react-native/Libraries/LinkingIOS/**",
996
 					"$(SRCROOT)/../node_modules/react-native/Libraries/LinkingIOS/**",
991
 					"$(SRCROOT)/../node_modules/react-native-keep-awake/ios",
997
 					"$(SRCROOT)/../node_modules/react-native-keep-awake/ios",
992
 					"$(SRCROOT)/../node_modules/react-native-vector-icons/RNVectorIconsManager",
998
 					"$(SRCROOT)/../node_modules/react-native-vector-icons/RNVectorIconsManager",
999
+					"$(SRCROOT)/../node_modules/react-native-background-timer/ios",
993
 				);
1000
 				);
994
 				INFOPLIST_FILE = app/Info.plist;
1001
 				INFOPLIST_FILE = app/Info.plist;
995
 				IPHONEOS_DEPLOYMENT_TARGET = 9.0;
1002
 				IPHONEOS_DEPLOYMENT_TARGET = 9.0;
997
 				LIBRARY_SEARCH_PATHS = (
1004
 				LIBRARY_SEARCH_PATHS = (
998
 					"$(inherited)",
1005
 					"$(inherited)",
999
 					"$(SRCROOT)/../node_modules/react-native-webrtc/**",
1006
 					"$(SRCROOT)/../node_modules/react-native-webrtc/**",
1007
+					"\"$(SRCROOT)/jitsi-meet-react\"",
1000
 				);
1008
 				);
1001
 				OTHER_LDFLAGS = (
1009
 				OTHER_LDFLAGS = (
1002
 					"$(inherited)",
1010
 					"$(inherited)",
1052
 					"$(SRCROOT)/../node_modules/react-native/React/**",
1060
 					"$(SRCROOT)/../node_modules/react-native/React/**",
1053
 					"$(SRCROOT)/../node_modules/react-native-keep-awake/ios",
1061
 					"$(SRCROOT)/../node_modules/react-native-keep-awake/ios",
1054
 					"$(SRCROOT)/../node_modules/react-native-vector-icons/RNVectorIconsManager",
1062
 					"$(SRCROOT)/../node_modules/react-native-vector-icons/RNVectorIconsManager",
1063
+					"$(SRCROOT)/../node_modules/react-native-background-timer/ios",
1055
 				);
1064
 				);
1056
 				IPHONEOS_DEPLOYMENT_TARGET = 8.0;
1065
 				IPHONEOS_DEPLOYMENT_TARGET = 8.0;
1057
 				MTL_ENABLE_DEBUG_INFO = YES;
1066
 				MTL_ENABLE_DEBUG_INFO = YES;
1097
 					"$(SRCROOT)/../node_modules/react-native/React/**",
1106
 					"$(SRCROOT)/../node_modules/react-native/React/**",
1098
 					"$(SRCROOT)/../node_modules/react-native-keep-awake/ios",
1107
 					"$(SRCROOT)/../node_modules/react-native-keep-awake/ios",
1099
 					"$(SRCROOT)/../node_modules/react-native-vector-icons/RNVectorIconsManager",
1108
 					"$(SRCROOT)/../node_modules/react-native-vector-icons/RNVectorIconsManager",
1109
+					"$(SRCROOT)/../node_modules/react-native-background-timer/ios",
1100
 				);
1110
 				);
1101
 				IPHONEOS_DEPLOYMENT_TARGET = 8.0;
1111
 				IPHONEOS_DEPLOYMENT_TARGET = 8.0;
1102
 				MTL_ENABLE_DEBUG_INFO = NO;
1112
 				MTL_ENABLE_DEBUG_INFO = NO;

+ 1
- 0
package.json View File

35
     "react": "15.4.2",
35
     "react": "15.4.2",
36
     "react-dom": "15.4.2",
36
     "react-dom": "15.4.2",
37
     "react-native": "0.41.2",
37
     "react-native": "0.41.2",
38
+    "react-native-background-timer": "^1.0.0",
38
     "react-native-immersive": "0.0.4",
39
     "react-native-immersive": "0.0.4",
39
     "react-native-keep-awake": "^2.0.2",
40
     "react-native-keep-awake": "^2.0.2",
40
     "react-native-prompt": "^1.0.0",
41
     "react-native-prompt": "^1.0.0",

+ 16
- 0
react/features/base/lib-jitsi-meet/native/polyfills-browser.js View File

1
+import BackgroundTimer from 'react-native-background-timer';
2
+
1
 /**
3
 /**
2
  * Gets the first common prototype of two specified Objects (treating the
4
  * Gets the first common prototype of two specified Objects (treating the
3
  * objects themselves as prototypes as well).
5
  * objects themselves as prototypes as well).
313
         }
315
         }
314
     }
316
     }
315
 
317
 
318
+    // Timers
319
+    //
320
+    // React Native's timers won't run while the app is in the background,
321
+    // this is a known limitation. Replace them with a background-friendly
322
+    // alternative.
323
+    //
324
+    // Required by:
325
+    // - lib-jitsi-meet
326
+    // - Strophe
327
+    global.setTimeout = window.setTimeout = BackgroundTimer.setTimeout;
328
+    global.clearTimeout = window.clearTimeout = BackgroundTimer.clearTimeout;
329
+    global.setInterval = window.setInterval = BackgroundTimer.setInterval;
330
+    global.clearInterval = window.clearInterval = BackgroundTimer.clearInterval;
331
+
316
 })(global || window || this); // eslint-disable-line no-invalid-this
332
 })(global || window || this); // eslint-disable-line no-invalid-this

Loading…
Cancel
Save