Explorar el Código

[RN] Keep device screen on while in a conference

j8
Saúl Ibarra Corretgé hace 8 años
padre
commit
acbfe5cb09

+ 1
- 0
android/app/build.gradle Ver fichero

@@ -153,6 +153,7 @@ repositories {
153 153
     maven { url 'https://maven.fabric.io/public' }
154 154
 }
155 155
 dependencies {
156
+    compile project(':react-native-keep-awake')
156 157
     compile project(':react-native-vector-icons')
157 158
     compile project(':react-native-webrtc')
158 159
     compile fileTree(dir: 'libs', include: ['*.jar'])

+ 1
- 0
android/app/src/main/java/org/jitsi/meet/MainApplication.java Ver fichero

@@ -28,6 +28,7 @@ public class MainApplication extends Application implements ReactApplication {
28 28
         @Override
29 29
         protected List<ReactPackage> getPackages() {
30 30
             return Arrays.<ReactPackage>asList(
31
+                new com.corbt.keepawake.KCKeepAwakePackage(),
31 32
                 new com.facebook.react.shell.MainReactPackage(),
32 33
                 new com.oblador.vectoricons.VectorIconsPackage(),
33 34
                 new com.oney.WebRTCModule.WebRTCModulePackage()

+ 2
- 0
android/settings.gradle Ver fichero

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

+ 35
- 0
ios/jitsi-meet-react.xcodeproj/project.pbxproj Ver fichero

@@ -24,6 +24,7 @@
24 24
 		2602576C1D0A7703001E3363 /* jitsi.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 2602576B1D0A7703001E3363 /* jitsi.ttf */; };
25 25
 		3847F11906B4479A9162628F /* libRNVectorIcons.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 821D8ABD506944B4BDBB069B /* libRNVectorIcons.a */; };
26 26
 		832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 832341B51AAA6A8300B99B32 /* libRCTText.a */; };
27
+		901FE90FA5744B5B94DCDC41 /* libKCKeepAwake.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 0EA8C046B2BF46279796F07D /* libKCKeepAwake.a */; };
27 28
 		B30EF2311DC0ED7C00690F45 /* WebRTC.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B30EF2301DC0ED7C00690F45 /* WebRTC.framework */; };
28 29
 		B30EF2331DC0EEA500690F45 /* WebRTC.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = B30EF2301DC0ED7C00690F45 /* WebRTC.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
29 30
 		B3A9D0251E0481E10009343D /* POSIX.m in Sources */ = {isa = PBXBuildFile; fileRef = B3A9D0241E0481E10009343D /* POSIX.m */; };
@@ -76,6 +77,13 @@
76 77
 			remoteGlobalIDString = 832C81801AAF6DEF007FA2F7;
77 78
 			remoteInfo = RCTVibration;
78 79
 		};
