Sfoglia il codice sorgente

feat(dropbox): Implement react-native module.

master
hristoterezov 6 anni fa
parent
commit
38517127c3

+ 26
- 0
android/README.md Vedi File

@@ -491,3 +491,29 @@ Picture-in-Picture style scenario, in a rectangle too small to accommodate its
491 491
 Jitsi Meet SDK automatically enables (unless explicitly disabled by a
492 492
 `setPictureInPictureEnabled(false)` call) Android's native Picture-in-Picture
493 493
 mode iff the platform is supported i.e. Android >= Oreo.
494
+
495
+## Dropbox integration
496
+
497
+To setup the Dropbox integration, follow these steps:
498
+
499
+1. Add the following to the app's AndroidManifest.xml and change `<APP_KEY>` to
500
+your Dropbox app key:
501
+```
502
+<activity
503
+    android:configChanges="keyboard|orientation"
504
+    android:launchMode="singleTask"
505
+    android:name="com.dropbox.core.android.AuthActivity">
506
+  <intent-filter>
507
+    <action android:name="android.intent.action.VIEW" />
508
+    <category android:name="android.intent.category.BROWSABLE" />
509
+    <category android:name="android.intent.category.DEFAULT" />
510
+    <data android:scheme="db-<APP_KEY>" />
511
+  </intent-filter>
512
+</activity>
513
+```
514
+
515
+2. Add the following to the app's strings.xml and change `<APP_KEY>` to your
516
+Dropbox app key:
517
+```
518
+<string name="dropbox_app_key"><APP_KEY></string>
519
+```

+ 34
- 0
android/app/build.gradle Vedi File

@@ -1,5 +1,7 @@
1 1
 apply plugin: 'com.android.application'
2 2
 
