@fishjam-cloud/react-native-client 0.2.4 → 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 (108) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +9 -8
  3. package/android/build.gradle +4 -4
  4. package/android/src/main/java/io/fishjam/reactnative/EmitableEvents.kt +25 -12
  5. package/android/src/main/java/io/fishjam/reactnative/Errors.kt +1 -2
  6. package/android/src/main/java/io/fishjam/reactnative/RNFishjamClient.kt +94 -52
  7. package/android/src/main/java/io/fishjam/reactnative/RNFishjamClientModule.kt +42 -90
  8. package/android/src/main/java/io/fishjam/reactnative/VideoPreviewView.kt +14 -3
  9. package/android/src/main/java/io/fishjam/reactnative/VideoPreviewViewModule.kt +5 -0
  10. package/android/src/main/java/io/fishjam/reactnative/VideoRendererView.kt +4 -3
  11. package/android/src/main/java/io/fishjam/reactnative/VideoRendererViewModule.kt +2 -0
  12. package/android/src/main/java/io/fishjam/reactnative/VideoView.kt +3 -2
  13. package/android/src/main/java/io/fishjam/reactnative/{FishjamForegroundService.kt → foregroundService/FishjamForegroundService.kt} +7 -2
  14. package/android/src/main/java/io/fishjam/reactnative/foregroundService/ForegroundServiceManager.kt +147 -0
  15. package/android/src/main/java/io/fishjam/reactnative/managers/LocalCameraTracksChangedListenersManager.kt +21 -0
  16. package/android/src/main/java/io/fishjam/reactnative/managers/LocalTracksSwitchListenersManager.kt +27 -0
  17. package/android/src/main/java/io/fishjam/reactnative/managers/TracksUpdateListenersManager.kt +21 -0
  18. package/android/src/main/java/io/fishjam/reactnative/utils/PermissionUtils.kt +45 -0
  19. package/build/RNFishjamClientModule.d.ts +16 -10
  20. package/build/RNFishjamClientModule.d.ts.map +1 -1
  21. package/build/RNFishjamClientModule.js.map +1 -1
  22. package/build/common/client.d.ts +3 -3
  23. package/build/common/client.d.ts.map +1 -1
  24. package/build/common/client.js +4 -4
  25. package/build/common/client.js.map +1 -1
  26. package/build/common/metadata.d.ts +3 -3
  27. package/build/common/metadata.d.ts.map +1 -1
  28. package/build/common/metadata.js +4 -4
  29. package/build/common/metadata.js.map +1 -1
  30. package/build/common/webRTC.d.ts +0 -8
  31. package/build/common/webRTC.d.ts.map +1 -1
  32. package/build/common/webRTC.js +0 -9
  33. package/build/common/webRTC.js.map +1 -1
  34. package/build/components/VideoRendererView.d.ts +1 -1
  35. package/build/components/VideoRendererView.js +1 -1
  36. package/build/components/VideoRendererView.js.map +1 -1
  37. package/build/debug/common/webRTC.d.ts +9 -0
  38. package/build/debug/common/webRTC.d.ts.map +1 -0
  39. package/build/debug/common/webRTC.js +11 -0
  40. package/build/debug/common/webRTC.js.map +1 -0
  41. package/build/debug/index.d.ts +4 -0
  42. package/build/debug/index.d.ts.map +1 -0
  43. package/build/debug/index.js +3 -0
  44. package/build/debug/index.js.map +1 -0
  45. package/build/debug/stats/types.d.ts.map +1 -0
  46. package/build/debug/stats/types.js.map +1 -0
  47. package/build/debug/stats/useRTCStatistics.d.ts.map +1 -0
  48. package/build/{stats → debug/stats}/useRTCStatistics.js +1 -1
  49. package/build/debug/stats/useRTCStatistics.js.map +1 -0
  50. package/build/hooks/useAppScreenShare.d.ts +11 -0
  51. package/build/hooks/useAppScreenShare.d.ts.map +1 -0
  52. package/build/hooks/useAppScreenShare.js +54 -0
  53. package/build/hooks/useAppScreenShare.js.map +1 -0
  54. package/build/hooks/useFishjamEvent.d.ts +2 -0
  55. package/build/hooks/useFishjamEvent.d.ts.map +1 -1
  56. package/build/hooks/useFishjamEvent.js +2 -0
  57. package/build/hooks/useFishjamEvent.js.map +1 -1
  58. package/build/hooks/useForegroundService.d.ts +44 -0
  59. package/build/hooks/useForegroundService.d.ts.map +1 -0
  60. package/build/hooks/useForegroundService.js +57 -0
  61. package/build/hooks/useForegroundService.js.map +1 -0
  62. package/build/hooks/useMicrophone.d.ts +1 -1
  63. package/build/hooks/useMicrophone.js +1 -1
  64. package/build/hooks/useMicrophone.js.map +1 -1
  65. package/build/hooks/usePeerStatus.d.ts +19 -0
  66. package/build/hooks/usePeerStatus.d.ts.map +1 -0
  67. package/build/hooks/usePeerStatus.js +18 -0
  68. package/build/hooks/usePeerStatus.js.map +1 -0
  69. package/build/hooks/{useParticipants.d.ts → usePeers.d.ts} +11 -11
  70. package/build/hooks/usePeers.d.ts.map +1 -0
  71. package/build/hooks/usePeers.js +34 -0
  72. package/build/hooks/usePeers.js.map +1 -0
  73. package/build/hooks/useScreenShare.d.ts +1 -0
  74. package/build/hooks/useScreenShare.d.ts.map +1 -1
  75. package/build/hooks/useScreenShare.js +20 -13
  76. package/build/hooks/useScreenShare.js.map +1 -1
  77. package/build/index.d.ts +8 -7
  78. package/build/index.d.ts.map +1 -1
  79. package/build/index.js +5 -5
  80. package/build/index.js.map +1 -1
  81. package/build/types.d.ts +0 -25
  82. package/build/types.d.ts.map +1 -1
  83. package/build/types.js +1 -10
  84. package/build/types.js.map +1 -1
  85. package/debug/package.json +4 -0
  86. package/ios/Events.swift +30 -13
  87. package/ios/RNFishjamClient.podspec +1 -1
  88. package/ios/RNFishjamClient.swift +196 -106
  89. package/ios/RNFishjamClientModule.swift +34 -34
  90. package/ios/VideoPreviewView.swift +26 -12
  91. package/ios/VideoRendererView.swift +5 -14
  92. package/package.json +7 -6
  93. package/plugin/build/withFishjamAndroid.js +1 -1
  94. package/plugin/build/withFishjamIos.js +2 -2
  95. package/build/hooks/useParticipants.d.ts.map +0 -1
  96. package/build/hooks/useParticipants.js +0 -34
  97. package/build/hooks/useParticipants.js.map +0 -1
  98. package/build/stats/types.d.ts.map +0 -1
  99. package/build/stats/types.js.map +0 -1
  100. package/build/stats/useRTCStatistics.d.ts.map +0 -1
  101. package/build/stats/useRTCStatistics.js.map +0 -1
  102. package/build/utils/foregroundService.d.ts +0 -32
  103. package/build/utils/foregroundService.d.ts.map +0 -1
  104. package/build/utils/foregroundService.js +0 -43
  105. package/build/utils/foregroundService.js.map +0 -1
  106. /package/build/{stats → debug/stats}/types.d.ts +0 -0
  107. /package/build/{stats → debug/stats}/types.js +0 -0
  108. /package/build/{stats → debug/stats}/useRTCStatistics.d.ts +0 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2023 Software Mansion
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -6,23 +6,24 @@
6
6
 
