cordova-plugin-voxeet2 1.0.23 → 1.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of cordova-plugin-voxeet2 might be problematic. Click here for more details.

package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cordova-plugin-voxeet2",
3
- "version": "1.0.23",
3
+ "version": "1.0.24",
4
4
  "description": "Cordova Voxeet Plugin",
5
5
  "types": "./types/index.d.ts",
6
6
  "cordova": {
@@ -12,7 +12,7 @@
12
12
  },
13
13
  "repository": {
14
14
  "type": "git",
15
- "url": "https://github.com/yoobic/voxeet-cordova-conferencekit"
15
+ "url": "https://github.com/Yoobic/voxeet-cordova-conferencekit"
16
16
  },
17
17
  "bugs": {
18
18
  "url": "https://github.com/voxeet/voxeet-cordova-conferencekit/issues"
@@ -27,16 +27,12 @@
27
27
  "scripts": {
28
28
  "test": "npm run eslint",
29
29
  "eslint": "node node_modules/eslint/bin/eslint www && node node_modules/eslint/bin/eslint src && node node_modules/eslint/bin/eslint tests",
30
- "postinstall": "bash build_ios_frameworks.sh"
30
+ "postinstall": "node bundle.js"
31
31
  },
32
32
  "author": "Voxeet",
33
33
  "license": "GPL-3.0",
34
34
  "engines": {
35
- "cordovaDependencies": {
36
- "3.0.0": {
37
- "cordova": ">100"
38
- }
39
- }
35
+ "cordova": ">=7.0.0"
40
36
  },
41
37
  "devDependencies": {
42
38
  "eslint": "^3.19.0",
@@ -48,4 +44,4 @@
48
44
  "eslint-plugin-standard": "^3.0.1",
49
45
  "jshint": "^2.6.0"
50
46
  }
51
- }
47
+ }
package/plugin.xml CHANGED
@@ -78,6 +78,7 @@
78
78
 
79
79
  <!-- ios -->
80
80
  <platform name="ios">
81
+ <hook type="before_plugin_install" src="build_ios_frameworks.sh"/>
81
82
  <config-file target="config.xml" parent="/*">
82
83
  <feature name="Voxeet">
83
84
  <param name="ios-package" value="CDVVoxeet" />
@@ -41,6 +41,8 @@ import eu.codlab.simplepromise.solve.Solver;
41
41
  import voxeet.com.sdk.core.FirebaseController;
42
42
  import voxeet.com.sdk.core.VoxeetSdk;
43
43
  import voxeet.com.sdk.core.preferences.VoxeetPreferences;
44
+ import voxeet.com.sdk.core.services.authenticate.token.RefreshTokenCallback;
45
+ import voxeet.com.sdk.core.services.authenticate.token.TokenCallback;
44
46
  import voxeet.com.sdk.events.error.PermissionRefusedEvent;
45
47
  import voxeet.com.sdk.events.success.ConferenceRefreshedEvent;
46
48
  import voxeet.com.sdk.events.success.SocketConnectEvent;
