Skip to content

Commit 5c265e5

Browse files
authored
Merge pull request #26 from JoaoCaixinha/master
added getIsConnected
2 parents 90344f4 + 2aaa4f8 commit 5c265e5

File tree

7 files changed

+30
-4
lines changed

7 files changed

+30
-4
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ Push Notifications only work in real devices for the iOS platform (not on simula
5454
* **disconnect(callback())**
5555

5656
This method is used to disconnect the ORTC connection.
57+
58+
* **getIsConnected(callback(state))**
59+
60+
Gets ortc client connection state.
61+
Returns callback state 0 if not connected and 1 connected.
5762

5863
* callback() - is triggered after connection is disconnected.
5964
* **subscribe(channel, callback())**

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cordovapush",
3-
"version": "0.1.28",
3+
"version": "0.1.29",
44
"description": "This Cordova plugin should be used with the iOS/Android platforms together with the Realtime Messaging library (ORTC) for Push Notifications support.",
55
"main": "index.js",
66
"scripts": {

plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
33
id="co.realtime.plugins.CordovaPush"
4-
version="0.1.28">
4+
version="0.1.29">
55

66
<name>cordovapush</name>
77
<author>Reatime</author>

src/android/OrtcPushPlugin.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class OrtcPushPlugin extends CordovaPlugin {
4242
public static final String ACTION_SEND_MESSAGE = "send";
4343
private static final String ACTION_ENABLE_HEADS_UP_NOTIFICATIONS = "enableHeadsUpNotifications";
4444
private static final String ACTION_DISABLE_HEADS_UP_NOTIFICATIONS = "disableHeadsUpNotifications";
45+
private static final String ACTION_GET_CONNECTION_STATE = "getIsConnected";
4546
private OrtcClient client;
4647
private static CordovaWebView gWebView;
4748
private static Bundle gCachedExtras = null;
@@ -78,7 +79,9 @@ public void run(OrtcClient ortcClient) {
7879
client.onDisconnected = new OnDisconnected() {
7980
@Override
8081
public void run(OrtcClient ortcClient) {
81-
Log.i(TAG,"Disconnected" );
82+
CallbackContext call = (CallbackContext)commands.get(ACTION_DISCONNECT);
83+
if (call != null)
84+
call.success();
8285
}
8386
};
8487

@@ -101,7 +104,6 @@ public void run(OrtcClient ortcClient, String s) {
101104
}
102105
};
103106

104-
105107
client.onReconnected = new OnReconnected(){
106108
@Override
107109
public void run(OrtcClient sender) {
@@ -158,6 +160,11 @@ public boolean execute(String action, JSONArray args, final CallbackContext call
158160
callbackContext.success();
159161
return true;
160162
}
163+
else if(ACTION_GET_CONNECTION_STATE.equals(action)){
164+
int isConnected = client.getIsConnected()? 1: 0;
165+
callbackContext.success(isConnected);
166+
return true;
167+
}
161168
else if(ACTION_CONNECT.equals(action)){
162169
commands.put(ACTION_CONNECT, callbackContext);
163170
cordova.getThreadPool().execute(new Runnable() {

src/ios/OrtcPushPlugin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- (void)removeNotifications:(CDVInvokedUrlCommand*)command;
2222
- (void)connect:(CDVInvokedUrlCommand*)command;
2323
- (void)disconnect:(CDVInvokedUrlCommand*)command;
24+
- (void)getIsConnected:(CDVInvokedUrlCommand*)command;
2425
- (void)subscribe:(CDVInvokedUrlCommand*)command;
2526
- (void)unsubscribe:(CDVInvokedUrlCommand*)command;
2627
- (void)setApplicationIconBadgeNumber:(CDVInvokedUrlCommand*)command;

src/ios/OrtcPushPlugin.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ - (void)disconnect:(CDVInvokedUrlCommand*)command
4444

4545
}
4646

47+
- (void)getIsConnected:(CDVInvokedUrlCommand*)command
48+
{
49+
[_connectCommand setObject:command forKey:@"getIsConnected"];
50+
CDVPluginResult* pluginResult = nil;
51+
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:[_ortc isConnected]];
52+
[self.commandDelegate sendPluginResult:pluginResult callbackId:[[_connectCommand objectForKey:@"getIsConnected"] callbackId]];
53+
}
54+
55+
4756
- (void)trowException:(NSString*)exception forCommand:(CDVInvokedUrlCommand*)command code:(void (^)(CDVInvokedUrlCommand*))code{
4857
if (!_ortc) {
4958
[[NSNotificationCenter defaultCenter] postNotificationName:@"onException" object:nil userInfo:@{@"exception":exception}];

www/OrtcPlugin.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
cordova.exec(success, success, "OrtcPushPlugin", "connect", config ? [config] : []);
1616
};
1717

18+
OrtcPushPlugin.prototype.getIsConnected = function(success) {
19+
cordova.exec(success, success, "OrtcPushPlugin", "getIsConnected", []);
20+
};
21+
1822
OrtcPushPlugin.prototype.enableHeadsUpNotifications = function(config, success) {
1923
cordova.exec(success, success, "OrtcPushPlugin", "enableHeadsUpNotifications", []);
2024
};

0 commit comments

Comments
 (0)