80
+		0B8752851E26E54A004C5CAB /* PBXContainerItemProxy */ = {
81
+			isa = PBXContainerItemProxy;
82
+			containerPortal = 5B09C20C78C74A548AAAC1FA /* KCKeepAwake.xcodeproj */;
83
+			proxyType = 2;
84
+			remoteGlobalIDString = 134814201AA4EA6300B7C361;
85
+			remoteInfo = KCKeepAwake;
86
+		};
79 87
 		139105C01AF99BAD00B5F7CC /* PBXContainerItemProxy */ = {
80 88
 			isa = PBXContainerItemProxy;
81 89
 			containerPortal = 139105B61AF99BAD00B5F7CC /* RCTSettings.xcodeproj */;
@@ -197,6 +205,7 @@
197 205
 		00C302BB1ABCB91800DB3ED1 /* RCTImage.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTImage.xcodeproj; path = "../node_modules/react-native/Libraries/Image/RCTImage.xcodeproj"; sourceTree = "<group>"; };
198 206
 		00C302D31ABCB9D200DB3ED1 /* RCTNetwork.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTNetwork.xcodeproj; path = "../node_modules/react-native/Libraries/Network/RCTNetwork.xcodeproj"; sourceTree = "<group>"; };
199 207
 		00C302DF1ABCB9EE00DB3ED1 /* RCTVibration.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTVibration.xcodeproj; path = "../node_modules/react-native/Libraries/Vibration/RCTVibration.xcodeproj"; sourceTree = "<group>"; };
208
+		0EA8C046B2BF46279796F07D /* libKCKeepAwake.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libKCKeepAwake.a; sourceTree = "<group>"; };
200 209
 		139105B61AF99BAD00B5F7CC /* RCTSettings.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTSettings.xcodeproj; path = "../node_modules/react-native/Libraries/Settings/RCTSettings.xcodeproj"; sourceTree = "<group>"; };
201 210
 		139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTWebSocket.xcodeproj; path = "../node_modules/react-native/Libraries/WebSocket/RCTWebSocket.xcodeproj"; sourceTree = "<group>"; };
202 211
 		13B07F961A680F5B00A75B9A /* jitsi-meet-react.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "jitsi-meet-react.app"; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -209,6 +218,7 @@
209 218
 		146833FF1AC3E56700842450 /* React.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = React.xcodeproj; path = "../node_modules/react-native/React/React.xcodeproj"; sourceTree = "<group>"; };
210 219
 		22418656B14845609F953A42 /* RNVectorIcons.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = RNVectorIcons.xcodeproj; path = "../node_modules/react-native-vector-icons/RNVectorIcons.xcodeproj"; sourceTree = "<group>"; };
211 220
 		2602576B1D0A7703001E3363 /* jitsi.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; name = jitsi.ttf; path = ../android/app/src/main/assets/fonts/jitsi.ttf; sourceTree = "<group>"; };
221
+		5B09C20C78C74A548AAAC1FA /* KCKeepAwake.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = KCKeepAwake.xcodeproj; path = "../node_modules/react-native-keep-awake/ios/KCKeepAwake.xcodeproj"; sourceTree = "<group>"; };
212 222
 		78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = "../node_modules/react-native/Libraries/LinkingIOS/RCTLinking.xcodeproj"; sourceTree = "<group>"; };
213 223
 		821D8ABD506944B4BDBB069B /* libRNVectorIcons.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libRNVectorIcons.a; sourceTree = "<group>"; };
214 224
 		832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = "../node_modules/react-native/Libraries/Text/RCTText.xcodeproj"; sourceTree = "<group>"; };
@@ -258,6 +268,7 @@
258 268
 				BFC745141CB829B300673F38 /* libRCTWebRTC.a in Frameworks */,
259 269
 				139FDEF61B0652A700C62182 /* libRCTWebSocket.a in Frameworks */,
260 270
 				3847F11906B4479A9162628F /* libRNVectorIcons.a in Frameworks */,
271
+				901FE90FA5744B5B94DCDC41 /* libKCKeepAwake.a in Frameworks */,
261 272
 			);
262 273
 			runOnlyForDeploymentPostprocessing = 0;
263 274
 		};
@@ -306,6 +317,14 @@
306 317
 			name = Products;
307 318
 			sourceTree = "<group>";
308 319
 		};
320
+		0B8752821E26E54A004C5CAB /* Products */ = {
321
+			isa = PBXGroup;
322
+			children = (
323
+				0B8752861E26E54A004C5CAB /* libKCKeepAwake.a */,
324
+			);
325
+			name = Products;
326
+			sourceTree = "<group>";
327
+		};
309 328
 		139105B71AF99BAD00B5F7CC /* Products */ = {
310 329
 			isa = PBXGroup;
311 330
 			children = (
@@ -393,6 +412,7 @@
393 412
 				139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */,
394 413
 				146833FF1AC3E56700842450 /* React.xcodeproj */,
395 414
 				22418656B14845609F953A42 /* RNVectorIcons.xcodeproj */,
415
+				5B09C20C78C74A548AAAC1FA /* KCKeepAwake.xcodeproj */,
396 416
 			);
397 417
 			name = Libraries;
398 418
 			sourceTree = "<group>";
@@ -506,6 +526,10 @@
506 526
 			productRefGroup = 83CBBA001A601CBA00E9B192 /* Products */;
507 527
 			projectDirPath = "";
508 528
 			projectReferences = (
529
+				{
530
+					ProductGroup = 0B8752821E26E54A004C5CAB /* Products */;
531
+					ProjectRef = 5B09C20C78C74A548AAAC1FA /* KCKeepAwake.xcodeproj */;
532
+				},
509 533
 				{
510 534
 					ProductGroup = 00C302A81ABCB8CE00DB3ED1 /* Products */;
511 535
 					ProjectRef = 00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */;
@@ -598,6 +622,13 @@
598 622
 			remoteRef = 00C302E31ABCB9EE00DB3ED1 /* PBXContainerItemProxy */;
599 623
 			sourceTree = BUILT_PRODUCTS_DIR;
600 624
 		};
625
+		0B8752861E26E54A004C5CAB /* libKCKeepAwake.a */ = {
626
+			isa = PBXReferenceProxy;
627
+			fileType = archive.ar;
628
+			path = libKCKeepAwake.a;
629
+			remoteRef = 0B8752851E26E54A004C5CAB /* PBXContainerItemProxy */;
630
+			sourceTree = BUILT_PRODUCTS_DIR;
631
+		};
601 632
 		139105C11AF99BAD00B5F7CC /* libRCTSettings.a */ = {
602 633
 			isa = PBXReferenceProxy;
603 634
 			fileType = archive.ar;
@@ -798,6 +829,7 @@
798 829
 					/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
799 830
 					"$(SRCROOT)/../node_modules/react-native/React/**",
800 831
 					"$(SRCROOT)/../node_modules/react-native/Libraries/LinkingIOS/**",
832
+					"$(SRCROOT)/../node_modules/react-native-keep-awake/ios",
801 833
 					"$(SRCROOT)/../node_modules/react-native-vector-icons/RNVectorIconsManager",
802 834
 				);
803 835
 				INFOPLIST_FILE = app/Info.plist;
@@ -833,6 +865,7 @@
833 865
 					/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
834 866
 					"$(SRCROOT)/../node_modules/react-native/React/**",
835 867
 					"$(SRCROOT)/../node_modules/react-native/Libraries/LinkingIOS/**",
868
+					"$(SRCROOT)/../node_modules/react-native-keep-awake/ios",
836 869
 					"$(SRCROOT)/../node_modules/react-native-vector-icons/RNVectorIconsManager",
837 870
 				);
838 871
 				INFOPLIST_FILE = app/Info.plist;
@@ -890,6 +923,7 @@
890 923
 					"$(inherited)",
891 924
 					/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
892 925
 					"$(SRCROOT)/../node_modules/react-native/React/**",
926
+					"$(SRCROOT)/../node_modules/react-native-keep-awake/ios",
893 927
 					"$(SRCROOT)/../node_modules/react-native-vector-icons/RNVectorIconsManager",
894 928
 				);
