react-native-altibbi 0.2.0 → 0.4.0

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.
Files changed (127) hide show
  1. package/android/build.gradle +1 -1
  2. package/android/src/main/java/com/altibbi/OTPublisherLayout.java +2 -1
  3. package/android/src/main/java/com/altibbi/OTPublisherViewManager.java +2 -1
  4. package/android/src/main/java/com/altibbi/OTRN.java +2 -1
  5. package/android/src/main/java/com/altibbi/OTScreenCapturer.java +1 -0
  6. package/android/src/main/java/com/altibbi/OTSessionManager.java +91 -33
  7. package/android/src/main/java/com/altibbi/OTSubscriberLayout.java +0 -1
  8. package/android/src/main/java/com/altibbi/OTSubscriberViewManager.java +2 -1
  9. package/android/src/main/java/com/altibbi/utils/EventUtils.java +1 -1
  10. package/android/src/main/java/com/altibbi/utils/Utils.java +8 -11
  11. package/ios/OTSessionManager.m +7 -4
  12. package/ios/OTSessionManager.swift +156 -80
  13. package/ios/Utils/EventUtils.swift +51 -12
  14. package/ios/Utils/Utils.swift +21 -12
  15. package/lib/commonjs/connection.js +157 -8
  16. package/lib/commonjs/connection.js.map +1 -1
  17. package/lib/commonjs/index.js +30 -0
  18. package/lib/commonjs/index.js.map +1 -1
  19. package/lib/commonjs/scoket.js.map +1 -1
  20. package/lib/commonjs/service.js +5 -3
  21. package/lib/commonjs/service.js.map +1 -1
  22. package/lib/commonjs/types.js +55 -0
  23. package/lib/commonjs/types.js.map +1 -1
  24. package/lib/commonjs/video/OT.d.js +3 -0
  25. package/lib/commonjs/video/OT.d.js.map +1 -1
  26. package/lib/commonjs/video/OT.js +3 -2
  27. package/lib/commonjs/video/OT.js.map +1 -1
  28. package/lib/commonjs/video/OTError.js.map +1 -1
  29. package/lib/commonjs/video/OTPublisher.d.js +2 -2
  30. package/lib/commonjs/video/OTPublisher.d.js.map +1 -1
  31. package/lib/commonjs/video/OTPublisher.js +27 -7
  32. package/lib/commonjs/video/OTPublisher.js.map +1 -1
  33. package/lib/commonjs/video/OTSession.d.js +2 -1
  34. package/lib/commonjs/video/OTSession.d.js.map +1 -1
  35. package/lib/commonjs/video/OTSession.js +25 -5
  36. package/lib/commonjs/video/OTSession.js.map +1 -1
  37. package/lib/commonjs/video/OTSubscriber.d.js +2 -2
  38. package/lib/commonjs/video/OTSubscriber.d.js.map +1 -1
  39. package/lib/commonjs/video/OTSubscriber.js +20 -4
  40. package/lib/commonjs/video/OTSubscriber.js.map +1 -1
  41. package/lib/commonjs/video/contexts/OTContext.js +1 -1
  42. package/lib/commonjs/video/contexts/OTContext.js.map +1 -1
  43. package/lib/commonjs/video/helpers/OTHelper.js +2 -2
  44. package/lib/commonjs/video/helpers/OTHelper.js.map +1 -1
  45. package/lib/commonjs/video/helpers/OTPublisherHelper.js +47 -8
  46. package/lib/commonjs/video/helpers/OTPublisherHelper.js.map +1 -1
  47. package/lib/commonjs/video/helpers/OTSessionHelper.js +7 -1
  48. package/lib/commonjs/video/helpers/OTSessionHelper.js.map +1 -1
  49. package/lib/commonjs/video/helpers/OTSubscriberHelper.js +1 -1
  50. package/lib/commonjs/video/index.d.js +1 -1
  51. package/lib/commonjs/video/index.d.js.map +1 -1
  52. package/lib/commonjs/video/index.js +1 -1
  53. package/lib/commonjs/video/index.js.map +1 -1
  54. package/lib/module/connection.js +145 -6
  55. package/lib/module/connection.js.map +1 -1
  56. package/lib/module/index.js +1 -1
  57. package/lib/module/index.js.map +1 -1
  58. package/lib/module/scoket.js.map +1 -1
  59. package/lib/module/service.js +5 -3
  60. package/lib/module/service.js.map +1 -1
  61. package/lib/module/types.js +47 -1
  62. package/lib/module/types.js.map +1 -1
  63. package/lib/module/video/OT.d.js +2 -1
  64. package/lib/module/video/OT.d.js.map +1 -1
  65. package/lib/module/video/OT.js +3 -2
  66. package/lib/module/video/OT.js.map +1 -1
  67. package/lib/module/video/OTError.js.map +1 -1
  68. package/lib/module/video/OTPublisher.d.js +1 -1
  69. package/lib/module/video/OTPublisher.d.js.map +1 -1
  70. package/lib/module/video/OTPublisher.js +26 -6
  71. package/lib/module/video/OTPublisher.js.map +1 -1
  72. package/lib/module/video/OTSession.d.js +1 -1
  73. package/lib/module/video/OTSession.d.js.map +1 -1
  74. package/lib/module/video/OTSession.js +25 -5
  75. package/lib/module/video/OTSession.js.map +1 -1
  76. package/lib/module/video/OTSubscriber.d.js +1 -1
  77. package/lib/module/video/OTSubscriber.d.js.map +1 -1
  78. package/lib/module/video/OTSubscriber.js +19 -3
  79. package/lib/module/video/OTSubscriber.js.map +1 -1
  80. package/lib/module/video/helpers/OTHelper.js +1 -1
  81. package/lib/module/video/helpers/OTHelper.js.map +1 -1
  82. package/lib/module/video/helpers/OTPublisherHelper.js +47 -8
  83. package/lib/module/video/helpers/OTPublisherHelper.js.map +1 -1
  84. package/lib/module/video/helpers/OTSessionHelper.js +6 -1
  85. package/lib/module/video/helpers/OTSessionHelper.js.map +1 -1
  86. package/lib/module/video/helpers/OTSubscriberHelper.js +1 -1
  87. package/lib/typescript/src/connection.d.ts +16 -4
  88. package/lib/typescript/src/connection.d.ts.map +1 -1
  89. package/lib/typescript/src/index.d.ts +2 -2
  90. package/lib/typescript/src/index.d.ts.map +1 -1
  91. package/lib/typescript/src/service.d.ts +2 -1
  92. package/lib/typescript/src/service.d.ts.map +1 -1
  93. package/lib/typescript/src/types.d.ts +83 -1
  94. package/lib/typescript/src/types.d.ts.map +1 -1
  95. package/lib/typescript/src/video/OT.d.ts +1 -1
  96. package/lib/typescript/src/video/OT.d.ts.map +1 -1
  97. package/lib/typescript/src/video/OTPublisher.d.ts +7 -1
  98. package/lib/typescript/src/video/OTPublisher.d.ts.map +1 -1
  99. package/lib/typescript/src/video/OTSession.d.ts +3 -1
  100. package/lib/typescript/src/video/OTSession.d.ts.map +1 -1
  101. package/lib/typescript/src/video/OTSubscriber.d.ts +7 -1
  102. package/lib/typescript/src/video/OTSubscriber.d.ts.map +1 -1
  103. package/lib/typescript/src/video/helpers/OTPublisherHelper.d.ts +2 -1
  104. package/lib/typescript/src/video/helpers/OTPublisherHelper.d.ts.map +1 -1
  105. package/lib/typescript/src/video/helpers/OTSessionHelper.d.ts +1 -0
  106. package/lib/typescript/src/video/helpers/OTSessionHelper.d.ts.map +1 -1
  107. package/lib/typescript/src/video/views/OTPublisherView.d.ts.map +1 -1
  108. package/lib/typescript/src/video/views/OTSubscriberView.d.ts.map +1 -1
  109. package/package.json +1 -1
  110. package/react-native-altibbi.podspec +2 -2
  111. package/src/connection.ts +193 -7
  112. package/src/index.tsx +8 -0
  113. package/src/service.ts +4 -1
  114. package/src/types.ts +143 -2
  115. package/src/video/OT.d.ts +5 -14
  116. package/src/video/OT.js +6 -4
  117. package/src/video/OTPublisher.d.ts +16 -10
  118. package/src/video/OTPublisher.js +37 -5
  119. package/src/video/OTSession.d.ts +42 -41
  120. package/src/video/OTSession.js +23 -4
  121. package/src/video/OTSubscriber.d.ts +12 -6
  122. package/src/video/OTSubscriber.js +25 -3
  123. package/src/video/helpers/OTHelper.js +1 -1
  124. package/src/video/helpers/OTPublisherHelper.js +56 -6
  125. package/src/video/helpers/OTSessionHelper.js +7 -0
  126. package/src/video/helpers/OTSubscriberHelper.js +1 -1
  127. package/android/src/main/java/com/altibbi/OTCustomAudioDevice.java +0 -1146