7
7
  # Installation
8
8
 
9
- Check out the [installation](https://fishjam-cloud.github.io/documentation/guide/react-native/installation) section of our docs for the detailed installation instructions.
9
+ Check out the [installation](https://docs.fishjam.io/react-native/installation) section of our docs for the detailed installation instructions.
10
10
 
11
11
  # Documentation
12
12
 
13
- Check out our [documentation](https://fishjam-cloud.github.io/documentation/) on how Fishjam Cloud work and how to integrate our service with your app.
13
+ Check out our [documentation](https://docs.fishjam.io/) on how Fishjam Cloud work and how to integrate our service with your app.
14
14
 
15
- There is also API documentation available.
15
+ There is also [API documentation](https://fishjam-cloud.github.io/mobile-client-sdk/modules/_fishjam_cloud_react_native_client.html) available.
16
16
 
17
17
  # Examples
18
18
 
19
19
  There is simple example app, that allows you to test our service. To run it locally, follow [instructions](https://github.com/fishjam-cloud/mobile-client-sdk/tree/main/examples/fishjam-chat#react-native-fishjam-cloud-example).
20
20
 
21
- ## Copyright and License
21
+ ## License
22
22
 
23
- Copyright 2024,
24
- [Software Mansion](https://swmansion.com/?utm_source=git&utm_medium=readme&utm_campaign=react-client)
23
+ Licensed under the [Apache License, Version 2.0](LICENSE)
25
24
 
26
- [![Software Mansion](https://logo.swmansion.com/logo?color=white&variant=desktop&width=200&tag=react-client)](https://swmansion.com/?utm_source=git&utm_medium=readme&utm_campaign=react-client)
25
+ ## Fishjam Cloud is created by Software Mansion
27
26
 
28
- Licensed under the [Apache License, Version 2.0](LICENSE)
27
+ Since 2012 [Software Mansion](https://swmansion.com) is a software agency with experience in building web and mobile apps. We are Core React Native Contributors and experts in dealing with all kinds of React Native issues. We can help you build your next dream product – [Hire us](https://swmansion.com/contact/projects?utm_source=fishjam&utm_medium=mobile-readme).
28
+
29
+ [![Software Mansion](https://logo.swmansion.com/logo?color=white&variant=desktop&width=200&tag=react-client)](https://swmansion.com/contact/projects?utm_source=fishjam&utm_medium=mobile-readme)
@@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
2
2
  apply plugin: 'kotlin-android'
3
3
  apply plugin: 'maven-publish'
4
4
 
5
- def packageVersion = '0.2.4'
5
+ def packageVersion = '0.4.0'
6
6
 
7
7
  group = 'io.fishjam.reactnative'
8
8
  version = "${packageVersion}"
@@ -55,11 +55,11 @@ afterEvaluate {
55
55
 
56
56
  android {
57
57
  namespace = "io.fishjam.reactnative"
58
- compileSdk(31)
58
+ compileSdk(34)
59
59
 
60
60
  defaultConfig {
61
61
  minSdkVersion safeExtGet("minSdkVersion", 21)
62
- targetSdkVersion safeExtGet("targetSdkVersion", 31)
62
+ targetSdkVersion safeExtGet("targetSdkVersion", 34)
63
63
  versionCode 1
64
64
  versionName "${packageVersion}"
65
65
  }
@@ -86,6 +86,6 @@ dependencies {
86
86
  // update version number when releasing
87
87
  implementation "com.github.fishjam-cloud:mobile-client-sdk:${packageVersion}"
88
88
  }
89
- api 'com.github.davidliu:audioswitch:8edf84ee46cdbc84c2b7725aa8f8d66363e19876'
89
+ implementation 'com.twilio:audioswitch:1.2.0'
90
90
  implementation 'androidx.appcompat:appcompat:1.6.1'
91
91
  }
@@ -1,15 +1,28 @@
1
1
  package io.fishjam.reactnative
2
2
 
3
- object EmitableEvents {
4
- const val IsCameraOn = "IsCameraOn"
5
- const val IsMicrophoneOn = "IsMicrophoneOn"
6
- const val IsScreenShareOn = "IsScreenShareOn"
7
- const val SimulcastConfigUpdate = "SimulcastConfigUpdate"
8
- const val PeersUpdate = "PeersUpdate"
9
- const val AudioDeviceUpdate = "AudioDeviceUpdate"
10
- const val BandwidthEstimation = "BandwidthEstimation"
11
- const val ReconnectionRetriesLimitReached = "ReconnectionRetriesLimitReached"
12
- const val ReconnectionStarted = "ReconnectionStarted"
13
- const val Reconnected = "Reconnected"
14
- const val Warning = "Warning"
3
+ @Suppress("ktlint:standard:enum-entry-name-case")
4
+ enum class PeerStatus {
5
+ connecting,
6
+ connected,
7
+ error,
8
+ idle
9
+ }
10
+
11
+ enum class EmitableEvents {
12
+ IsCameraOn,
13
+ IsMicrophoneOn,
14
+ IsScreenShareOn,
15
+ SimulcastConfigUpdate,
16
+ PeersUpdate,
17
+ AudioDeviceUpdate,
18
+ BandwidthEstimation,
19
+ ReconnectionRetriesLimitReached,
20
+ ReconnectionStarted,
21
+ Reconnected,
22
+ Warning,
23
+ PeerStatusChanged;
24
+
25
+ companion object {
26
+ val allEvents = EmitableEvents.entries.map { it.name }.toTypedArray()
27
+ }
15
28
  }
@@ -11,8 +11,7 @@ class ConnectionError(
11
11
  reason: AuthError
12
12
  ) : CodedException(message = "Connection error: ${reason.error}")
13
13
 
14
- class MissingScreenSharePermission :
15
- CodedException(message = "No permission to start screen share, call handleScreenSharePermission first.")
14
+ class MissingScreenSharePermission : CodedException(message = "No permission to start screen share.")
16
15
 
17
16
  class ClientNotConnectedError : CodedException(message = "Client not connected to server yet. Make sure to call connect() first!")
18
17
 
@@ -27,6 +27,11 @@ import com.twilio.audioswitch.AudioDevice
27
27
  import expo.modules.kotlin.AppContext
28
28
  import expo.modules.kotlin.Promise
29
29
  import expo.modules.kotlin.exception.CodedException
30
+ import io.fishjam.reactnative.foregroundService.ForegroundServiceManager
31
+ import io.fishjam.reactnative.managers.LocalCameraTracksChangedListenersManager
32
+ import io.fishjam.reactnative.managers.LocalTracksSwitchListenersManager
33
+ import io.fishjam.reactnative.managers.TracksUpdateListenersManager
34
+ import io.fishjam.reactnative.utils.PermissionUtils
30
35
  import kotlinx.coroutines.CoroutineScope
31
36
  import kotlinx.coroutines.Dispatchers
32
37
  import kotlinx.coroutines.SupervisorJob
@@ -63,19 +68,22 @@ class RNFishjamClient(
63
68
 
64
69
  var appContext: AppContext? = null
65
70
 
66
- interface OnTrackUpdateListener {
67
- fun onTracksUpdate()
68
- }
69
-
70
- interface OnLocalTrackSwitchListener {
71
- suspend fun onLocalTrackWillSwitch()
71
+ var peerStatus = PeerStatus.idle
72
+ private set(value) {
73
+ field = value
74
+ val event = EmitableEvents.PeerStatusChanged
75
+ emitEvent(event, mapOf(event.name to value))
76
+ }
72
77
 
73
- suspend fun onLocalTrackSwitched()
74
- }
78
+ private var foregroundServiceManager: ForegroundServiceManager? = null
75
79
 
76
80
  companion object {
77
- var onTracksUpdateListeners: MutableList<OnTrackUpdateListener> = mutableListOf()
78
- val onLocalTrackSwitchListener: MutableList<OnLocalTrackSwitchListener> = mutableListOf()
81
+ val trackUpdateListenersManager = TracksUpdateListenersManager()
82
+
83
+ val localTracksSwitchListenerManager = LocalTracksSwitchListenersManager()
84
+
85
+ val localCameraTracksChangedListenersManager = LocalCameraTracksChangedListenersManager()
86
+
79
87
  lateinit var fishjamClient: FishjamClient
80
88
 
81
89
  fun getAllPeers(): List<Peer> {
@@ -228,23 +236,25 @@ class RNFishjamClient(
228
236
  CoroutineScope(Dispatchers.Main).launch {
229
237
  connectPromise?.reject(ConnectionError(reason))
230
238
  connectPromise = null
239
+ peerStatus = PeerStatus.error
231
240
  }
232
241
  }
233
242
 
234
243
  fun joinRoom(
235
244
  url: String,
236
- participantToken: String,
237
- participantMetadata: Map<String, Any>,
245
+ peerToken: String,
246
+ peerMetadata: Map<String, Any>,
238
247
  config: ConnectConfig,
239
248
  promise: Promise
240
249
  ) {
250
+ peerStatus = PeerStatus.connecting
241
251
  connectPromise = promise
242
- localUserMetadata = participantMetadata
252
+ localUserMetadata = mapOf("server" to emptyMap(), "peer" to peerMetadata)
243
253
  fishjamClient.connect(
244
254
  com.fishjamcloud.client.ConnectConfig(
245
255
  url,
246
- participantToken,
247
- participantMetadata,
256
+ peerToken,
257
+ localUserMetadata,
248
258
  ReconnectConfig(
249
259
  config.reconnectConfig.maxAttempts,
250
260
  config.reconnectConfig.initialDelayMs,
@@ -263,7 +273,9 @@ class RNFishjamClient(
263
273
  isScreenShareOn = false
264
274
  isConnected = false
265
275
  isCameraInitialized = false
266
- fishjamClient.leave()
276
+ fishjamClient.leave {
277
+ emitEndpoints()
278
+ }
267
279
  }
268
280
 
269
281
  suspend fun startCamera(config: CameraConfig) {
@@ -271,6 +283,11 @@ class RNFishjamClient(
271
283
  emitWarning("Camera already started. You may only call startCamera once before leaveRoom is called.")
272
284
  return
273
285
  }
286
+ if (!PermissionUtils.requestCameraPermission(appContext)) {
287
+ emitWarning("Camera permission not granted.")
288
+ return
289
+ }
290
+
274
291
  val cameraTrack = createCameraTrack(config)
275
292
  setCameraTrackState(cameraTrack, config.cameraEnabled)
276
293
  emitEndpoints()
@@ -293,9 +310,9 @@ class RNFishjamClient(
293
310
  ) {
294
311
  cameraTrack.setEnabled(isEnabled)
295
312
  isCameraOn = isEnabled
296
- val eventName = EmitableEvents.IsCameraOn
297
- val isCameraOnMap = mapOf(eventName to isEnabled)
298
- emitEvent(eventName, isCameraOnMap)
313
+ val event = EmitableEvents.IsCameraOn
314
+ emitEvent(event, mapOf(event.name to isEnabled))
315
+ localCameraTracksChangedListenersManager.notifyListeners()
299
316
  }
300
317
 
301
318
  fun toggleCamera(): Boolean {
@@ -306,21 +323,24 @@ class RNFishjamClient(
306
323
 
307
324
  suspend fun flipCamera() {
308
325
  ensureVideoTrack()
309
- onLocalTrackSwitchListener.forEach { it.onLocalTrackWillSwitch() }
326
+ localTracksSwitchListenerManager.notifyWillSwitch()
310
327
  getLocalVideoTrack()?.flipCamera()
311
- onLocalTrackSwitchListener.forEach { it.onLocalTrackSwitched() }
328
+ localTracksSwitchListenerManager.notifySwitched()
312
329
  }
313
330
 
314
331
  suspend fun switchCamera(cameraId: String) {
315
332
  ensureVideoTrack()
316
- onLocalTrackSwitchListener.forEach { it.onLocalTrackWillSwitch() }
333
+ localTracksSwitchListenerManager.notifyWillSwitch()
317
334
  getLocalVideoTrack()?.switchCamera(cameraId)
318
- onLocalTrackSwitchListener.forEach {
319
- it.onLocalTrackSwitched()
320
- }
335
+ localTracksSwitchListenerManager.notifySwitched()
321
336
  }
322
337
 
323
338
  private suspend fun startMicrophone() {
339
+ if (!PermissionUtils.requestMicrophonePermission(appContext)) {
340
+ emitWarning("Microphone permission not granted.")
341
+ return
342
+ }
343
+
324
344
  val microphoneTrack = fishjamClient.createAudioTrack(emptyMap())
325
345
  setMicrophoneTrackState(microphoneTrack, true)
326
346
  emitEndpoints()
@@ -332,9 +352,8 @@ class RNFishjamClient(
332
352
  ) {
333
353
  microphoneTrack.setEnabled(isEnabled)
334
354
  isMicrophoneOn = isEnabled
335
- val eventName = EmitableEvents.IsMicrophoneOn
336
- val isMicrophoneOnMap = mapOf(eventName to isEnabled)
337
- emitEvent(eventName, isMicrophoneOnMap)
355
+ val event = EmitableEvents.IsMicrophoneOn
356
+ emitEvent(event, mapOf(event.name to isEnabled))
338
357
  }
339
358
 
340
359
  suspend fun toggleMicrophone(): Boolean {
@@ -361,6 +380,24 @@ class RNFishjamClient(
361
380
  }
362
381
  }
363
382
 
383
+ fun configureForegroundService(config: ForegroundServiceNotificationConfig) {
384
+ if (foregroundServiceManager == null) {
385
+ foregroundServiceManager = ForegroundServiceManager(appContext!!, config)
386
+ }
387
+ }
388
+
389
+ suspend fun startForegroundService(config: ForegroundServicePermissionsConfig) {
390
+ if (foregroundServiceManager == null) {
391
+ throw CodedException("Foreground service not configured.")
392
+ }
393
+
394
+ foregroundServiceManager?.startForegroundService(config)
395
+ }
396
+
397
+ fun stopForegroundService() {
398
+ foregroundServiceManager?.stopForegroundService()
399
+ }
400
+
364
401
  suspend fun toggleScreenShare(screenShareOptions: ScreenShareOptions) {
365
402
  this.screenShareMetadata = screenShareOptions.screenShareMetadata
366
403
  this.screenShareQuality = screenShareOptions.quality
@@ -534,7 +571,8 @@ class RNFishjamClient(
534
571
  fun toggleScreenShareTrackEncoding(encoding: String): Map<String, Any> {
535
572
  ensureScreenShareTrack()
536
573
  getLocalScreenShareTrack()?.let {
537
- screenShareSimulcastConfig = toggleTrackEncoding(encoding, it.id(), screenShareSimulcastConfig)
574
+ screenShareSimulcastConfig =
575
+ toggleTrackEncoding(encoding, it.id(), screenShareSimulcastConfig)
538
576
  }
539
577
  return getSimulcastConfigAsRNMap(screenShareSimulcastConfig)
540
578
  }
@@ -705,8 +743,8 @@ class RNFishjamClient(
705
743
 
706
744
  private fun setScreenShareTrackState(isEnabled: Boolean) {
707
745
  isScreenShareOn = isEnabled
708
- val eventName = EmitableEvents.IsScreenShareOn
709
- emitEvent(eventName, mapOf(eventName to isEnabled))
746
+ val event = EmitableEvents.IsScreenShareOn
747
+ emitEvent(event, mapOf(event.name to isEnabled))
710
748
  }
711
749
 
712
750
  private fun stopScreenShare() {
@@ -725,21 +763,21 @@ class RNFishjamClient(
725
763
  }
726
764
 
727
765
  private fun emitEvent(
728
- eventName: String,
729
- data: Map<String, Any?>
766
+ event: EmitableEvents,
767
+ data: Map<String, Any?> = mapOf()
730
768
  ) {
731
- sendEvent(eventName, data)
769
+ CoroutineScope(Dispatchers.Main).launch {
770
+ sendEvent(event.name, data)
771
+ }
732
772
  }
733
773
 
734
- private fun emitWarning(warning: String) {
735
- val eventName = EmitableEvents.Warning
736
- emitEvent(eventName, mapOf("message" to warning))
774
+ fun emitWarning(warning: String) {
775
+ emitEvent(EmitableEvents.Warning, mapOf("message" to warning))
737
776
  }
738
777
 
739
778
  private fun emitEndpoints() {
740
- val eventName = EmitableEvents.PeersUpdate
741
- val map = mapOf(eventName to getPeers())
742
- emitEvent(eventName, map)
779
+ val event = EmitableEvents.PeersUpdate
780
+ emitEvent(event, mapOf(event.name to getPeers()))
743
781
  }
744
782
 
745
783
  private fun audioDeviceAsRNMap(audioDevice: AudioDevice): Map<String, String?> =
@@ -752,10 +790,11 @@ class RNFishjamClient(
752
790
  audioDevices: List<AudioDevice>,
753
791
  selectedDevice: AudioDevice?
754
792
  ) {
755
- val eventName = EmitableEvents.AudioDeviceUpdate
756
- val map =
793
+ val event = EmitableEvents.AudioDeviceUpdate
794
+ emitEvent(
795
+ event,
757
796
  mapOf(
758
- eventName to
797
+ event.name to
759
798
  mapOf(
760
799
  "selectedDevice" to (
761
800
  if (selectedDevice != null) {
@@ -774,8 +813,7 @@ class RNFishjamClient(
774
813
  }
775
814
  )
776
815
  )
777
-
778
- emitEvent(eventName, map)
816
+ )
779
817
  }
780
818
 
781
819
  private fun getSimulcastConfigAsRNMap(simulcastConfig: SimulcastConfig): Map<String, Any> =
@@ -796,6 +834,7 @@ class RNFishjamClient(
796
834
  connectPromise?.resolve(null)
797
835
  connectPromise = null
798
836
  emitEndpoints()
837
+ peerStatus = PeerStatus.connected
799
838
  }
800
839
  }
801
840
 
@@ -808,7 +847,7 @@ class RNFishjamClient(
808
847
 
809
848
  private fun addOrUpdateTrack(track: Track) {
810
849
  emitEndpoints()
811
- onTracksUpdateListeners.forEach { it.onTracksUpdate() }
850
+ trackUpdateListenersManager.notifyListeners()
812
851
  }
813
852
 
814
853
  override fun onTrackReady(track: Track) {
@@ -846,11 +885,13 @@ class RNFishjamClient(
846
885
  override fun onPeerUpdated(peer: Peer) {}
847
886
 
848
887
  override fun onBandwidthEstimationChanged(estimation: Long) {
849
- val eventName = EmitableEvents.BandwidthEstimation
850
- emitEvent(eventName, mapOf(eventName to estimation.toFloat()))
888
+ val event = EmitableEvents.BandwidthEstimation
889
+ emitEvent(event, mapOf(event.name to estimation.toFloat()))
851
890
  }
852
891
 
853
- override fun onDisconnected() {}
892
+ override fun onDisconnected() {
893
+ peerStatus = PeerStatus.idle
894
+ }
854
895
 
855
896
  override fun onSocketClose(
856
897
  code: Int,
@@ -859,6 +900,7 @@ class RNFishjamClient(
859
900
  CoroutineScope(Dispatchers.Main).launch {
860
901
  connectPromise?.reject(SocketClosedError(code, reason))
861
902
  connectPromise = null
903
+ peerStatus = PeerStatus.error
862
904
  }
863
905
  }
864
906
 
@@ -870,14 +912,14 @@ class RNFishjamClient(
870
912
  }
871
913
 
872
914
  override fun onReconnected() {
873
- emitEvent(EmitableEvents.Reconnected, emptyMap())
915
+ emitEvent(EmitableEvents.Reconnected)
874
916
  }
875
917
 
876
918
  override fun onReconnectionStarted() {
877
- emitEvent(EmitableEvents.ReconnectionStarted, emptyMap())
919
+ emitEvent(EmitableEvents.ReconnectionStarted)
878
920
  }
879
921
 
880
922
  override fun onReconnectionRetriesLimitReached() {
881
- emitEvent(EmitableEvents.ReconnectionRetriesLimitReached, emptyMap())
923
+ emitEvent(EmitableEvents.ReconnectionRetriesLimitReached)
882
924
  }
883
925
  }