react-native-altibbi 0.1.3 → 0.1.4

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.
@@ -0,0 +1,232 @@
1
+ import { NativeModules, NativeEventEmitter, Platform } from 'react-native';
2
+ const LINKING_ERROR = `The package 'react-native-altibbi' doesn't seem to be linked. Make sure: \n\n` +
3
+ Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
4
+ '- You rebuilt the app after installing the package\n' +
5
+ '- You are not using Expo managed workflow\n';
6
+ const SocketReactNative = NativeModules.SocketReactNative
7
+ ? NativeModules.SocketReactNative
8
+ : new Proxy({}, {
9
+ get() {
10
+ throw new Error(LINKING_ERROR);
11
+ },
12
+ });
13
+ var SocketEventName;
14
+ (function (SocketEventName) {
15
+ SocketEventName["ON_AUTHORIZER"] = "SocketReactNative:onAuthorizer";
16
+ SocketEventName["ON_CONNECTION_STATE_CHANGE"] = "SocketReactNative:onConnectionStateChange";
17
+ SocketEventName["ON_SUBSCRIPTION_ERROR"] = "SocketReactNative:onSubscriptionError";
18
+ SocketEventName["ON_EVENT"] = "SocketReactNative:onEvent";
19
+ SocketEventName["ON_ERROR"] = "SocketReactNative:onError";
20
+ SocketEventName["ON_MEMBER_ADDED"] = "SocketReactNative:onMemberAdded";
21
+ SocketEventName["ON_MEMBER_REMOVED"] = "SocketReactNative:onMemberRemoved";
22
+ })(SocketEventName || (SocketEventName = {}));
23
+ export class TBISocketEvent {
24
+ channelName;
25
+ eventName;
26
+ data;
27
+ userId;
28
+ constructor(args) {
29
+ this.channelName = args.channelName;
30
+ this.eventName = args.eventName;
31
+ this.data = args.data;
32
+ this.userId = args.userId;
33
+ }
34
+ toString() {
35
+ return `{ channelName: ${this.channelName}, eventName: ${this.eventName}, data: ${this.data}, userId: ${this.userId} }`;
36
+ }
37
+ }
38
+ export class TBISocketMember {
39
+ userId;
40
+ userInfo;
41
+ constructor(userId, userInfo) {
42
+ this.userId = userId;
43
+ this.userInfo = userInfo;
44
+ }
45
+ toString() {
46
+ return `{ userId: ${this.userId}, userInfo: ${JSON.stringify(this.userInfo)} }`;
47
+ }
48
+ }
49
+ export class TBISocketChannel {
50
+ channelName;
51
+ members = new Map();
52
+ me;
53
+ subscriptionCount;
54
+ onSubscriptionSucceeded;
55
+ onSubscriptionCount;
56
+ onEvent;
57
+ onMemberAdded;
58
+ onMemberRemoved;
59
+ constructor(args) {
60
+ this.channelName = args.channelName;
61
+ this.onSubscriptionSucceeded = args.onSubscriptionSucceeded;
62
+ this.onEvent = args.onEvent;
63
+ this.onMemberAdded = args.onMemberAdded;
64
+ this.onMemberRemoved = args.onMemberRemoved;
65
+ this.onSubscriptionCount = args.onSubscriptionCount;
66
+ this.me = args.me;
67
+ }
68
+ async unsubscribe() {
69
+ return TBISocket.getInstance().unsubscribe({
70
+ channelName: this.channelName,
71
+ });
72
+ }
73
+ async trigger(event) {
74
+ if (event.channelName !== this.channelName) {
75
+ throw 'Event is not for this channel';
76
+ }
77
+ return TBISocket.getInstance().trigger(event);
78
+ }
79
+ }
80
+ export class TBISocket {
81
+ static instance;
82
+ socketEventEmitter = new NativeEventEmitter(SocketReactNative);
83
+ channels = new Map();
84
+ connectionState = 'DISCONNECTED';
85
+ constructor() { }
86
+ static getInstance() {
87
+ if (!TBISocket.instance) {
88
+ TBISocket.instance = new TBISocket();
89
+ }
90
+ return TBISocket.instance;
91
+ }
92
+ addListener(socketEventName, callback) {
93
+ return this.socketEventEmitter.addListener(socketEventName, callback);
94
+ }
95
+ init(args) {
96
+ this.removeAllListeners();
97
+ this.addListener(SocketEventName.ON_CONNECTION_STATE_CHANGE, (event) => {
98
+ this.connectionState = event.currentState.toUpperCase();
99
+ args.onConnectionStateChange?.(event.currentState.toUpperCase(), event.previousState.toUpperCase());
100
+ });
101
+ this.addListener(SocketEventName.ON_ERROR, (event) => args.onError?.(event.message, event.code, event.error));
102
+ this.addListener(SocketEventName.ON_EVENT, (event) => {
103
+ const channelName = event.channelName;
104
+ const eventName = event.eventName;
105
+ const data = event.data;
106
+ const userId = event.userId;
107
+ const channel = this.channels.get(channelName);
108
+ switch (eventName) {
109
+ case 'socket_internal:subscription_succeeded':
110
+ // Depending on the platform implementation we get json or a Map.
111
+ var decodedData = data instanceof Object ? data : JSON.parse(data);
112
+ for (const _userId in decodedData?.presence?.hash) {
113
+ const userInfo = decodedData?.presence?.hash[_userId];
114
+ var member = new TBISocketMember(_userId, userInfo);
115
+ channel?.members.set(member.userId, member);
116
+ if (_userId === userId && channel) {
117
+ channel.me = member;
118
+ }
119
+ }
120
+ args.onSubscriptionSucceeded?.(channelName, decodedData);
121
+ channel?.onSubscriptionSucceeded?.(decodedData);
122
+ break;
123
+ case 'socket_internal:subscription_count':
124
+ // Depending on the platform implementation we get json or a Map.
125
+ var decodedData = data instanceof Object ? data : JSON.parse(data);
126
+ if (channel) {
127
+ channel.subscriptionCount = decodedData.subscription_count;
128
+ }
129
+ args.onSubscriptionCount?.(channelName, decodedData.subscription_count);
130
+ channel?.onSubscriptionCount?.(decodedData.subscription_count);
131
+ break;
132
+ default:
133
+ const socketEvent = new TBISocketEvent(event);
134
+ args.onEvent?.(socketEvent);
135
+ channel?.onEvent?.(socketEvent);
136
+ break;
137
+ }
138
+ });
139
+ this.addListener(SocketEventName.ON_MEMBER_ADDED, (event) => {
140
+ const user = event.user;
141
+ const channelName = event.channelName;
142
+ var member = new TBISocketMember(user.userId, user.userInfo);
143
+ const channel = this.channels.get(channelName);
144
+ channel?.members.set(member.userId, member);
145
+ args.onMemberAdded?.(channelName, member);
146
+ channel?.onMemberAdded?.(member);
147
+ });
148
+ this.addListener(SocketEventName.ON_MEMBER_REMOVED, (event) => {
149
+ const user = event.user;
150
+ const channelName = event.channelName;
151
+ var member = new TBISocketMember(user.userId, user.userInfo);
152
+ const channel = this.channels.get(channelName);
153
+ channel?.members.delete(member.userId);
154
+ args.onMemberRemoved?.(channelName, member);
155
+ channel?.onMemberRemoved?.(member);
156
+ });
157
+ this.addListener(SocketEventName.ON_AUTHORIZER, async ({ channelName, socketId }) => {
158
+ const data = await args.onAuthorizer?.(channelName, socketId);
159
+ if (data) {
160
+ await SocketReactNative.onAuthorizer(channelName, socketId, data);
161
+ }
162
+ });
163
+ this.addListener(SocketEventName.ON_SUBSCRIPTION_ERROR, async ({ channelName, message, type }) => {
164
+ args.onSubscriptionError?.(channelName, message, type);
165
+ });
166
+ return SocketReactNative.initialize({
167
+ apiKey: args.apiKey,
168
+ cluster: args.cluster,
169
+ authEndpoint: args.authEndpoint,
170
+ useTLS: args.useTLS,
171
+ activityTimeout: args.activityTimeout,
172
+ pongTimeout: args.pongTimeout,
173
+ maxReconnectionAttempts: args.maxReconnectionAttempts,
174
+ maxReconnectGapInSeconds: args.maxReconnectGapInSeconds,
175
+ authorizerTimeoutInSeconds: args.authorizerTimeoutInSeconds,
176
+ authorizer: args.onAuthorizer ? true : false,
177
+ proxy: args.proxy,
178
+ });
179
+ }
180
+ async connect() {
181
+ return await SocketReactNative.connect();
182
+ }
183
+ async disconnect() {
184
+ return await SocketReactNative.disconnect();
185
+ }
186
+ unsubscribeAllChannels() {
187
+ const channelsCopy = new Map(this.channels);
188
+ channelsCopy.forEach((channel) => {
189
+ this.unsubscribe({ channelName: channel.channelName });
190
+ });
191
+ }
192
+ removeAllListeners() {
193
+ this.socketEventEmitter.removeAllListeners(SocketEventName.ON_AUTHORIZER);
194
+ this.socketEventEmitter.removeAllListeners(SocketEventName.ON_ERROR);
195
+ this.socketEventEmitter.removeAllListeners(SocketEventName.ON_EVENT);
196
+ this.socketEventEmitter.removeAllListeners(SocketEventName.ON_MEMBER_ADDED);
197
+ this.socketEventEmitter.removeAllListeners(SocketEventName.ON_MEMBER_REMOVED);
198
+ }
199
+ async reset() {
200
+ this.removeAllListeners();
201
+ this.unsubscribeAllChannels();
202
+ }
203
+ async subscribe(args) {
204
+ const channel = this.channels.get(args.channelName);
205
+ if (channel) {
206
+ return channel;
207
+ }
208
+ const newChannel = new TBISocketChannel(args);
209
+ await SocketReactNative.subscribe(args.channelName);
210
+ this.channels.set(args.channelName, newChannel);
211
+ return newChannel;
212
+ }
213
+ async unsubscribe({ channelName }) {
214
+ await SocketReactNative.unsubscribe(channelName);
215
+ this.channels.delete(channelName);
216
+ }
217
+ async trigger(event) {
218
+ if (event.channelName.startsWith('private-') ||
219
+ event.channelName.startsWith('presence-')) {
220
+ await SocketReactNative.trigger(event.channelName, event.eventName, event.data);
221
+ }
222
+ else {
223
+ throw 'Trigger event is only for private/presence channels';
224
+ }
225
+ }
226
+ async getSocketId() {
227
+ return await SocketReactNative.getSocketId();
228
+ }
229
+ getChannel(channelName) {
230
+ return this.channels.get(channelName);
231
+ }
232
+ }
@@ -0,0 +1,12 @@
1
+ export let TBIConstants = {
2
+ token: '',
3
+ baseURL: '',
4
+ language: 'ar',
5
+ };
6
+ export const init = (token, baseURL, language) => {
7
+ TBIConstants = {
8
+ token,
9
+ baseURL,
10
+ language,
11
+ };
12
+ };
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-native-altibbi",
3
- "version": "0.1.3",
4
- "description": "Altibbi Sdk",
3
+ "version": "0.1.4",
4
+ "description": "React native SDK provides integration for the Altibbi services, including video consultation, text consultation, push Welcome to the React Native SDK for Altibbi services, your comprehensive solution for integrating health consultation services into your React Native applications. This SDK enables video and text consultations, push notifications, and many other features to provide a seamless healthcare experience. project.",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
7
7
  "types": "@types/index.d.ts",