package/src/connection.ts CHANGED
@@ -1,9 +1,17 @@
1
1
  import { TBIConstants } from './service';
2
2
  import type {
3
+ Article,
3
4
  ConsultationType,
4
5
  MediaType,
6
+ PredictSpecialty,
7
+ PredictSummary,
5
8
  ResponseType,
9
+ Soap,
10
+ Transcription,
6
11
  UserType,
12
+ ChatType,
13
+ ChatResponse,
14
+ ChatMessage,
7
15
  } from './types';
8
16
 
9
17
  interface MethodsObject {
@@ -18,7 +26,8 @@ interface ConsultationObject {
18
26
  medium: string;
19
27
  user_id: number;
20
28
  mediaIds?: string[];
21
- parent_consultation_id?: number;
29
+ parent_consultation_id?: number | null;
30
+ forceWhiteLabelingPartnerName?: string | null;
22
31
  }
23
32
 
24
33
  interface RequestParamsInterface {
@@ -29,6 +38,7 @@ interface RequestParamsInterface {
29
38
  type?: string;
30
39
  fileName?: string;
31
40
  download?: boolean;
41
+ isSinaAPI?: boolean;
32
42
  }
33
43
 
34
44
  interface RequestInterface {
@@ -68,8 +78,12 @@ export const request = async ({
68
78
  type,
69
79
  fileName,
70
80
  download,
81
+ isSinaAPI,
71
82
  }: RequestParamsInterface) => {
72
- if (!TBIConstants.baseURL) {
83
+ if (
84
+ !TBIConstants.baseURL ||
85
+ (isSinaAPI && !(TBIConstants.sinaModelEndPoint?.length > 0))
86
+ ) {
73
87
  return {
74
88
  message: 'Add your baseURL to Init',
75
89
  };
@@ -77,12 +91,23 @@ export const request = async ({
77
91
 
78
92
  const headers = {
79
93
  'Content-Type': 'application/json',
80
- 'Authorization': `Bearer ${TBIConstants.token}`,
94
+ 'Authorization': `Bearer ${isSinaAPI ? '' : TBIConstants.token}`,
81
95
  'accept-language': TBIConstants.language,
82
96
  };
83
97
 
84
- let url = `${TBIConstants.baseURL}/v1/${endPoint}`;
98
+ let url = endPoint.includes('rest-api')
99
+ ? endPoint
100
+ : isSinaAPI
101
+ ? `${TBIConstants.sinaModelEndPoint}/${endPoint}`
102
+ : `${TBIConstants.baseURL}/v1/${endPoint}`;
85
103
  let body;
104
+ if (isSinaAPI) {
105
+ if (!data) {
106
+ data = {};
107
+ }
108
+ data.partner = TBIConstants.baseURL;
109
+ data.partnerUser = TBIConstants.token;
110
+ }
86
111
  if (method === Methods.get) {
87
112
  url = url + '?' + new URLSearchParams(data).toString();
88
113
  } else if (path) {
@@ -197,13 +222,13 @@ export const createConsultation = async ({
197
222
  medium,
198
223
  user_id,
199
224
  mediaIds,
200
- parent_consultation_id,
225
+ parent_consultation_id = null,
226
+ forceWhiteLabelingPartnerName = null,
201
227
  }: ConsultationObject): Promise<ResponseType<ConsultationType>> => {
202
228
  if (!question || !medium || !user_id) {
203
229
  throw Error('missing field');
204
230
  }
205
-
206
- const data = {
231
+ let data = {
207
232
  question,
208
233
  medium,
209
234
  user_id,
@@ -213,6 +238,12 @@ export const createConsultation = async ({
213
238
  'chatConfig,chatHistory,voipConfig,videoConfig,recommendation',
214
239
  parent_consultation_id,
215
240
  };
241
+ if (
242
+ forceWhiteLabelingPartnerName &&
243
+ forceWhiteLabelingPartnerName?.length > 3
244
+ ) {
245
+ data.question = `${data.question} ~${forceWhiteLabelingPartnerName}~`;
246
+ }
216
247
  const response: ResponseType<ConsultationType> = await request({
217
248
  method: Methods.post,
218
249
  data,
@@ -379,8 +410,163 @@ export const rateConsultation = async (
379
410
  data: { score },
380
411
  endPoint: `consultations/${consultation_id}/rate`,
381
412
  });
413
+ if (response.status === 200) {
414
+ return response;
415
+ }
416
+ throw Error(JSON.stringify(response));
417
+ };
418
+ export const getPredictSummary = async (
419
+ consultation_id: number
420
+ ): Promise<ResponseType<PredictSummary>> => {
421
+ const response: ResponseType<PredictSummary> = await request({
422
+ method: Methods.get,
423
+ data: {},
424
+ endPoint: `consultations/${consultation_id}/predict-summary`,
425
+ });
426
+ if (response.status === 200) {
427
+ return response;
428
+ }
429
+ throw Error(JSON.stringify(response));
430
+ };
431
+
432
+ export const getSoapSummary = async (
433
+ consultation_id: number
434
+ ): Promise<ResponseType<Soap>> => {
435
+ const response: ResponseType<Soap> = await request({
436
+ method: Methods.get,
437
+ data: {},
438
+ endPoint: `consultations/${consultation_id}/soap-summary`,
439
+ });
440
+ if (response.status === 200) {
441
+ return response;
442
+ }
443
+ throw Error(JSON.stringify(response));
444
+ };
445
+ export const getTranscription = async (
446
+ consultation_id: number
447
+ ): Promise<ResponseType<Transcription>> => {
448
+ const response: ResponseType<Transcription> = await request({
449
+ method: Methods.get,
450
+ data: {},
451
+ endPoint: `consultations/${consultation_id}/transcription`,
452
+ });
453
+ if (response.status === 200) {
454
+ return response;
455
+ }
456
+ throw Error(JSON.stringify(response));
457
+ };
458
+ export const getPredictSpecialty = async (
459
+ consultation_id: number
460
+ ): Promise<ResponseType<PredictSpecialty[]>> => {
461
+ const response: ResponseType<PredictSpecialty[]> = await request({
462
+ method: Methods.get,
463
+ data: {},
464
+ endPoint: `consultations/${consultation_id}/predict-specialty`,
465
+ });
466
+ if (response.status === 200) {
467
+ return response;
468
+ }
469
+ throw Error(JSON.stringify(response));
470
+ };
471
+
472
+ export const getMediaList = async (
473
+ page: number = 1,
474
+ perPage = 20
475
+ ): Promise<ResponseType<ConsultationType[]>> => {
476
+ const response = await request({
477
+ method: Methods.get,
478
+ data: {
479
+ page,
480
+ 'sort': '-id',
481
+ 'per-page': perPage,
482
+ },
483
+ endPoint: `media`,
484
+ });
485
+ if (response.status === 200) {
486
+ return response;
487
+ }
488
+ throw Error(JSON.stringify(response));
489
+ };
490
+
491
+ export const deleteMedia = async (
492
+ mediaId: string
493
+ ): Promise<ResponseType<string>> => {
494
+ const response: ResponseType<string> = await request({
495
+ method: Methods.delete,
496
+ data: {},
497
+ endPoint: `media/${mediaId}`,
498
+ });
382
499
  if (response.status === 204) {
383
500
  return response;
384
501
  }
385
502
  throw Error(JSON.stringify(response));
386
503
  };
504
+
505
+ export const getArticlesList = async (
506
+ subcategoryIds: string[]
507
+ ): Promise<ResponseType<Article[]>> => {
508
+ const response: ResponseType<Article[]> = await request({
509
+ method: Methods.get,
510
+ data: {
511
+ 'filter[sub_category_id][in]': subcategoryIds.join(','),
512
+ 'sort': '-article_id',
513
+ },
514
+ endPoint: `https://rest-api.altibbi.com/active/v1/articles`,
515
+ });
516
+ if (response.status === 204) {
517
+ return response;
518
+ }
519
+ throw Error(JSON.stringify(response));
520
+ };
521
+
522
+ export const createChat = async (): Promise<ResponseType<ChatType>> => {
523
+ const response: ResponseType<ChatType> = await request({
524
+ method: Methods.post,
525
+ endPoint: `chats`,
526
+ isSinaAPI: true,
527
+ });
528
+ if (response.status === 201) {
529
+ return response;
530
+ }
531
+ throw Error(JSON.stringify(response));
532
+ };
533
+
534
+ export const sendSinaMessage = async (
535
+ text: String,
536
+ sessionId: String
537
+ ): Promise<ResponseType<ChatResponse>> => {
538
+ const response: ResponseType<ChatResponse> = await request({
539
+ method: Methods.post,
540
+ endPoint: `chats/${sessionId}/messages`,
541
+ isSinaAPI: true,
542
+ data: {
543
+ text,
544
+ },
545
+ });
546
+ if (response.status === 201) {
547
+ return response;
548
+ }
549
+ throw Error(JSON.stringify(response));
550
+ };
551
+
552
+ export const getSinaChatMessages = async (
553
+ sessionId: string,
554
+ page: number = 1,
555
+ perPage = 20
556
+ ): Promise<ResponseType<ChatMessage[]>> => {
557
+ const response = await request({
558
+ isSinaAPI: true,
559
+ method: Methods.get,
560
+ data: {
561
+ sessionId,
562
+ page,
563
+ 'sort': '-id',
564
+ 'per-page': perPage,
565
+ },
566
+ endPoint: `chats/${sessionId}/messages`,
567
+ });
568
+ if (response.status === 200) {
569
+ return response;
570
+ }
571
+ throw Error(JSON.stringify(response));
572
+ };
package/src/index.tsx CHANGED
@@ -54,6 +54,11 @@ export {
54
54
  cancelConsultation,
55
55
  getPrescription,
56
56
  rateConsultation,
57
+ getMediaList,
58
+ deleteMedia,
59
+ createChat,
60
+ sendSinaMessage,
61
+ getSinaChatMessages,
57
62
  } from './connection';
58
63
 
59
64
  export { TBIConstants, init } from './service';
@@ -92,6 +97,9 @@ export type {
92
97
  RecommendationDoctorReferral,
93
98
  RecommendationPostCallAnswer,
94
99
  ConsultationType,
100
+ ChatType,
101
+ ChatResponse,
102
+ ChatMessage,
95
103
  } from './types';
96
104
  export {
97
105
  materialStatusArray,
package/src/service.ts CHANGED
@@ -2,18 +2,21 @@ interface ConstantObject {
2
2
  token: string;
3
3
  baseURL: string;
4
4
  language: string;
5
+ sinaModelEndPoint: string;
5
6
  }
6
7
 
7
8
  export let TBIConstants: ConstantObject = {
8
9
  token: '',
9
10
  baseURL: '',
10
11
  language: 'ar',
12
+ sinaModelEndPoint: '',
11
13
  };
12
14
 
13
- export const init = (token: string, baseURL: string, language: string) => {
15
+ export const init = (token: string, baseURL: string, language: string, sinaModelEndPoint: string = "") => {
14
16
  TBIConstants = {
15
17
  token,
16
18
  baseURL,
17
19
  language,
20
+ sinaModelEndPoint,
18
21
  };
19
22
  };
package/src/types.ts CHANGED
@@ -80,8 +80,8 @@ interface VoipConfig {
80
80
  api_key?: string;
81
81
  call_id?: string;
82
82
  token?: string;
83
- created_at?: string
84
- updated_at?: string
83
+ created_at?: string;
84
+ updated_at?: string;
85
85
  }
86
86
  interface Recommendation {
87
87
  id?: number;
@@ -175,6 +175,61 @@ interface ConsultationType {
175
175
  socketParams?: SocketParams;
176
176
  doctor_average_rating?: number;
177
177
  }
178
+ interface Transcription {
179
+ transcript: string;
180
+ }
181
+ interface SubCategory {
182
+ sub_category_id: number;
183
+ name_en: string;
184
+ name_ar: string;
185
+ }
186
+
187
+ interface PredictSpecialty {
188
+ specialty_id: number;
189
+ subCategories: SubCategory[];
190
+ }
191
+ interface PredictSummary {
192
+ summary: string;
193
+ }
194
+ interface Soap {
195
+ summary: {
196
+ subjective: {
197
+ symptoms?: string;
198
+ concerns?: string;
199
+ };
200
+ objective: {
201
+ laboratory_results?: string;
202
+ physical_examination_findings?: string;
203
+ };
204
+ assessment: {
205
+ diagnosis?: string;
206
+ differential_diagnosis?: string;
207
+ };
208
+ plan: {
209
+ non_pharmacological_intervention?: string;
210
+ medications?: string;
211
+ referrals?: string;
212
+ follow_up_instructions?: string;
213
+ };
214
+ };
215
+ }
216
+ interface Article {
217
+ article_id: number;
218
+ slug: string;
219
+ sub_category_id: number;
220
+ title: string;
221
+ body: string;
222
+ article_references: string;
223
+ activation_date: string;
224
+ publish_status: string;
225
+ adult_content: boolean;
226
+ featured: boolean;
227
+ date_added: string;
228
+ date_modified: string;
229
+ body_clean: string;
230
+ image_url: string;
231
+ url: string;
232
+ }
178
233
  export type {
179
234
  ResponseType,
180
235
  MediumType,
@@ -202,4 +257,90 @@ export type {
202
257
  RecommendationDoctorReferral,
203
258
  RecommendationPostCallAnswer,
204
259
  ConsultationType,
260
+ Transcription,
261
+ PredictSpecialty,
262
+ PredictSummary,
263
+ Soap,
264
+ Article,
205
265
  };
266
+
267
+ export interface ChatType {
268
+ id?: string;
269
+ created_at?: string;
270
+ updated_at?: string;
271
+ }
272
+
273
+ export interface MessageData {
274
+ contentType: string;
275
+ foundInRag: boolean;
276
+ links: any[];
277
+ }
278
+
279
+ export interface ChatMessage {
280
+ id: number;
281
+ sender: string;
282
+ text: string;
283
+ chatId: string;
284
+ createdAt: Date;
285
+ updatedAt: Date;
286
+ media: any;
287
+ data?: MessageData;
288
+ }
289
+
290
+ export interface ChatResponse {
291
+ userMessage: ChatMessage;
292
+ sinaMessage: ChatMessage;
293
+ }
294
+
295
+ export function parseChatMessage(json: any): ChatMessage {
296
+ return {
297
+ id: json.id,
298
+ sender: json.sender,
299
+ text: json.text,
300
+ chatId: json.chat_id,
301
+ createdAt: new Date(json.created_at),
302
+ updatedAt: new Date(json.updated_at),
303
+ media: json.media,
304
+ data: json.data
305
+ ? {
306
+ contentType: json.data.content_type,
307
+ foundInRag: json.data.found_in_rag,
308
+ links: json.data.links,
309
+ }
310
+ : undefined,
311
+ };
312
+ }
313
+
314
+ export function parseChatResponse(json: any): ChatResponse {
315
+ return {
316
+ userMessage: parseChatMessage(json.user_message),
317
+ sinaMessage: parseChatMessage(json.sina_message),
318
+ };
319
+ }
320
+
321
+ export function serializeChatMessage(msg: ChatMessage): any {
322
+ const base: any = {
323
+ id: msg.id,
324
+ sender: msg.sender,
325
+ text: msg.text,
326
+ chat_id: msg.chatId,
327
+ created_at: msg.createdAt.toISOString(),
328
+ updated_at: msg.updatedAt.toISOString(),
329
+ media: msg.media,
330
+ };
331
+ if (msg.data) {
332
+ base.data = {
333
+ content_type: msg.data.contentType,
334
+ found_in_rag: msg.data.foundInRag,
335
+ links: msg.data.links,
336
+ };
337
+ }
338
+ return base;
339
+ }
340
+
341
+ export function serializeChatResponse(resp: ChatResponse): any {
342
+ return {
343
+ user_message: serializeChatMessage(resp.userMessage),
344
+ sina_message: serializeChatMessage(resp.sinaMessage),
345
+ };
346
+ }
package/src/video/OT.d.ts CHANGED
@@ -1,15 +1,6 @@
1
- declare const OT: any;
2
- declare const nativeEvents: NativeEventEmitter;
3
- declare function checkAndroidPermissions(): Promise<any>;
4
- declare function setNativeEvents(events: any): void;
5
- declare function removeNativeEvents(events: any): void;
1
+ export let OT: any;
2
+ export let nativeEvents: NativeEventEmitter;
3
+ export function checkAndroidPermissions(audioTrack: any, videoTrack: any, isScreenSharing: any): Promise<any>;
4
+ export function setNativeEvents(events: any): void;
5
+ export function removeNativeEvents(events: any): void;
6
6
  import { NativeEventEmitter } from 'react-native';
7
-
8
- // Export the declared types
9
- export {
10
- OT,
11
- nativeEvents,
12
- checkAndroidPermissions,
13
- setNativeEvents,
14
- removeNativeEvents,
15
- };
package/src/video/OT.js CHANGED
@@ -4,10 +4,12 @@ import { each } from 'underscore';
4
4
  const OT = NativeModules.OTSessionManager;
5
5
  const nativeEvents = new NativeEventEmitter(OT);
6
6
 
7
- const checkAndroidPermissions = () => new Promise((resolve, reject) => {
8
- PermissionsAndroid.requestMultiple([
9
- PermissionsAndroid.PERMISSIONS.CAMERA,
10
- PermissionsAndroid.PERMISSIONS.RECORD_AUDIO])
7
+ const checkAndroidPermissions = (audioTrack, videoTrack, isScreenSharing) => new Promise((resolve, reject) => {
8
+ const permissionsToCheck = [
9
+ ... audioTrack ? [PermissionsAndroid.PERMISSIONS.RECORD_AUDIO] : [],
10
+ ... (videoTrack && !isScreenSharing) ? [PermissionsAndroid.PERMISSIONS.CAMERA] : [],
11
+ ];
12
+ PermissionsAndroid.requestMultiple(permissionsToCheck)
11
13
  .then((result) => {
12
14
  const permissionsError = {};
13
15
  permissionsError.permissionsDenied = [];
@@ -1,27 +1,33 @@
1
1
  export default OTPublisher;
2
- declare class OTPublisher extends Component<any, any, any> {
2
+ declare class OTPublisher extends React.Component<any, any, any> {
3
3
  constructor(props: any, context: any);
4
4
  state: {
5
- initError: any;
6
- publisher: any;
5
+ initError: null;
6
+ publisher: null;
7
7
  publisherId: any;
8
8
  };
9
9
  initComponent: () => void;
10
10
  componentEvents: {
11
+ publisherStreamCreated: string;
12
+ publisherStreamDestroyed: string;
11
13
  sessionConnected: string;
12
- };
13
- componentEventsArray: string[];
14
- otrnEventHandler: (event: any) => void;
15
- publisherEvents: {};
16
- sessionConnected: import("react-native").EmitterSubscription;
14
+ } | undefined;
15
+ componentEventsArray: string[] | undefined;
16
+ otrnEventHandler: ((event: any) => void) | undefined;
17
+ publisherEvents: {} | undefined;
18
+ publisherStreamCreated: import("react-native").EmitterSubscription | undefined;
19
+ publisherStreamDestroyed: import("react-native").EmitterSubscription | undefined;
20
+ sessionConnected: import("react-native").EmitterSubscription | undefined;
17
21
  componentDidMount(): void;
18
22
  componentDidUpdate(previousProps: any): void;
19
23
  componentWillUnmount(): void;
20
24
  sessionConnectedHandler: () => void;
21
25
  createPublisher(): void;
22
- initPublisher(): void;
26
+ initPublisher(publisherProperties: any): void;
23
27
  publish(): void;
24
28
  getRtcStatsReport(): void;
29
+ publisherStreamCreatedHandler: (stream: any) => void;
30
+ publisherStreamDestroyedHandler: (stream: any) => void;
25
31
  setVideoTransformers(videoTransformers: any): void;
26
32
  render(): JSX.Element;
27
33
  }
@@ -34,5 +40,5 @@ declare namespace OTPublisher {
34
40
  }
35
41
  export { OTContext as contextType };
36
42
  }
37
- import { Component } from 'react';
43
+ import React from 'react';
38
44
  import OTContext from './contexts/OTContext';
@@ -31,6 +31,8 @@ class OTPublisher extends Component {
31
31
  }
32
32
  initComponent = () => {
33
33
  this.componentEvents = {
34
+ publisherStreamCreated: 'publisherStreamCreated',
35
+ publisherStreamDestroyed: 'publisherStreamDestroyed:',
34
36
  sessionConnected:
35
37
  Platform.OS === 'android'
36
38
  ? 'session:onConnected'
@@ -44,6 +46,14 @@ class OTPublisher extends Component {
44
46
  );
45
47
  setNativeEvents(this.publisherEvents);
46
48
  OT.setJSComponentEvents(this.componentEventsArray);
49
+ this.publisherStreamCreated = nativeEvents.addListener(
50
+ 'publisherStreamCreated',
51
+ stream => this.publisherStreamCreatedHandler(stream)
52
+ );
53
+ this.publisherStreamDestroyed = nativeEvents.addListener(
54
+ 'publisherStreamDestroyed',
55
+ stream => this.publisherStreamDestroyedHandler(stream)
56
+ );
47
57
  if (this.context.sessionId) {
48
58
  this.sessionConnected = nativeEvents.addListener(
49
59
  `${this.context.sessionId}:${this.componentEvents.sessionConnected}`,
@@ -99,20 +109,22 @@ class OTPublisher extends Component {
99
109
  }
100
110
  };
101
111
  createPublisher() {
112
+ const publisherProperties = sanitizeProperties(this.props.properties);
102
113
  if (Platform.OS === 'android') {
103
- checkAndroidPermissions()
114
+ const { audioTrack, videoTrack, videoSource } = publisherProperties;
115
+ const isScreenSharing = (videoSource === 'screen');
116
+ checkAndroidPermissions(audioTrack, videoTrack, isScreenSharing)
104
117
  .then(() => {
105
- this.initPublisher();
118
+ this.initPublisher(publisherProperties);
106
119
  })
107
120
  .catch((error) => {
108
121
  this.otrnEventHandler(error);
109
122
  });
110
123
  } else {
111
- this.initPublisher();
124
+ this.initPublisher(publisherProperties);
112
125
  }
113
126
  }
114
- initPublisher() {
115
- const publisherProperties = sanitizeProperties(this.props.properties);
127
+ initPublisher(publisherProperties) {
116
128
  OT.initPublisher(
117
129
  this.state.publisherId,
118
130
  publisherProperties,
@@ -157,6 +169,26 @@ class OTPublisher extends Component {
157
169
  OT.getRtcStatsReport(this.state.publisherId);
158
170
  }
159
171
 
172
+ publisherStreamCreatedHandler = (stream) => {
173
+ if (
174
+ this.props.eventHandlers
175
+ && this.props.eventHandlers.streamCreated
176
+ && stream.publisherId === this.state.publisherId
177
+ ) {
178
+ this.props.eventHandlers.streamCreated(stream);
179
+ }
180
+ }
181
+
182
+ publisherStreamDestroyedHandler = (stream) => {
183
+ if (
184
+ this.props.eventHandlers
185
+ && this.props.eventHandlers.streamCreated
186
+ && stream.publisherId === this.state.publisherId
187
+ ) {
188
+ this.props.eventHandlers.streamDestroyed(stream);
189
+ }
190
+ }
191
+
160
192
  setVideoTransformers(videoTransformers) {
161
193
  OT.setVideoTransformers(this.state.publisherId, videoTransformers);
162
194
  }