├── reactnativemessagingandroid
├── src
│ └── main
│ │ ├── res
│ │ └── values
│ │ │ └── strings.xml
│ │ ├── java
│ │ └── co
│ │ │ └── realtime
│ │ │ └── reactnativemessagingandroid
│ │ │ ├── RealtimeMessagingPackage.java
│ │ │ ├── RealtimePushNotificationActivity.java
│ │ │ ├── GcmReceiver.java
│ │ │ └── RealtimeMessagingAndroid.java
│ │ └── AndroidManifest.xml
├── build.gradle
└── proguard-rules.pro
├── .gitignore
├── package.json
├── LICENSE
├── RCTRealtimeMessagingAndroid.js
└── README.md
/reactnativemessagingandroid/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ReactNativeMessagingAndroid
3 |
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | reactnativemessagingandroid/.idea/.name
2 | reactnativemessagingandroid/.idea/compiler.xml
3 | reactnativemessagingandroid/.idea/encodings.xml
4 | reactnativemessagingandroid/.idea/gradle.xml
5 | reactnativemessagingandroid/.idea/misc.xml
6 | reactnativemessagingandroid/.idea/modules.xml
7 | .idea/.name
8 | .idea/compiler.xml
9 | .idea/encodings.xml
10 | .idea/misc.xml
11 | .idea/modules.xml
12 | .idea/RCTRealtimeMessagingAndroid.iml
13 | .idea/vcs.xml
14 | reactnativemessagingandroid/.gitignore
15 | reactnativemessagingandroid/reactnativemessagingandroid.iml
16 |
17 |
--------------------------------------------------------------------------------
/reactnativemessagingandroid/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.1"
6 |
7 | defaultConfig {
8 | minSdkVersion 16
9 | targetSdkVersion 23
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile "com.facebook.react:react-native:+"
23 | compile 'co.realtime:messaging-android:2.1.+'
24 | }
25 |
--------------------------------------------------------------------------------
/reactnativemessagingandroid/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/admin/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-native-realtimemessaging-android",
3 | "version": "1.1.7",
4 | "description": "The Realtime Framework Cloud Messaging Pub/Sub client for React-Native Android",
5 | "main": "RCTRealtimeMessagingAndroid.js",
6 | "scripts": {
7 | "start": "exit 1"
8 | },
9 | "repository": {
10 | "type": "git",
11 | "url": "https://github.com/realtime-framework/RCTRealtimeMessagingAndroid.git"
12 | },
13 | "keywords": [
14 | "react-component",
15 | "reactnative",
16 | "react-native",
17 | "RealtimeMessaging",
18 | "Realtime",
19 | "Android"
20 | ],
21 | "author": "Realtime",
22 | "license": "MIT",
23 | "bugs": {
24 | "url": "https://github.com/realtime-framework/RCTRealtimeMessagingAndroid/issues"
25 | },
26 | "homepage": "https://github.com/realtime-framework/RCTRealtimeMessagingAndroid"
27 | }
28 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Realtime Framework
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/reactnativemessagingandroid/src/main/java/co/realtime/reactnativemessagingandroid/RealtimeMessagingPackage.java:
--------------------------------------------------------------------------------
1 | package co.realtime.reactnativemessagingandroid;
2 |
3 | import com.facebook.react.ReactPackage;
4 | import com.facebook.react.bridge.JavaScriptModule;
5 | import com.facebook.react.bridge.NativeModule;
6 | import com.facebook.react.bridge.ReactApplicationContext;
7 | import com.facebook.react.uimanager.ViewManager;
8 |
9 | import java.util.Arrays;
10 | import java.util.Collections;
11 | import java.util.List;
12 |
13 | /**
14 | * Created by jcaixinha on 15/09/15.
15 | */
16 | public class RealtimeMessagingPackage implements ReactPackage {
17 | @Override
18 | public List createNativeModules(ReactApplicationContext reactContext) {
19 | return Arrays.asList(new NativeModule[]{new RealtimeMessagingAndroid(reactContext)});
20 | }
21 |
22 | public List> createJSModules() {
23 | return Collections.emptyList();
24 | }
25 |
26 | @Override
27 | public List createViewManagers(ReactApplicationContext reactContext) {
28 | return Collections.emptyList();
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/reactnativemessagingandroid/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
15 |
16 |
17 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/reactnativemessagingandroid/src/main/java/co/realtime/reactnativemessagingandroid/RealtimePushNotificationActivity.java:
--------------------------------------------------------------------------------
1 | package co.realtime.reactnativemessagingandroid;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 |
6 | import com.facebook.react.ReactActivity;
7 |
8 | /**
9 | * Created by jcaixinha on 16/09/15.
10 | */
11 | public class RealtimePushNotificationActivity extends ReactActivity {
12 | private static Activity mainParent;
13 |
14 |
15 | public static Activity getMainParent(){
16 | return mainParent;
17 | }
18 |
19 | @Override
20 | protected String getMainComponentName() {
21 | return null;
22 | }
23 |
24 |
25 | @Override
26 | protected void onCreate(Bundle savedInstanceState) {
27 | mainParent = this;
28 | super.onCreate(savedInstanceState);
29 | this.processPushBundle();
30 | }
31 |
32 |
33 | private void processPushBundle()
34 | {
35 | Bundle extras = getIntent().getExtras();
36 |
37 | if (extras != null) {
38 | Bundle originalExtras = extras.getBundle("pushBundle");
39 |
40 | if(originalExtras != null){
41 | originalExtras.putBoolean("foreground", false);
42 | RealtimeMessagingAndroid.sendExtras(originalExtras);
43 | }
44 | }
45 | }
46 |
47 | @Override
48 | protected void onPause() {
49 | super.onPause();
50 |
51 | if (RealtimeMessagingAndroid.isOnForeground() == true) {
52 | RealtimeMessagingAndroid.setIsOnForeground(false);
53 | }
54 | }
55 |
56 | @Override
57 | protected void onResume() {
58 | super.onResume();
59 |
60 | if (RealtimeMessagingAndroid.isOnForeground() == false) {
61 | RealtimeMessagingAndroid.setIsOnForeground(true);
62 | //this.processPushBundle();
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/reactnativemessagingandroid/src/main/java/co/realtime/reactnativemessagingandroid/GcmReceiver.java:
--------------------------------------------------------------------------------
1 | package co.realtime.reactnativemessagingandroid;
2 |
3 | import android.app.Notification;
4 | import android.app.NotificationManager;
5 | import android.app.PendingIntent;
6 | import android.content.Context;
7 | import android.content.Intent;
8 | import android.os.Bundle;
9 | import android.support.v4.app.NotificationCompat;
10 | import android.util.Log;
11 |
12 | import java.util.Random;
13 |
14 | import ibt.ortc.extensibility.GcmOrtcBroadcastReceiver;
15 |
16 | public class GcmReceiver extends GcmOrtcBroadcastReceiver {
17 |
18 | private static final String TAG = "GcmReceiver";
19 |
20 | public GcmReceiver() {
21 | }
22 |
23 | @Override
24 | public void onReceive(Context context, Intent intent) {
25 | // Extract the payload from the message
26 | Bundle extras = intent.getExtras();
27 | if (extras != null) {
28 | // if we are in the foreground, just surface the payload, else post it to the statusbar
29 | if (RealtimeMessagingAndroid.isOnForeground()) {
30 | extras.putBoolean("foreground", true);
31 | RealtimeMessagingAndroid.sendExtras(extras);
32 | } else {
33 | extras.putBoolean("foreground", false);
34 | // Send a notification if there is a message
35 | if (extras.getString("M") != null && extras.getString("M").length() != 0) {
36 | createNotification(context, extras);
37 | }
38 | }
39 |
40 | }
41 | }
42 |
43 | public void createNotification(Context context, Bundle extras)
44 | {
45 | NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
46 | String appName = getAppName(context);
47 |
48 | String packageName = context.getPackageName();
49 | Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(packageName);
50 | Class className = launchIntent.getComponent().getClass();
51 |
52 | Intent notificationIntent = context.getPackageManager().getLaunchIntentForPackage(packageName);
53 | notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
54 | notificationIntent.putExtra("pushBundle", extras);
55 |
56 | PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
57 |
58 | int defaults = Notification.DEFAULT_ALL;
59 |
60 | if (extras.getString("defaults") != null) {
61 | try {
62 | defaults = Integer.parseInt(extras.getString("defaults"));
63 | } catch (NumberFormatException e) {}
64 | }
65 |
66 | String channel = extras.getString("C");
67 | String message = extras.getString("message");
68 |
69 | NotificationCompat.Builder mBuilder =
70 | new NotificationCompat.Builder(context)
71 | .setDefaults(defaults)
72 | .setSmallIcon(context.getApplicationInfo().icon)
73 | .setWhen(System.currentTimeMillis())
74 | .setContentTitle(context.getString(context.getApplicationInfo().labelRes))
75 | .setContentIntent(contentIntent)
76 | .setAutoCancel(true);
77 |
78 |
79 | if (message != null) {
80 | mBuilder.setContentText(message);
81 | } else {
82 | mBuilder.setContentText("");
83 | }
84 |
85 | int notId = 0;
86 |
87 | try {
88 | notId = new Random().nextInt();
89 | }
90 | catch(NumberFormatException e) {
91 | Log.e(TAG, "Number format exception - Error parsing Notification ID: " + e.getMessage());
92 | }
93 | catch(Exception e) {
94 | Log.e(TAG, "Number format exception - Error parsing Notification ID" + e.getMessage());
95 | }
96 |
97 | mNotificationManager.notify(appName, notId, mBuilder.build());
98 | }
99 |
100 | private static String getAppName(Context context)
101 | {
102 | CharSequence appName =
103 | context
104 | .getPackageManager()
105 | .getApplicationLabel(context.getApplicationInfo());
106 |
107 | return (String)appName;
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/RCTRealtimeMessagingAndroid.js:
--------------------------------------------------------------------------------
1 | // Created by Joao Caixinha on 02/04/15.
2 | // Copyright (c) 2015 Realtime. All rights reserved.
3 | //
4 |
5 | /**
6 | * @providesModule RCTRealtimeMessagingAndroid
7 | * @flow
8 | */
9 |
10 | 'use strict';
11 |
12 | import React, { Component } from 'react';
13 | import { NativeModules } from 'react-native';
14 | var RCTDeviceEventEmitter = require('RCTDeviceEventEmitter');
15 | var ortcClient = NativeModules.RealtimeMessagingAndroid;
16 | var RTEvents = {};
17 | var instances = 0;
18 |
19 | class RCTRealtimeMessagingAndroid extends React.Component {
20 | id: String;
21 |
22 | RCTRealtimeMessagingAndroid(){
23 | this.id = instances++;
24 | }
25 | constructor(props) {
26 | super(props);
27 | this.id = instances++;
28 | }
29 |
30 | RTConnect(config){
31 | ortcClient.connect(config, this.id);
32 | }
33 |
34 | RTDisconnect(){
35 | ortcClient.disconnect(this.id);
36 | }
37 |
38 | RTSubscribe(channel, subscribeOnReconnect: boolean){
39 | ortcClient.subscribe(channel, subscribeOnReconnect, this.id);
40 | }
41 |
42 | RTSubscribeWithFilter(channel, subscribeOnReconnect: boolean, filter){
43 | ortcClient.subscribeWithFilter(channel, subscribeOnReconnect, filter, this.id);
44 | }
45 |
46 | RTSubscribeWithBuffer(channel, subscriberId){
47 | ortcClient.subscribeWithBuffer(channel, subscriberId, this.id);
48 | }
49 |
50 | RTSubscribeWithOptions(options){
51 | ortcClient.subscribeWithOptions(options, this.id);
52 | }
53 |
54 | RTSubscribeWithNotifications(channel, subscribeOnReconnect: boolean){
55 | ortcClient.subscribeWithNotifications(channel, subscribeOnReconnect, this.id);
56 | }
57 |
58 | RTUnsubscribe(channel){
59 | ortcClient.unsubscribe(channel, this.id);
60 | }
61 |
62 | RTPublishMessage(channel, message, ttl, callBack){
63 | ortcClient.publish(channel, message, ttl, this.id, callBack);
64 | }
65 |
66 | RTSendMessage(message, channel){
67 | ortcClient.sendMessage(message, channel, this.id);
68 | }
69 |
70 | RTEnablePresence(aPrivateKey, channel, aMetadata:boolean){
71 | ortcClient.enablePresence(aPrivateKey, channel, aMetadata, this.id);
72 | }
73 |
74 | RTDisablePresence(aPrivateKey, channel){
75 | ortcClient.disablePresence(aPrivateKey, channel, this.id);
76 | }
77 |
78 | RTPresence(channel){
79 | ortcClient.presence(channel, this.id);
80 | }
81 |
82 | RTIsSubscribed(channel, callBack: Function){
83 | ortcClient.isSubscribed(channel, this.id, callBack);
84 | }
85 |
86 | // RTSaveAuthentication(url, isCluster, authenticationToken, authenticationTokenIsPrivate, applicationKey, timeToLive, privateKey, permissions, callBack: Function){
87 | // ortcClient.saveAuthentication(url, isCluster, authenticationToken, authenticationTokenIsPrivate, applicationKey, timeToLive, privateKey, permissions, this.id, callBack);
88 | // }
89 |
90 | RTGetHeartbeatTime(callBack: Function){
91 | ortcClient.getHeartbeatTime(this.id, callBack);
92 | }
93 |
94 | RTSetHeartbeatTime(newHeartbeatTime){
95 | ortcClient.setHeartbeatTime(newHeartbeatTime, this.id);
96 | }
97 |
98 | RTGetHeartbeatFails(callBack: Function){
99 | ortcClient.getHeartbeatFails(this.id, callBack);
100 | }
101 |
102 | RTSetHeartbeatFails(newHeartbeatFails){
103 | ortcClient.setHeartbeatFails(newHeartbeatFails, this.id);
104 | }
105 |
106 | RTIsHeartbeatActive(callBack: Function){
107 | ortcClient.isHeartbeatActive(this.id, callBack);
108 | }
109 |
110 | RTEnableHeartbeat(){
111 | ortcClient.enableHeartbeat(this.id);
112 | }
113 |
114 | RTDisableHeartbeat(){
115 | ortcClient.disableHeartbeat(this.id);
116 | }
117 |
118 | /*
119 | Events list
120 | - onConnected
121 | - onDisconnect
122 | - onReconnect
123 | - onReconnecting
124 | - onSubscribed
125 | - onUnSubscribed
126 | - onExcption
127 | - onMessage
128 | - onPresence
129 | - onDisablePresence
130 | - onEnablePresence
131 | */
132 |
133 | RTPushNotificationListener(callBack: Function){
134 | require('RCTDeviceEventEmitter').addListener(
135 | 'onPushNotification',
136 | callBack
137 | );
138 | ortcClient.checkForNotifications();
139 | };
140 |
141 |
142 | RTEventListener(notification, callBack: Function){
143 | var modNotification = String(this.id) + '-' + notification;
144 | var channelExists = RTEvents[modNotification];
145 | if (channelExists){
146 | this.RTRemoveEventListener(notification);
147 | }
148 |
149 | RTEvents[modNotification] = (
150 | require('RCTDeviceEventEmitter').addListener(
151 | modNotification,
152 | callBack
153 | )
154 | );
155 | };
156 |
157 | RTRemoveEventListener(notification)
158 | {
159 | var modNotification = String(this.id) + '-' + notification;
160 | RTEvents[modNotification].remove(),
161 | delete RTEvents[modNotification];
162 | };
163 | }
164 |
165 | module.exports = RCTRealtimeMessagingAndroid;
166 |
--------------------------------------------------------------------------------
/reactnativemessagingandroid/src/main/java/co/realtime/reactnativemessagingandroid/RealtimeMessagingAndroid.java:
--------------------------------------------------------------------------------
1 | package co.realtime.reactnativemessagingandroid; /**
2 | * Created by jcaixinha on 15/09/15.
3 | */
4 |
5 | import android.annotation.TargetApi;
6 | import android.os.Build;
7 | import android.os.Bundle;
8 | import android.support.annotation.Nullable;
9 | import android.util.Log;
10 |
11 | import com.facebook.react.bridge.Callback;
12 | import com.facebook.react.bridge.ReactApplicationContext;
13 | import com.facebook.react.bridge.ReactContext;
14 | import com.facebook.react.bridge.ReactContextBaseJavaModule;
15 | import com.facebook.react.bridge.ReactMethod;
16 | import com.facebook.react.bridge.ReadableArray;
17 | import com.facebook.react.bridge.ReadableMap;
18 | import com.facebook.react.bridge.ReadableMapKeySetIterator;
19 | import com.facebook.react.bridge.ReadableType;
20 | import com.facebook.react.bridge.WritableMap;
21 | import com.facebook.react.bridge.WritableNativeMap;
22 | import com.facebook.react.modules.core.DeviceEventManagerModule;
23 |
24 | import org.json.JSONException;
25 | import org.json.JSONObject;
26 |
27 | import java.util.ArrayList;
28 | import java.util.HashMap;
29 | import java.util.Iterator;
30 | import java.util.List;
31 | import java.util.Map;
32 | import java.util.Objects;
33 |
34 | import ibt.ortc.api.OnDisablePresence;
35 | import ibt.ortc.api.OnEnablePresence;
36 | import ibt.ortc.api.OnPresence;
37 | import ibt.ortc.api.Ortc;
38 | import ibt.ortc.api.Presence;
39 | import ibt.ortc.extensibility.OnConnected;
40 | import ibt.ortc.extensibility.OnDisconnected;
41 | import ibt.ortc.extensibility.OnException;
42 | import ibt.ortc.extensibility.OnMessage;
43 | import ibt.ortc.extensibility.OnMessageWithBuffer;
44 | import ibt.ortc.extensibility.OnMessageWithFilter;
45 | import ibt.ortc.extensibility.OnMessageWithOptions;
46 | import ibt.ortc.extensibility.OnPublishResult;
47 | import ibt.ortc.extensibility.OnReconnected;
48 | import ibt.ortc.extensibility.OnReconnecting;
49 | import ibt.ortc.extensibility.OnSubscribed;
50 | import ibt.ortc.extensibility.OnUnsubscribed;
51 | import ibt.ortc.extensibility.OrtcClient;
52 | import ibt.ortc.extensibility.OrtcFactory;
53 | import ibt.ortc.extensibility.exception.OrtcNotConnectedException;
54 |
55 |
56 | public class RealtimeMessagingAndroid extends ReactContextBaseJavaModule
57 | {
58 |
59 | private static final String TAG = "" ;
60 | private static Bundle gCachedExtras;
61 | private OrtcClient client;
62 | private HashMap queue;
63 | private ReadableMap config;
64 | private static boolean isOnForeground;
65 | private static RealtimeMessagingAndroid instance;
66 |
67 | public static RealtimeMessagingAndroid instance(){
68 | return instance;
69 | }
70 |
71 | public static void setIsOnForeground(boolean isOnForeground){
72 | RealtimeMessagingAndroid.isOnForeground = isOnForeground;
73 | }
74 |
75 | public static boolean isOnForeground(){
76 | return RealtimeMessagingAndroid.isOnForeground;
77 | }
78 |
79 |
80 |
81 | public RealtimeMessagingAndroid(ReactApplicationContext reactContext){
82 | super(reactContext);
83 | RealtimeMessagingAndroid.instance = this;
84 | queue = new HashMap();
85 | }
86 |
87 | @Override
88 | public String getName() {
89 | return "RealtimeMessagingAndroid";
90 | }
91 |
92 | private void sendEvent(ReactContext reactContext,
93 | String eventName,
94 | @Nullable Object params) {
95 | reactContext
96 | .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
97 | .emit(eventName, params);
98 | }
99 |
100 | @TargetApi(Build.VERSION_CODES.KITKAT)
101 | public static Integer getKeyByValue(Map map, OrtcClient value) {
102 | for (Map.Entry entry : map.entrySet()) {
103 | if (Objects.equals(value, entry.getValue())) {
104 | return entry.getKey();
105 | }
106 | }
107 | return null;
108 | }
109 |
110 |
111 | @ReactMethod
112 | public void connect(ReadableMap config, Integer id){
113 | this.config = config;
114 | if (this.queue == null)
115 | queue = new HashMap();
116 |
117 | if (queue.containsKey(id))
118 | {
119 | client = (OrtcClient)queue.get(id);
120 | }else {
121 | Ortc api = new Ortc();
122 | OrtcFactory factory = null;
123 |
124 | try {
125 | factory = api.loadOrtcFactory("IbtRealtimeSJ");
126 | } catch (InstantiationException e) {
127 | e.printStackTrace();
128 | } catch (IllegalAccessException e) {
129 | e.printStackTrace();
130 | } catch (ClassNotFoundException e) {
131 | e.printStackTrace();
132 | }
133 |
134 | client = factory.createClient();
135 | queue.put(id, client);
136 | }
137 |
138 | client.setApplicationContext(this.getReactApplicationContext());
139 |
140 | if (this.config.hasKey("projectId"))
141 | client.setGoogleProjectId(this.config.getString("projectId"));
142 |
143 | if (this.config.hasKey("connectionMetadata"))
144 | client.setConnectionMetadata(this.config.getString("connectionMetadata"));
145 |
146 | if(this.config.hasKey("clusterUrl")){
147 | client.setClusterUrl(this.config.getString("clusterUrl"));
148 | } else if(this.config.hasKey("url")){
149 | client.setUrl(this.config.getString("url"));
150 | }
151 |
152 | client.onConnected = new OnConnected() {
153 | @Override
154 | public void run(OrtcClient ortcClient) {
155 | String thisId = ""+RealtimeMessagingAndroid.getKeyByValue(queue, ortcClient);
156 | sendEvent(getReactApplicationContext(), thisId + "-onConnected", null);
157 | }
158 | };
159 |
160 | client.onDisconnected = new OnDisconnected() {
161 | @Override
162 | public void run(OrtcClient ortcClient) {
163 | String thisId = ""+RealtimeMessagingAndroid.getKeyByValue(queue, ortcClient);
164 | sendEvent(getReactApplicationContext(), thisId + "-onDisconnected", null);
165 | }
166 | };
167 |
168 | client.onException = new OnException() {
169 | @Override
170 | public void run(OrtcClient ortcClient, Exception e) {
171 | WritableMap params = new WritableNativeMap();
172 | params.putString("error", e.toString());
173 | String thisId = ""+RealtimeMessagingAndroid.getKeyByValue(queue, ortcClient);
174 | sendEvent(getReactApplicationContext(), thisId + "-onException", params);
175 | }
176 | };
177 |
178 | client.onSubscribed = new OnSubscribed() {
179 | @Override
180 | public void run(OrtcClient ortcClient, String s) {
181 | checkForNotifications();
182 | WritableMap params = new WritableNativeMap();
183 | params.putString("channel", s);
184 | String thisId = ""+RealtimeMessagingAndroid.getKeyByValue(queue, ortcClient);
185 | sendEvent(getReactApplicationContext(), thisId + "-onSubscribed", params);
186 | }
187 | };
188 |
189 | client.onUnsubscribed = new OnUnsubscribed() {
190 | @Override
191 | public void run(OrtcClient ortcClient, String s) {
192 | WritableMap params = new WritableNativeMap();
193 | params.putString("channel", s);
194 | String thisId = ""+RealtimeMessagingAndroid.getKeyByValue(queue, ortcClient);
195 | sendEvent(getReactApplicationContext(), thisId + "-onUnsubscribed", params);
196 | }
197 | };
198 |
199 | client.onReconnected = new OnReconnected() {
200 | @Override
201 | public void run(OrtcClient ortcClient) {
202 | String thisId = ""+RealtimeMessagingAndroid.getKeyByValue(queue, ortcClient);
203 | sendEvent(getReactApplicationContext(), thisId + "-onReconnected", null);
204 | }
205 | };
206 |
207 | client.onReconnecting = new OnReconnecting() {
208 | @Override
209 | public void run(OrtcClient ortcClient) {
210 | String thisId = ""+RealtimeMessagingAndroid.getKeyByValue(queue, ortcClient);
211 | sendEvent(getReactApplicationContext(), thisId + "-onReconnecting", null);
212 | }
213 | };
214 |
215 | client.connect(this.config.getString("appKey"), this.config.getString("token"));
216 |
217 | }
218 |
219 | @ReactMethod
220 | public void disconnect(Integer id){
221 | OrtcClient client = null;
222 | if (queue.containsKey(id)) {
223 | client = queue.get(id);
224 | client.disconnect();
225 | }
226 | }
227 |
228 | private Map recursivelyDeconstructReadableMap(ReadableMap readableMap) {
229 | ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
230 | Map deconstructedMap = new HashMap<>();
231 | while (iterator.hasNextKey()) {
232 | String key = iterator.nextKey();
233 | ReadableType type = readableMap.getType(key);
234 | switch (type) {
235 | case Null:
236 | deconstructedMap.put(key, null);
237 | break;
238 | case Boolean:
239 | deconstructedMap.put(key, readableMap.getBoolean(key));
240 | break;
241 | case Number:
242 | deconstructedMap.put(key, readableMap.getDouble(key));
243 | break;
244 | case String:
245 | deconstructedMap.put(key, readableMap.getString(key));
246 | break;
247 | case Map:
248 | deconstructedMap.put(key, recursivelyDeconstructReadableMap(readableMap.getMap(key)));
249 | break;
250 | case Array:
251 | deconstructedMap.put(key, recursivelyDeconstructReadableArray(readableMap.getArray(key)));
252 | break;
253 | default:
254 | throw new IllegalArgumentException("Could not convert object with key: " + key + ".");
255 | }
256 |
257 | }
258 | return deconstructedMap;
259 | }
260 |
261 | private List