-
Notifications
You must be signed in to change notification settings - Fork 9
/
RCTRealtimeMessagingIOS.js
155 lines (122 loc) · 3.96 KB
/
RCTRealtimeMessagingIOS.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// Created by Joao Caixinha on 02/04/15.
// Copyright (c) 2015 Realtime. All rights reserved.
//
/**
* @providesModule RCTRealtimeMessagingIOS
* @flow
*/
'use strict';
import React, { Component } from 'react';
import { NativeModules } from 'react-native';
var RCTDeviceEventEmitter = require('RCTDeviceEventEmitter');
var ortcClient = NativeModules.RealtimeMessaging;
var RTEvents = {};
var instances = 0;
class RCTRealtimeMessagingIOS extends React.Component {
id: String;
constructor(props) {
super(props);
this.id = ""+instances++;
}
RTConnect(config){
ortcClient.connect(config, this.id);
}
RTDisconnect(){
ortcClient.disconnect(this.id);
}
RTSubscribe(channel, subscribeOnReconnect: boolean){
ortcClient.subscribe(channel, subscribeOnReconnect, this.id);
}
RTSubscribeWithFilter(channel, subscribeOnReconnect: boolean, filter){
ortcClient.subscribeWithFilter(channel, subscribeOnReconnect, filter, this.id);
}
RTSubscribeWithNotifications(channel, subscribeOnReconnect: boolean){
ortcClient.subscribeWithNotifications(channel, subscribeOnReconnect, this.id);
}
RTUnsubscribe(channel){
ortcClient.unsubscribe(channel, this.id);
}
RTPublishMessage(channel, message, ttl, callBack){
ortcClient.publish(channel, message, ttl, this.id, callBack);
}
RTSendMessage(message, channel){
ortcClient.sendMessage(message, channel, this.id);
}
RTEnablePresence(aUrl, aIsCluster:boolean, aApplicationKey, aPrivateKey, channel, aMetadata){
ortcClient.enablePresence(aUrl, aIsCluster, aApplicationKey, aPrivateKey, channel, aMetadata, this.id);
}
RTDisablePresence(aUrl, aIsCluster:boolean, aApplicationKey, aPrivateKey, channel, aMetadata){
ortcClient.disablePresence(aUrl, aIsCluster, aApplicationKey, aPrivateKey, channel, this.id);
}
RTPresence(aUrl, aIsCluster:boolean, aApplicationKey, aAuthenticationToken, channel){
ortcClient.presence(aUrl, aIsCluster, aApplicationKey, aAuthenticationToken, channel, this.id);
}
RTIsSubscribed(channel, callBack: Function){
ortcClient.isSubscribed(channel, this.id, callBack);
}
RTSaveAuthentication(url, isCluster, authenticationToken, authenticationTokenIsPrivate, applicationKey, timeToLive, privateKey, permissions, callBack: Function){
ortcClient.saveAuthentication(url, isCluster, authenticationToken, authenticationTokenIsPrivate, applicationKey, timeToLive, privateKey, permissions, this.id, callBack);
}
RTGetHeartbeatTime(callBack: Function){
ortcClient.getHeartbeatTime(this.id, callBack);
}
RTSetHeartbeatTime(newHeartbeatTime){
ortcClient.setHeartbeatTime(newHeartbeatTime, this.id);
}
RTGetHeartbeatFails(callBack: Function){
ortcClient.getHeartbeatFails(this.id, callBack);
}
RTSetHeartbeatFails(newHeartbeatFails){
ortcClient.setHeartbeatFails(newHeartbeatFails, this.id);
}
RTIsHeartbeatActive(callBack: Function){
ortcClient.isHeartbeatActive(this.id, callBack);
}
RTEnableHeartbeat(){
ortcClient.enableHeartbeat(this.id);
}
RTDisableHeartbeat(){
ortcClient.disableHeartbeat(this.id);
}
/*
Events list
- onConnected
- onDisconnect
- onReconnect
- onReconnecting
- onSubscribed
- onUnSubscribed
- onExcption
- onMessage
- onPresence
- onDisablePresence
- onEnablePresence
*/
RTPushNotificationListener(callBack: Function){
require('RCTDeviceEventEmitter').addListener(
'onPushNotification',
callBack
);
ortcClient.checkForNotifications();
};
RTEventListener(notification, callBack: Function){
var modNotification = String(this.id) + '-' + notification;
var channelExists = RTEvents[modNotification];
if (channelExists){
this.RTRemoveEventListener(notification);
}
RTEvents[modNotification] = (
require('RCTDeviceEventEmitter').addListener(
modNotification,
callBack
)
);
};
RTRemoveEventListener(notification)
{
var modNotification = String(this.id) + '-' + notification;
RTEvents[modNotification].remove(),
delete RTEvents[modNotification];
};
}
module.exports = RCTRealtimeMessagingIOS;