@@ -30,20 +30,22 @@
30
30
  "test": "jest",
31
31
  "typecheck": "tsc --noEmit",
32
32
  "lint": "eslint \"**/*.{js,ts,tsx}\"",
33
- "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib"
33
+ "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
34
+ "build": "tsc"
34
35
  },
35
36
  "keywords": [
36
37
  "react-native",
37
38
  "ios",
38
- "android"
39
+ "android",
40
+ "altibbi"
39
41
  ],
40
- "repository": "https://github.com/altibbi-com/altibb-react-native",
41
- "author": "Altibbi Tech team <mobile@altibbi.com> (https://github.com/altibbi-com/altibb-react-native)",
42
+ "repository": "https://github.com/altibbi-com/altibbi-react-native",
43
+ "author": "Altibbi Tech team <mobile@altibbi.com> (https://github.com/altibbi-com/altibbi-react-native)",
42
44
  "license": "MIT",
43
45
  "bugs": {
44
- "url": "https://github.com/altibbi-com/altibb-react-native/issues"
46
+ "url": "https://github.com/altibbi-com/altibbi-react-native/issues"
45
47
  },
46
- "homepage": "https://github.com/altibbi-com/altibb-react-native/readme",
48
+ "homepage": "https://github.com/altibbi-com/altibbi-react-native/readme",
47
49
  "publishConfig": {
48
50
  "registry": "https://registry.npmjs.org/"
49
51
  },
@@ -76,7 +78,7 @@
76
78
  "react-test-renderer": "18.2.0",
77
79
  "release-it": "^15.0.0",
78
80
  "turbo": "^1.10.7",
79
- "typescript": "^5.0.2"
81
+ "typescript": "^5.3.3"
80
82
  },
81
83
  "resolutions": {
82
84
  "@types/react": "17.0.21"
@@ -16,7 +16,6 @@ Pod::Spec.new do |s|
16
16
  s.source = { :git => "https://bitbucket.org/altibbi/react-native-altibbi-sdk/src/master/.git", :tag => "#{s.version}" }
17
17
  s.dependency 'React'
18
18
  s.dependency 'PusherSwift', '~> 10.1.1'
19
- #s.dependency 'OpenTok','~> 2.21.3'
20
19
  s.dependency 'OTXCFramework','2.26.1'
21
20
 
22
21
  s.source_files = "ios/**/*.{h,m,mm,swift}"
package/src/data.ts CHANGED
@@ -1,4 +1,4 @@
1
- import {
1
+ import type {
2
2
  BloodType,
3
3
  BoolString,
4
4
  GenderType,