895 929
 				IPHONEOS_DEPLOYMENT_TARGET = 8.0;
@@ -931,6 +965,7 @@
931 965
 					"$(inherited)",
932 966
 					/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
933 967
 					"$(SRCROOT)/../node_modules/react-native/React/**",
968
+					"$(SRCROOT)/../node_modules/react-native-keep-awake/ios",
934 969
 					"$(SRCROOT)/../node_modules/react-native-vector-icons/RNVectorIconsManager",
935 970
 				);
936 971
 				IPHONEOS_DEPLOYMENT_TARGET = 8.0;

+ 1
- 0
package.json Ver fichero

@@ -35,6 +35,7 @@
35 35
     "react": "15.4.2",
36 36
     "react-dom": "15.4.2",
37 37
     "react-native": "0.39.2",
38
+    "react-native-keep-awake": "^1.0.7",
38 39
     "react-native-prompt": "^1.0.0",
39 40
     "react-native-vector-icons": "^3.0.0",
40 41
     "react-native-webrtc": "jitsi/react-native-webrtc",

+ 1
- 0
react/features/app/components/App.native.js Ver fichero

@@ -3,6 +3,7 @@
3 3
 import { Linking } from 'react-native';
4 4
 
5 5
 import { Platform } from '../../base/react';
6
+import '../../wake-lock';
6 7
 
7 8
 import { AbstractApp } from './AbstractApp';
8 9
 

+ 1
- 0
react/features/wake-lock/index.js Ver fichero

@@ -0,0 +1 @@
1
+import './middleware';

+ 53
- 0
react/features/wake-lock/middleware.js Ver fichero

@@ -0,0 +1,53 @@
1
+import KeepAwake from 'react-native-keep-awake';
2
+
3
+import {
4
+    CONFERENCE_FAILED,
5
+    CONFERENCE_JOINED,
6
+    CONFERENCE_LEFT
7
+} from '../base/conference';
8
+import { MiddlewareRegistry } from '../base/redux';
9
+
10
+/**
11
+ * Middleware that captures conference actions and activates or deactivates the
12
+ * wake lock accordingly. If the wake lock is active, it will prevent the screen
13
+ * from dimming.
14
+ *
15
+ * @param {Store} store - Redux store.
16
+ * @returns {Function}
17
+ */
18
+MiddlewareRegistry.register(store => next => action => {
19
+    switch (action.type) {
20
+    case CONFERENCE_JOINED: {
21
+        const state = store.getState()['features/base/conference'];
22
+
23
+        // TODO(saghul): Implement audio-only mode.
24
+        if (!state.audioOnly) {
25
+            setWakeLock(true);
26
+        }
27
+        break;
28
+    }
29
+
30
+    case CONFERENCE_FAILED:
31
+    case CONFERENCE_LEFT:
32
+        setWakeLock(false);
33
+        break;
34
+    }
35
+
36
+    return next(action);
37
+});
38
+
39
+/**
40
+ * Activates/deactivates the wake lock. If the wake lock is active, it will
41
+ * prevent the screen from dimming.
42
+ *
43
+ * @param {boolean} wakeLock - True to active the wake lock or false to
44
+ * deactivate it.
45
+ * @returns {void}
46
+ */
47
+function setWakeLock(wakeLock) {
48
+    if (wakeLock) {
49
+        KeepAwake.activate();
50
+    } else {
51
+        KeepAwake.deactivate();
52
+    }
53
+}

Loading…
Cancelar
Guardar