3
+def dropboxAppID = ""
4
+
3 5
 android {
4 6
     compileSdkVersion rootProject.ext.compileSdkVersion
5 7
 
@@ -28,10 +30,12 @@ android {
28 30
 
29 31
     buildTypes {
30 32
         debug {
33
+            resValue("string", "dropbox_app_key", "${dropboxAppID}")
31 34
             minifyEnabled true
32 35
             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules-debug.pro'
33 36
         }
34 37
         release {
38
+            resValue("string", "dropbox_app_key", "${dropboxAppID}")
35 39
             minifyEnabled true
36 40
             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules-release.pro'
37 41
         }
@@ -41,6 +45,36 @@ android {
41 45
         sourceCompatibility JavaVersion.VERSION_1_8
42 46
         targetCompatibility JavaVersion.VERSION_1_8
43 47
     }
48
+
49
+    if (dropboxAppID) {
50
+        def dropboxActivity = """<activity
51
+            android:name="com.dropbox.core.android.AuthActivity"
52
+            android:configChanges="orientation|keyboard"
53
+            android:launchMode="singleTask">
54
+          <intent-filter>
55
+            <data android:scheme="db-${dropboxAppID}" />
56
+            <action android:name="android.intent.action.VIEW" />
57
+            <category android:name="android.intent.category.BROWSABLE" />
58
+            <category android:name="android.intent.category.DEFAULT" />
59
+          </intent-filter>
60
+        </activity>""";
61
+
62
+
63
+        applicationVariants.all { variant ->
64
+            variant.outputs.each { output ->
65
+                output.processManifest.doLast {
66
+                    File manifestOutFile = new File(output.processManifest.manifestOutputDirectory, "AndroidManifest.xml")
67
+                    if (!manifestOutFile.isFile()) {
68
+                        manifestOutFile = new File(new File(output.processManifest.manifestOutputDirectory, output.dirName),"AndroidManifest.xml")
69
+                    }
70
+                    if (manifestOutFile.exists()) {
71
+                        def newFileContents = manifestOutFile.getText('UTF-8').replace("</application>", "${dropboxActivity}</application>")
72
+                        manifestOutFile.write(newFileContents, 'UTF-8')
73
+                    }
74
+                }
75
+            }
76
+        }
77
+    }
44 78
 }
45 79
 
46 80
 dependencies {

+ 1
- 0
android/sdk/build.gradle Vedi File

@@ -22,6 +22,7 @@ dependencies {
22 22
     compile fileTree(dir: 'libs', include: ['*.jar'])
23 23
 
24 24
     compile 'com.android.support:appcompat-v7:27.0.2'
25
+    compile 'com.dropbox.core:dropbox-core-sdk:3.0.8'
25 26
     compile 'com.facebook.react:react-native:+'
26 27
 
27 28
     compile project(':react-native-background-timer')

+ 1
- 0
android/sdk/src/main/java/org/jitsi/meet/sdk/ReactInstanceManagerHolder.java Vedi File

@@ -45,6 +45,7 @@ class ReactInstanceManagerHolder {
45 45
             new PictureInPictureModule(reactContext),
46 46
             new ProximityModule(reactContext),
47 47
             new WiFiStatsModule(reactContext),
48
+            new org.jitsi.meet.sdk.dropbox.Dropbox(reactContext),
48 49
             new org.jitsi.meet.sdk.invite.InviteModule(reactContext),
49 50
             new org.jitsi.meet.sdk.net.NAT64AddrInfoModule(reactContext)
50 51
         );

+ 181
- 0
android/sdk/src/main/java/org/jitsi/meet/sdk/dropbox/Dropbox.java Vedi File

@@ -0,0 +1,181 @@
1
+package org.jitsi.meet.sdk.dropbox;
2
+
3
+import android.app.Activity;
4
+import android.content.Context;
5
+import android.content.pm.ApplicationInfo;
6
+import android.content.pm.PackageInfo;
7
+import android.content.pm.PackageManager;
8
+import android.text.TextUtils;
9
+import android.util.Log;
10
+
11
+import com.dropbox.core.DbxException;
12
+import com.dropbox.core.DbxRequestConfig;
13
+import com.dropbox.core.v2.DbxClientV2;
14
+import com.dropbox.core.v2.users.FullAccount;
15
+import com.dropbox.core.v2.users.SpaceAllocation;
16
+import com.dropbox.core.v2.users.SpaceUsage;
17
+import com.facebook.react.bridge.Arguments;
18
+import com.facebook.react.bridge.LifecycleEventListener;
19
+import com.facebook.react.bridge.Promise;
20
+import com.facebook.react.bridge.ReactApplicationContext;
21
+import com.facebook.react.bridge.ReactContextBaseJavaModule;
22
+import com.dropbox.core.android.Auth;
23
+import com.facebook.react.bridge.ReactMethod;
24
+import com.facebook.react.bridge.WritableMap;
25
+import org.jitsi.meet.sdk.R;
26
+
27
+import java.util.HashMap;
28
+import java.util.Map;
29
+
30
+/**
31
+ * Implements the react-native module for the dropbox integration.
32
+ */
33
+public class Dropbox extends ReactContextBaseJavaModule implements LifecycleEventListener {
34
+
35
+    private Promise promise = null;
36
+    private String clientId;
37
+    private String appID;
38
+    private boolean isEnabled = false;
39
+
40
+    public Dropbox(ReactApplicationContext reactContext) {
41
+        super(reactContext);
42
+        reactContext.addLifecycleEventListener(this);
43
+        clientId = generateClientId();
44
+        appID = reactContext.getString(R.string.dropbox_app_key);
45
+        if (!TextUtils.isEmpty(appID)) {
46
+            isEnabled = true;
47
+        }
48
+    }
49
+
50
+    @Override
51
+    public String getName() {
52
+        return "Dropbox";
53
+    }
54
+
55
+    /**
56
+     * Executes the dropbox auth flow.
57
+     *
58
+     * @param promise The promise used to return the result of the auth flow.
59
+     */
60
+    @ReactMethod
61
+    public void authorize(final Promise promise) {
62
+        if (!isEnabled) {
63
+            promise.reject(new Exception("Dropbox integration isn't configured."));
64
+            return;
65
+        }
66
+        Auth.startOAuth2Authentication(this.getCurrentActivity(), appID);
67
+        this.promise = promise;
68
+    }
69
+
70
+    @Override
71
+    public Map<String, Object> getConstants() {
72
+        final Map<String, Object> constants = new HashMap<>();
73
+        constants.put("ENABLED", isEnabled);
74
+        return constants;
75
+    }
76
+
77
+
78
+    /**
79
+     * Resolves the current user dropbox display name.
80
+     *
81
+     * @param token A dropbox access token.
82
+     * @param promise The promise used to return the result of the auth flow.
83
+     */
84
+    @ReactMethod
85
+    public void getDisplayName(final String token, final Promise promise) {
86
+        DbxRequestConfig config
87
+            = DbxRequestConfig.newBuilder(clientId).build();
88
+        DbxClientV2 client = new DbxClientV2(config, token);
89
+        // Get current account info
90
+        try {
91
+            FullAccount account = client.users().getCurrentAccount();
92
+            promise.resolve(account.getName().getDisplayName());
93
+        } catch (DbxException e) {
94
+            promise.reject(e);
95
+        }
96
+    }
97
+
98
+    /**
99
+     * Resolves the current user space usage.
100
+     *
101
+     * @param token A dropbox access token.
102
+     * @param promise The promise used to return the result of the auth flow.
103
+     */
104
+    @ReactMethod
105
+    public void getSpaceUsage(final String token, final Promise promise) {
106
+        DbxRequestConfig config
107
+            = DbxRequestConfig.newBuilder(clientId).build();
108
+        DbxClientV2 client = new DbxClientV2(config, token);
109
+        try {
110
+            SpaceUsage spaceUsage = client.users().getSpaceUsage();
111
+            WritableMap map = Arguments.createMap();
112
+            map.putString("used", String.valueOf(spaceUsage.getUsed()));
113
+            SpaceAllocation allocation = spaceUsage.getAllocation();
114
+            long allocated = 0;
115
+            if(allocation.isIndividual()) {
116
+                allocated += allocation.getIndividualValue().getAllocated();
117
+            }
118
+
119
+            if(allocation.isTeam()) {
120
+                allocated += allocation.getTeamValue().getAllocated();
121
+            }
122
+            map.putString("allocated", String.valueOf(allocated));
123
+            promise.resolve(map);
124
+        } catch (DbxException e) {
125
+            promise.reject(e);
126
+        }
127
+    }
128
+
129
+    /**
130
+     * Generate a client identifier for the dropbox sdk.
131
+     *
132
+     * @returns a client identifier for the dropbox sdk.
133
+     * @see {https://dropbox.github.io/dropbox-sdk-java/api-docs/v3.0.x/com/dropbox/core/DbxRequestConfig.html#getClientIdentifier--}
134
+     */
135
+    private String generateClientId() {
136
+        Context context = getReactApplicationContext();
137
+        PackageManager packageManager = context.getPackageManager();
138
+        ApplicationInfo applicationInfo = null;
139
+        PackageInfo packageInfo = null;
140
+
141
+        try {
142
+            String packageName = context.getPackageName();
143
+
144
+            applicationInfo
145
+                    = packageManager.getApplicationInfo(packageName, 0);
146
+            packageInfo = packageManager.getPackageInfo(packageName, 0);
147
+        } catch (PackageManager.NameNotFoundException e) {
148
+        }
149
+
150
+        String applicationLabel
151
+            = applicationInfo == null
152
+                ? "JitsiMeet"
153
+                    : packageManager.getApplicationLabel(applicationInfo)
154
+                        .toString().replaceAll("\\s", "");
155
+        String version = packageInfo == null ? "dev" : packageInfo.versionName;
156
+
157
+       return applicationLabel + "/" + version;
158
+    }
159
+
160
+    @Override
161
+    public void onHostResume() {
162
+        final String token = Auth.getOAuth2Token();
163
+        if (token == null)
164
+            return;
165
+
166
+        if (this.promise != null) {
167
+            this.promise.resolve(token);
168
+            this.promise = null;
169
+        }
170
+    }
171
+
172
+    @Override
173
+    public void onHostPause() {
174
+
175
+    }
176
+
177
+    @Override
178
+    public void onHostDestroy() {
179
+
180
+    }
181
+}

+ 1
- 0
android/sdk/src/main/res/values/strings.xml Vedi File

@@ -1,3 +1,4 @@
1 1
 <resources>
2 2
     <string name="app_name">Jitsi Meet SDK</string>
3
+    <string name="dropbox_app_key"></string>
3 4
 </resources>

+ 2
- 0
ios/Podfile Vedi File

@@ -26,6 +26,8 @@ target 'JitsiMeet' do
26 26
   pod 'Folly',
27 27
     :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
28 28
 
29
+  pod 'ObjectiveDropboxOfficial'
30
+
29 31
   pod 'react-native-background-timer',
30 32
     :path => '../node_modules/react-native-background-timer'
31 33
   pod 'react-native-fast-image',

+ 5
- 1
ios/Podfile.lock Vedi File

@@ -27,6 +27,7 @@ PODS:
27 27
   - GTMSessionFetcher/Core (1.2.0)
28 28
   - GTMSessionFetcher/Full (1.2.0):
29 29
     - GTMSessionFetcher/Core (= 1.2.0)
30
+  - ObjectiveDropboxOfficial (3.9.1)
30 31
   - React (0.55.4):
31 32
     - React/Core (= 0.55.4)
32 33
   - react-native-background-timer (2.0.0):
@@ -103,6 +104,7 @@ DEPENDENCIES:
103 104
   - DoubleConversion (from `../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec`)
104 105
   - Folly (from `../node_modules/react-native/third-party-podspecs/Folly.podspec`)
105 106
   - glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`)
107
+  - ObjectiveDropboxOfficial
106 108
   - react-native-background-timer (from `../node_modules/react-native-background-timer`)
107 109
   - react-native-calendar-events (from `../node_modules/react-native-calendar-events`)
108 110
   - react-native-fast-image (from `../node_modules/react-native-fast-image`)
@@ -132,6 +134,7 @@ SPEC REPOS:
132 134
     - GoogleToolboxForMac
133 135
     - GTMOAuth2
134 136
     - GTMSessionFetcher
137
+    - ObjectiveDropboxOfficial
135 138
     - SDWebImage
136 139
 
137 140
 EXTERNAL SOURCES:
@@ -174,6 +177,7 @@ SPEC CHECKSUMS:
174 177
   GoogleToolboxForMac: 91c824d21e85b31c2aae9bb011c5027c9b4e738f
175 178
   GTMOAuth2: c77fe325e4acd453837e72d91e3b5f13116857b2
176 179
   GTMSessionFetcher: 0c4baf0a73acd0041bf9f71ea018deedab5ea84e
180
+  ObjectiveDropboxOfficial: 274ce69d66286c94416daf1da5237c55e105e8c0
177 181
   React: aa2040dbb6f317b95314968021bd2888816e03d5
178 182
   react-native-background-timer: 63dcbf37dbcf294b5c6c071afcdc661fa06a7594
179 183
   react-native-calendar-events: fe6fbc8ed337a7423c98f2c9012b25f20444de09
@@ -187,6 +191,6 @@ SPEC CHECKSUMS:
187 191
   SDWebImage: 624d6e296c69b244bcede364c72ae0430ac14681
188 192
   yoga: a23273df0088bf7f2bb7e5d7b00044ea57a2a54a
189 193
 
190
-PODFILE CHECKSUM: da74c08f6eb674668c49d8d799f8d9e2476a9fc5
194
+PODFILE CHECKSUM: cf8276ba4b0933b24c6082a25a5f4eabe0ba4ea6
191 195
 
192 196
 COCOAPODS: 1.5.3

+ 34
- 0
ios/README.md Vedi File

@@ -212,3 +212,37 @@ resize `JitsiMeetView`.
212 212
 If `pictureInPictureEnabled` is set to `YES` or `delegate` implements
213 213
 `enterPictureInPicture:`, the in-call toolbar will render a button to afford the
214 214
 user to request entering Picture-in-Picture.
215
+
216
+## Dropbox integration
217
+
218
+To setup the dropbox integration you need to do the following steps:
219
+
220
+1. Add the following lines in your Info.plist file and replace `<APP_KEY>` with your dropbox app key:
221
+```
222
+<key>CFBundleURLTypes</key>
223
+<array>
224
+    <dict>
225
+        <key>CFBundleURLSchemes</key>
226
+        <array>
227
+            <string>db-<APP_KEY></string>
228
+        </array>
229
+        <key>CFBundleURLName</key>
230
+        <string></string>
231
+    </dict>
232
+</array>
233
+<key>LSApplicationQueriesSchemes</key>
234
+<array>
235
+    <string>dbapi-8-emm</string>
236
+    <string>dbapi-2</string>
237
+</array>
238
+```
239
+
240
+2. Add the following method to `AppDelegate`:
241
+```objc
242
+- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url
243
+            options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
244
+  return [JitsiMeetView application:app
245
+                            openURL:url
246
+                            options:options];
247
+}
248
+```

+ 8
- 0
ios/app/src/AppDelegate.m Vedi File

@@ -46,4 +46,12 @@
46 46
                            annotation:annotation];
47 47
 }
48 48
 
49
+
50
+- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url
51
+            options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
52
+  return [JitsiMeetView application:app
53
+                            openURL:url
54
+                            options: options];
55
+}
56
+
49 57
 @end

+ 17
- 3
ios/sdk/sdk.xcodeproj/project.pbxproj Vedi File

@@ -34,6 +34,7 @@
34 34
 		75635B0A20751D6D00F29C9F /* joined.wav in Resources */ = {isa = PBXBuildFile; fileRef = 75635B0820751D6D00F29C9F /* joined.wav */; };
35 35
 		75635B0B20751D6D00F29C9F /* left.wav in Resources */ = {isa = PBXBuildFile; fileRef = 75635B0920751D6D00F29C9F /* left.wav */; };
36 36
 		A4414AE020B37F1A003546E6 /* rejected.wav in Resources */ = {isa = PBXBuildFile; fileRef = A4414ADF20B37F1A003546E6 /* rejected.wav */; };
37
+		A4A934E9212F3ADB001E9388 /* Dropbox.m in Sources */ = {isa = PBXBuildFile; fileRef = A4A934E8212F3ADB001E9388 /* Dropbox.m */; };
37 38
 		B386B85720981A75000DEF7A /* InviteController.m in Sources */ = {isa = PBXBuildFile; fileRef = B386B85020981A74000DEF7A /* InviteController.m */; };
38 39
 		B386B85820981A75000DEF7A /* AddPeopleController.m in Sources */ = {isa = PBXBuildFile; fileRef = B386B85120981A74000DEF7A /* AddPeopleController.m */; };
39 40
 		B386B85920981A75000DEF7A /* AddPeopleControllerDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = B386B85220981A74000DEF7A /* AddPeopleControllerDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -87,6 +88,8 @@
87 88
 		98E09B5C73D9036B4ED252FC /* Pods-JitsiMeet.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-JitsiMeet.debug.xcconfig"; path = "../Pods/Target Support Files/Pods-JitsiMeet/Pods-JitsiMeet.debug.xcconfig"; sourceTree = "<group>"; };
88 89
 		9C77CA3CC919B081F1A52982 /* Pods-JitsiMeet.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-JitsiMeet.release.xcconfig"; path = "../Pods/Target Support Files/Pods-JitsiMeet/Pods-JitsiMeet.release.xcconfig"; sourceTree = "<group>"; };
89 90
 		A4414ADF20B37F1A003546E6 /* rejected.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; name = rejected.wav; path = ../../sounds/rejected.wav; sourceTree = "<group>"; };
91
+		A4A934E8212F3ADB001E9388 /* Dropbox.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Dropbox.m; sourceTree = "<group>"; };
92
+		A4A934EB21349A06001E9388 /* Dropbox.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Dropbox.h; sourceTree = "<group>"; };
90 93
 		B386B85020981A74000DEF7A /* InviteController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = InviteController.m; sourceTree = "<group>"; };
91 94
 		B386B85120981A74000DEF7A /* AddPeopleController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AddPeopleController.m; sourceTree = "<group>"; };
92 95
 		B386B85220981A74000DEF7A /* AddPeopleControllerDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AddPeopleControllerDelegate.h; sourceTree = "<group>"; };
@@ -122,9 +125,6 @@
122 125
 		0BCA49681EC4BBE500B793EE /* Resources */ = {
123 126
 			isa = PBXGroup;
124 127
 			children = (
125
-				6C31EDC720C06D490089C899 /* recordingOn.mp3 */,
126
-				6C31EDC920C06D530089C899 /* recordingOff.mp3 */,
127
-				A4414ADF20B37F1A003546E6 /* rejected.wav */,
128 128
 				0BC4B8681F8C01E100CE8B21 /* CallKitIcon.png */,
129 129
 				C6245F5B2053091D0040BE68 /* image-resize@2x.png */,
130 130
 				C6245F5C2053091D0040BE68 /* image-resize@3x.png */,
@@ -133,6 +133,9 @@
133 133
 				75635B0920751D6D00F29C9F /* left.wav */,
134 134
 				0B49424420AD8DBD00BD2DE0 /* outgoingRinging.wav */,
135 135
 				0B49424320AD8DBD00BD2DE0 /* outgoingStart.wav */,
136
+				6C31EDC920C06D530089C899 /* recordingOff.mp3 */,
137
+				6C31EDC720C06D490089C899 /* recordingOn.mp3 */,
138
+				A4414ADF20B37F1A003546E6 /* rejected.wav */,
136 139
 			);
137 140
 			name = Resources;
138 141
 			sourceTree = "<group>";
@@ -162,6 +165,7 @@
162 165
 				0BB9AD7C1F60356D001C08DB /* AppInfo.m */,
163 166
 				0BCA495C1EC4B6C600B793EE /* AudioMode.m */,
164 167
 				C69EFA02209A0EFD0027712B /* callkit */,
168
+				A4A934E7212F3AB8001E9388 /* dropbox */,
165 169
 				0BA13D301EE83FF8007BEF7F /* ExternalAPI.m */,
166 170
 				0BD906E91EC0C00300C8C18E /* Info.plist */,
167 171
 				B386B84F20981A11000DEF7A /* invite */,
@@ -193,6 +197,15 @@
193 197
 			name = Frameworks;
194 198
 			sourceTree = "<group>";
195 199
 		};
200
+		A4A934E7212F3AB8001E9388 /* dropbox */ = {
201
+			isa = PBXGroup;
202
+			children = (
203
+				A4A934EB21349A06001E9388 /* Dropbox.h */,
204
+				A4A934E8212F3ADB001E9388 /* Dropbox.m */,
205
+			);
206
+			path = dropbox;
207
+			sourceTree = "<group>";
208
+		};
196 209
 		B386B84F20981A11000DEF7A /* invite */ = {
197 210
 			isa = PBXGroup;
198 211
 			children = (
@@ -433,6 +446,7 @@
433 446
 				0BCA49611EC4B6C600B793EE /* Proximity.m in Sources */,
434 447
 				C69EFA0C209A0F660027712B /* JMCallKitEmitter.swift in Sources */,
435 448
 				C6A34261204EF76800E062DD /* DragGestureController.swift in Sources */,
449
+				A4A934E9212F3ADB001E9388 /* Dropbox.m in Sources */,
436 450
 				C69EFA0D209A0F660027712B /* JMCallKitProxy.swift in Sources */,
437 451
 				C69EFA0E209A0F660027712B /* JMCallKitListener.swift in Sources */,
438 452
 				0B412F191EDEC65D00B1A0A6 /* JitsiMeetView.m in Sources */,

+ 10
- 5
ios/sdk/src/Info.plist Vedi File

@@ -18,12 +18,17 @@
18 18
 	<string>1.9.0</string>
19 19
 	<key>CFBundleVersion</key>
20 20
 	<string>$(CURRENT_PROJECT_VERSION)</string>
21
+	<key>JitsiMeetFonts</key>
22
+	<array>
23
+		<string>FontAwesome.ttf</string>
24
+		<string>jitsi.ttf</string>
25
+	</array>
26
+	<key>LSApplicationQueriesSchemes</key>
27
+	<array>
28
+		<string>dbapi-2</string>
29
+		<string>dbapi-8-emm</string>
30
+	</array>
21 31
 	<key>NSPrincipalClass</key>
22 32
 	<string></string>
23
-  <key>JitsiMeetFonts</key>
24
-  <array>
25
-    <string>FontAwesome.ttf</string>
26
-    <string>jitsi.ttf</string>
27
-  </array>
28 33
 </dict>
29 34
 </plist>

+ 4
- 0
ios/sdk/src/JitsiMeetView.h Vedi File

@@ -39,6 +39,10 @@
39 39
   continueUserActivity:(NSUserActivity * _Nonnull)userActivity
40 40
     restorationHandler:(void (^ _Nullable)(NSArray * _Nullable))restorationHandler;
41 41
 
42
++ (BOOL)application:(UIApplication *)app
43
+            openURL:(NSURL *)url
44
+            options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options;
45
+
42 46
 + (BOOL)application:(UIApplication * _Nonnull)application
43 47
             openURL:(NSURL * _Nonnull)URL
44 48
   sourceApplication:(NSString * _Nullable)sourceApplication

+ 10
- 0
ios/sdk/src/JitsiMeetView.m Vedi File

@@ -23,6 +23,7 @@
23 23
 #import <React/RCTLinkingManager.h>
24 24
 #import <React/RCTRootView.h>
25 25
 
26
+#import "Dropbox.h"
26 27
 #import "Invite+Private.h"
27 28
 #import "InviteController+Private.h"
28 29
 #import "JitsiMeetView+Private.h"
@@ -137,6 +138,8 @@ static NSMapTable<NSString *, JitsiMeetView *> *views;
137 138
     // Store launch options, will be used when we create the bridge.
138 139
     _launchOptions = [launchOptions copy];
139 140
 
141
+    [Dropbox setAppKey];
142
+
140 143
     return YES;
141 144
 }
142 145
 
@@ -211,6 +214,13 @@ static NSMapTable<NSString *, JitsiMeetView *> *views;
211 214
                                annotation:annotation];
212 215
 }
213 216
 
217
++ (BOOL)application:(UIApplication *)app openURL:(NSURL *)url
218
+            options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
219
+    return [Dropbox application:app
220
+                              openURL:url
221
+                              options: options];
222
+}
223
+
214 224
 #pragma mark Initializers
215 225
 
216 226
 - (instancetype)init {

+ 27
- 0
ios/sdk/src/dropbox/Dropbox.h Vedi File

@@ -0,0 +1,27 @@
1
+/*
2
+ * Copyright @ 2018-present Atlassian Pty Ltd
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+#import <React/RCTBridge.h>
18
+
19
+@interface Dropbox : NSObject<RCTBridgeModule>
20
+
21
++ (BOOL)application:(UIApplication *)app
22
+            openURL:(NSURL *)url
23
+            options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options;
24
+
25
++ (void)setAppKey;
26
+
27
+@end

+ 163
- 0
ios/sdk/src/dropbox/Dropbox.m Vedi File

@@ -0,0 +1,163 @@
1
+/*
2
+ * Copyright @ 2017-present Atlassian Pty Ltd
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+#import <React/RCTBridgeModule.h>
18
+#import <ObjectiveDropboxOfficial/ObjectiveDropboxOfficial.h>
19
+#import "Dropbox.h"
20
+
21
+RCTPromiseResolveBlock currentResolve = nil;
22
+RCTPromiseRejectBlock currentReject = nil;
23
+
24
+@implementation Dropbox
25
+
26
++ (NSString *)getAppKey{
27
+    NSArray *urlTypes = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleURLTypes"];
28
+    for(NSDictionary<NSString *, NSArray *> *urlType in urlTypes) {
29
+        NSArray *urlSchemes = urlType[@"CFBundleURLSchemes"];
30
+        if(urlSchemes != nil) {
31
+            for(NSString *urlScheme in urlSchemes) {
32
+                if(urlScheme != nil) {
33
+                    if ([urlScheme hasPrefix:@"db-"]) {
34
+                        return [urlScheme substringFromIndex:3];
35
+                    }
36
+                }
37
+            }
38
+        }
39
+        
40
+    }
41
+   
42
+    return nil;
43
+}
44
+
45
+RCT_EXPORT_MODULE();
46
+
47
+- (NSDictionary *)constantsToExport {
48
+    BOOL enabled = [Dropbox getAppKey] != nil;
49
+    
50
+    return @{
51
+        @"ENABLED": [NSNumber numberWithBool:enabled]
52
+    };
53
+};
54
+
55
+RCT_EXPORT_METHOD(authorize: (RCTPromiseResolveBlock)resolve
56
+                  reject:(__unused RCTPromiseRejectBlock)reject) {
57
+    currentResolve = resolve;
58
+    currentReject = reject;
59
+    
60
+    dispatch_async(dispatch_get_main_queue(), ^{
61
+        [DBClientsManager authorizeFromController:[UIApplication sharedApplication]
62
+                                       controller:[[self class] topMostController]
63
+                                          openURL:^(NSURL *url) {
64
+                                              [[UIApplication sharedApplication] openURL:url];
65
+                                          }];
66
+    });
67
+}
68
+
69
+RCT_EXPORT_METHOD(getDisplayName: (NSString *)token
70
+                  resolve: (RCTPromiseResolveBlock)resolve
71
+                  reject:(RCTPromiseRejectBlock)reject) {
72
+    DBUserClient *client = [[DBUserClient alloc] initWithAccessToken:token];
73
+    [[client.usersRoutes getCurrentAccount] setResponseBlock:^(DBUSERSFullAccount *result, DBNilObject *routeError, DBRequestError *networkError) {
74
+        if (result) {
75
+            resolve(result.name.displayName);
76
+        } else {
77
+            NSString *msg = @"Failed!";
78
+            if (networkError != nil) {
79
+                msg = [NSString stringWithFormat:@"Failed! Error: %@", networkError];
80
+            }
81
+            reject(@"getDisplayName", @"Failed", nil);
82
+        }
83
+    }];
84
+
85
+}
86
+
87
+RCT_EXPORT_METHOD(getSpaceUsage: (NSString *)token
88
+                  resolve: (RCTPromiseResolveBlock)resolve
89
+                  reject:(RCTPromiseRejectBlock)reject) {
90
+    DBUserClient *client = [[DBUserClient alloc] initWithAccessToken:token];
91
+    [[client.usersRoutes getSpaceUsage] setResponseBlock:^(DBUSERSSpaceUsage *result, DBNilObject *routeError, DBRequestError *networkError) {
92
+        if (result) {
93
+            DBUSERSSpaceAllocation *allocation = result.allocation;
94
+            NSNumber *allocated = 0;
95
+            NSNumber *used = 0;
96
+            if([allocation isIndividual]) {
97
+                allocated = allocation.individual.allocated;
98
+                used = result.used;
99
+            } else if ([allocation isTeam]) {
100
+                allocated = allocation.team.allocated;
101
+                used = allocation.team.used;
102
+            }
103
+            id objects[] = { used, allocated };
104
+            id keys[] = { @"used", @"allocated" };
105
+            NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:objects
106
+                                            forKeys:keys
107
+                                            count:2];
108
+            resolve(dictionary);
109
+        } else {
110
+            NSString *msg = @"Failed!";
111
+            if (networkError != nil) {
112
+                msg = [NSString stringWithFormat:@"Failed! Error: %@", networkError];
113
+            }
114
+            reject(@"getSpaceUsage", msg, nil);
115
+        }
116
+    }];
117
+
118
+}
119
+
120
++ (BOOL)application:(UIApplication *)app openURL:(NSURL *)url
121
+            options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
122
+    DBOAuthResult *authResult = [DBClientsManager handleRedirectURL:url];
123
+    if (authResult != nil) {
124
+        if ([authResult isSuccess]) {
125
+            currentResolve(authResult.accessToken.accessToken);
126
+            currentResolve = nil;
127
+            currentReject = nil;
128
+            return YES;
129
+        } else {
130
+            NSString *msg;
131
+            if ([authResult isError]) {
132
+                msg = [NSString stringWithFormat:@"%@, error type: %ld",[authResult errorDescription], [authResult errorType]];
133
+            } else {
134
+                msg = @"OAuth canceled!";
135
+            }
136
+            currentReject(@"authorize", msg, nil);
137
+            currentResolve = nil;
138
+            currentReject = nil;
139
+        }
140
+    }
141
+    return NO;
142
+}
143
+
144
++ (UIViewController*)topMostController
145
+{
146
+    UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
147
+    
148
+    while (topController.presentedViewController) {
149
+        topController = topController.presentedViewController;
150
+    }
151
+    
152
+    return topController;
153
+}
154
+
155
++ (void)setAppKey {
156
+    NSString *appKey = [self getAppKey];
157
+    if (appKey != nil) {
158
+        [DBClientsManager setupWithAppKey:appKey];
159
+    }
160
+}
161
+
162
+
163
+@end

Loading…
Annulla
Salva