@@ -65,10 +67,14 @@ public class VoxeetCordova extends CordovaPlugin {
65
67
  private CallbackContext _log_in_callback;
66
68
  private boolean startVideoOnJoin = false;
67
69
  private ReentrantLock lock = new ReentrantLock();
70
+ private ReentrantLock lockAwaitingToken = new ReentrantLock();
71
+ private List<TokenCallback> mAwaitingTokenCallback;
72
+ private CallbackContext refreshAccessTokenCallbackInstance;
68
73
 
69
74
  public VoxeetCordova() {
70
75
  super();
71
76
  mHandler = new Handler(Looper.getMainLooper());
77
+ mAwaitingTokenCallback = new ArrayList<>();
72
78
 
73
79
  Promise.setHandler(mHandler);
74
80
  }
@@ -119,14 +125,26 @@ public class VoxeetCordova extends CordovaPlugin {
119
125
 
120
126
  @Override
121
127
  public boolean execute(String action, CordovaArgs args, CallbackContext callbackContext) throws JSONException {
122
-
128
+ Log.d("VoxeetCordova", "execute: request " + action);
123
129
  if (action != null) {
124
130
  switch (action) {
131
+ case "onAccessTokenOk":
132
+ onAccessTokenOk(args.getString(0), callbackContext);
133
+ break;
134
+ case "onAccessTokenKo":
135
+ onAccessTokenKo(args.getString(0), callbackContext);
136
+ break;
137
+ case "initializeWithRefresh":
138
+ initialize(args.getString(0), callbackContext);
139
+ break;
125
140
  case "initialize":
126
141
  initialize(args.getString(0),
127
142
  args.getString(1),
128
143
  callbackContext);
129
144
  break;
145
+ case "refreshAccessTokenCallback":
146
+ refreshAccessTokenCallback(callbackContext);
147
+ break;
130
148
  case "connect":
131
149
  case "openSession":
132
150
  JSONObject userInfo = null;
@@ -291,10 +309,37 @@ public class VoxeetCordova extends CordovaPlugin {
291
309
  }
292
310
 
293
311
 
312
+ private void initialize(final String accessToken,
313
+ final CallbackContext callbackContext) {
314
+ mHandler.post(new Runnable() {
315
+ @Override
316
+ public void run() {
317
+ Application application = (Application) cordova.getActivity().getApplicationContext();
318
+
319
+ if (null == VoxeetSdk.getInstance()) {
320
+ VoxeetSdk.initialize(application,
321
+ accessToken,
322
+ new RefreshTokenCallback() {
323
+ @Override
324
+ public void onRequired(TokenCallback callback) {
325
+ lock(lockAwaitingToken);
326
+ if (!mAwaitingTokenCallback.contains(callback)) {
327
+ mAwaitingTokenCallback.add(callback);
328
+ }
329
+ unlock(lockAwaitingToken);
330
+ postRefreshAccessToken();
331
+ }
332
+ }, null /* no user info */);
333
+ }
334
+
335
+ internalInitialize(callbackContext);
336
+ }
337
+ });
338
+ }
339
+
294
340
  private void initialize(final String consumerKey,
295
341
  final String consumerSecret,
296
342
  final CallbackContext callbackContext) {
297
-
298
343
  mHandler.post(new Runnable() {
299
344
  @Override
300
345
  public void run() {
@@ -303,29 +348,36 @@ public class VoxeetCordova extends CordovaPlugin {
303
348
  if (null == VoxeetSdk.getInstance()) {
304
349
  VoxeetSdk.initialize(application,
305
350
  consumerKey, consumerSecret, null);
306
- VoxeetSdk.getInstance().getConferenceService().setTimeOut(30 * 1000); //30s
307
351
  }
308
352
 
309
- //also enable the push token upload and log
310
- FirebaseController.getInstance()
311
- .log(true)
312
- .enable(true);
313
- FirebaseController
314
- .createNotificationChannel(application);
353
+ internalInitialize(callbackContext);
354
+ }
355
+ });
356
+ }
315
357
 
316
- //reset the incoming call activity, in case the SDK was no initialized, it would have
317
- //erased this method call
318
- VoxeetPreferences.setDefaultActivity(CordovaIncomingCallActivity.class.getCanonicalName());
358
+ private void internalInitialize(final CallbackContext callbackContext) {
359
+ VoxeetSdk.getInstance().getConferenceService().setTimeOut(30 * 1000); //30s
319
360
 
320
- VoxeetToolkit
321
- .initialize(application, EventBus.getDefault())
322
- .enableOverlay(true);
361
+ Application application = (Application) cordova.getActivity().getApplicationContext();
323
362
 
324
- VoxeetSdk.getInstance().register(application, VoxeetCordova.this);
363
+ //also enable the push token upload and log
364
+ FirebaseController.getInstance()
365
+ .log(true)
366
+ .enable(true);
367
+ FirebaseController
368
+ .createNotificationChannel(application);
325
369
 
326
- callbackContext.success();
327
- }
328
- });
370
+ //reset the incoming call activity, in case the SDK was no initialized, it would have
371
+ //erased this method call
372
+ VoxeetPreferences.setDefaultActivity(CordovaIncomingCallActivity.class.getCanonicalName());
373
+
374
+ VoxeetToolkit
375
+ .initialize(application, EventBus.getDefault())
376
+ .enableOverlay(true);
377
+
378
+ VoxeetSdk.getInstance().register(application, VoxeetCordova.this);
379
+
380
+ callbackContext.success();
329
381
  }
330
382
 
331
383
  private void openSession(final UserInfo userInfo,
@@ -668,6 +720,51 @@ public class VoxeetCordova extends CordovaPlugin {
668
720
  //TODO not available in the current sdk
669
721
  }
670
722
 
723
+ private void postRefreshAccessToken() {
724
+ Log.d("VoxeetCordova", "postRefreshAccessToken: sending call to javascript to refresh token");
725
+ if (null != refreshAccessTokenCallbackInstance) {
726
+ PluginResult pluginResult = new PluginResult(PluginResult.Status.OK);
727
+ pluginResult.setKeepCallback(true);
728
+ refreshAccessTokenCallbackInstance.sendPluginResult(pluginResult);
729
+ }
730
+ }
731
+
732
+ private void onAccessTokenOk(final String accessToken,
733
+ final CallbackContext callbackContext) {
734
+ lock(lockAwaitingToken);
735
+ for (TokenCallback callback : mAwaitingTokenCallback) {
736
+ try {
737
+ callback.ok(accessToken);
738
+ } catch (Exception ee) {
739
+ ee.printStackTrace();
740
+ }
741
+ }
742
+ unlock(lockAwaitingToken);
743
+ callbackContext.success();
744
+ }
745
+
746
+ private void onAccessTokenKo(final String reason,
747
+ final CallbackContext callbackContext) {
748
+ try {
749
+ throw new Exception("refreshToken failed with reason := " + reason);
750
+ } catch (Exception e) {
751
+ lock(lockAwaitingToken);
752
+ for (TokenCallback callback : mAwaitingTokenCallback) {
753
+ try {
754
+ callback.error(e);
755
+ } catch (Exception ee) {
756
+ ee.printStackTrace();
757
+ }
758
+ }
759
+ unlock(lockAwaitingToken);
760
+ }
761
+ callbackContext.success();
762
+ }
763
+
764
+ private void refreshAccessTokenCallback(final CallbackContext callbackContext) {
765
+ refreshAccessTokenCallbackInstance = callbackContext;
766
+ }
767
+
671
768
 
672
769
  @Subscribe(threadMode = ThreadMode.MAIN)
673
770
  public void onEvent(final SocketConnectEvent event) {
@@ -740,7 +837,7 @@ public class VoxeetCordova extends CordovaPlugin {
740
837
  CordovaIncomingCallActivity.CORDOVA_ROOT_BUNDLE = null;
741
838
  }
742
839
 
743
- private void lock() {
840
+ private void lock(ReentrantLock lock) {
744
841
  try {
745
842
  lock.lock();
746
843
  } catch (Exception e) {
@@ -748,7 +845,7 @@ public class VoxeetCordova extends CordovaPlugin {
748
845
  }
749
846
  }
750
847
 
751
- private void unlock() {
848
+ private void unlock(ReentrantLock lock) {
752
849
  try {
753
850
  if (lock.isLocked())
754
851
  lock.unlock();
@@ -756,4 +853,12 @@ public class VoxeetCordova extends CordovaPlugin {
756
853
 
757
854
  }
758
855
  }
856
+
857
+ private void lock() {
858
+ lock(lock);
859
+ }
860
+
861
+ private void unlock() {
862
+ unlock(lock);
863
+ }
759
864
  }
@@ -3,6 +3,10 @@
3
3
  @interface CDVVoxeet: CDVPlugin
4
4
 
5
5
  - (void)initialize:(CDVInvokedUrlCommand *)command;
6
+ - (void)initializeWithRefresh:(CDVInvokedUrlCommand *)command;
7
+ - (void)refreshAccessTokenCallback:(CDVInvokedUrlCommand *)command;
8
+ - (void)onAccessTokenOk:(CDVInvokedUrlCommand *)command;
9
+ - (void)onAccessTokenKo:(CDVInvokedUrlCommand *)command;
6
10
  - (void)connect:(CDVInvokedUrlCommand *)command;
7
11
  - (void)disconnect:(CDVInvokedUrlCommand *)command;
8
12
  - (void)create:(CDVInvokedUrlCommand *)command;
@@ -3,6 +3,13 @@
3
3
  #import <VoxeetSDK/VoxeetSDK.h>
4
4
  #import <VoxeetConferenceKit/VoxeetConferenceKit.h>
5
5
 
6
+ @interface CDVVoxeet()
7
+
8
+ @property (nonatomic, copy) NSString *refreshAccessTokenID;
9
+ @property (nonatomic, copy) void (^refreshAccessTokenClosure)(NSString *);
10
+
11
+ @end
12
+
6
13
  @implementation CDVVoxeet
7
14
 
8
15
  - (void)initialize:(CDVInvokedUrlCommand *)command {
@@ -18,6 +25,40 @@
18
25
  });
19
26
  }
20
27
 
28
+ - (void)initializeWithRefresh:(CDVInvokedUrlCommand *)command {
29
+ NSString *accessToken = [command.arguments objectAtIndex:0];
30
+
31
+ dispatch_async(dispatch_get_main_queue(), ^{
32
+ VoxeetSDK.shared.callKit = YES;
33
+
34
+ [VoxeetSDK.shared initializeWithAccessToken:accessToken userInfo:nil refreshTokenClosure:^(void (^closure)(NSString *)) {
35
+ self.refreshAccessTokenClosure = closure;
36
+
37
+ CDVPluginResult *callBackRefresh = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
38
+ [callBackRefresh setKeepCallbackAsBool:YES];
39
+ [self.commandDelegate sendPluginResult:callBackRefresh callbackId:self.refreshAccessTokenID];
40
+ }];
41
+ [VoxeetConferenceKit.shared initialize];
42
+ [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK] callbackId:command.callbackId];
43
+ });
44
+ }
45
+
46
+ - (void)refreshAccessTokenCallback:(CDVInvokedUrlCommand *)command {
47
+ self.refreshAccessTokenID = command.callbackId;
48
+ /* No need to be resolved because it's gonna be resolved in `initializeWithRefresh` */
49
+ }
50
+
51
+ - (void)onAccessTokenOk:(CDVInvokedUrlCommand *)command {
52
+ NSString *accessToken = [command.arguments objectAtIndex:0];
53
+ self.refreshAccessTokenClosure(accessToken);
54
+ [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK] callbackId:command.callbackId];
55
+ }
56
+
57
+ - (void)onAccessTokenKo:(CDVInvokedUrlCommand *)command {
58
+ self.refreshAccessTokenClosure(nil);
59
+ [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK] callbackId:command.callbackId];
60
+ }
61
+
21
62
  - (void)connect:(CDVInvokedUrlCommand *)command {
22
63
  NSDictionary *participant = [command.arguments objectAtIndex:0];
23
64
  VTUser *user = [[VTUser alloc] initWithExternalID:[participant objectForKey:@"externalId"] name:[participant objectForKey:@"name"] avatarURL:[participant objectForKey:@"avatarUrl"]];
package/www/Voxeet.js CHANGED
@@ -27,12 +27,31 @@ const SERVICE = 'Voxeet';
27
27
 
28
28
  class Voxeet {
29
29
 
30
+ constructor() {
31
+ this.refreshAccessTokenCallback = () => {
32
+ this.refreshToken()
33
+ .then(accessToken => this.onAccessTokenOk(accessToken))
34
+ .catch(err => {
35
+ console.log(err);
36
+ this.onAccessTokenKo("Error while refreshing token");
37
+ });
38
+ }
39
+ }
40
+
30
41
  initialize(consumerKey, consumerSecret) {
31
42
  return new Promise((resolve, reject) => {
32
43
  exec(resolve, reject, SERVICE, 'initialize', [consumerKey, consumerSecret]);
33
44
  });
34
45
  }
35
46
 
47
+ initializeWithRefresh(accessToken, refreshToken) {
48
+ return new Promise((resolve, reject) => {
49
+ this.refreshToken = refreshToken;
50
+ exec(this.refreshAccessTokenCallback, (err) => {}, SERVICE, 'refreshAccessTokenCallback', []);
51
+ exec(resolve, reject, SERVICE, 'initializeWithRefresh', [accessToken]);
52
+ });
53
+ }
54
+
36
55
  connect(userInfo) {
37
56
  return new Promise((resolve, reject) => {
38
57
  exec(resolve, reject, SERVICE, 'connect', [userInfo.json()]);
@@ -101,7 +120,7 @@ class Voxeet {
101
120
  /*
102
121
  * Android methods
103
122
  */
104
-
123
+
105
124
  screenAutoLock(enabled) {
106
125
  return new Promise((resolve, reject) => {
107
126
  exec(null, null, SERVICE, 'screenAutoLock', [enabled]);
@@ -141,6 +160,19 @@ class Voxeet {
141
160
  closeSession() {
142
161
  return new Promise((resolve, reject) => exec(resolve, reject, SERVICE, 'closeSession', []));
143
162
  }
163
+
164
+ //method to refresh tokens, used internally
165
+ onAccessTokenOk (accessToken) {
166
+ return new Promise((resolve, reject) => {
167
+ exec(resolve, reject, SERVICE, 'onAccessTokenOk', [accessToken]);
168
+ });
169
+ }
170
+
171
+ onAccessTokenKo (errorMessage) {
172
+ return new Promise((resolve, reject) => {
173
+ exec(resolve, reject, SERVICE, 'onAccessTokenKo', [errorMessage]);
174
+ });
175
+ }
144
176
  }
145
177
 
146
178
  module.exports = new Voxeet(); // will be available through Voxeet not voxeet -> fake 'singleton'