@100mslive/react-native-hms 1.9.9 → 1.9.10

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 (205) hide show
  1. package/android/local.properties +8 -1
  2. package/android/src/main/java/com/reactnativehmssdk/HMSDecoder.kt +2 -0
  3. package/android/src/main/java/com/reactnativehmssdk/HMSManager.kt +61 -2
  4. package/android/src/main/java/com/reactnativehmssdk/HMSRNSDK.kt +10 -3
  5. package/android/src/main/java/com/reactnativehmssdk/Interactivity/HMSInteractivityDecoder.kt +328 -0
  6. package/android/src/main/java/com/reactnativehmssdk/Interactivity/HMSInteractivityHelper.kt +352 -0
  7. package/android/src/main/java/com/reactnativehmssdk/Interactivity/HMSRNInteractivityCenter.kt +184 -0
  8. package/ios/HMSConstants.swift +1 -0
  9. package/ios/HMSDecoder.swift +3 -1
  10. package/ios/HMSInteractivityDecoder.swift +223 -0
  11. package/ios/HMSInteractivityHelper.swift +169 -0
  12. package/ios/HMSManager.m +17 -0
  13. package/ios/HMSManager.swift +30 -1
  14. package/ios/HMSRNInteractivityCenter.swift +89 -0
  15. package/ios/HMSRNSDK.swift +10 -4
  16. package/ios/Hmssdk.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  17. package/ios/Hmssdk.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  18. package/ios/Hmssdk.xcodeproj/project.xcworkspace/xcuserdata/jatinnagar.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  19. package/ios/Hmssdk.xcodeproj/xcuserdata/jatinnagar.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
  20. package/lib/commonjs/classes/HMSInteractivityCenter.js +93 -0
  21. package/lib/commonjs/classes/HMSInteractivityCenter.js.map +1 -0
  22. package/lib/commonjs/classes/HMSInteractivityEncoder.js +33 -0
  23. package/lib/commonjs/classes/HMSInteractivityEncoder.js.map +1 -0
  24. package/lib/commonjs/classes/HMSPermissions.js +4 -0
  25. package/lib/commonjs/classes/HMSPermissions.js.map +1 -1
  26. package/lib/commonjs/classes/HMSPollsListenerActions.js +11 -0
  27. package/lib/commonjs/classes/HMSPollsListenerActions.js.map +1 -0
  28. package/lib/commonjs/classes/HMSSDK.js +8 -0
  29. package/lib/commonjs/classes/HMSSDK.js.map +1 -1
  30. package/lib/commonjs/classes/polls/HMSPoll.js +6 -0
  31. package/lib/commonjs/classes/polls/HMSPoll.js.map +1 -0
  32. package/lib/commonjs/classes/polls/HMSPollCategory.js +12 -0
  33. package/lib/commonjs/classes/polls/HMSPollCategory.js.map +1 -0
  34. package/lib/commonjs/classes/polls/HMSPollCreateParams.js +6 -0
  35. package/lib/commonjs/classes/polls/HMSPollCreateParams.js.map +1 -0
  36. package/lib/commonjs/classes/polls/HMSPollQuestion.js +6 -0
  37. package/lib/commonjs/classes/polls/HMSPollQuestion.js.map +1 -0
  38. package/lib/commonjs/classes/polls/HMSPollQuestionAnswer.js +2 -0
  39. package/lib/commonjs/classes/polls/HMSPollQuestionAnswer.js.map +1 -0
  40. package/lib/commonjs/classes/polls/HMSPollQuestionCreateParams.js +6 -0
  41. package/lib/commonjs/classes/polls/HMSPollQuestionCreateParams.js.map +1 -0
  42. package/lib/commonjs/classes/polls/HMSPollQuestionOption.js +2 -0
  43. package/lib/commonjs/classes/polls/HMSPollQuestionOption.js.map +1 -0
  44. package/lib/commonjs/classes/polls/HMSPollQuestionOptionCreateParams.js +6 -0
  45. package/lib/commonjs/classes/polls/HMSPollQuestionOptionCreateParams.js.map +1 -0
  46. package/lib/commonjs/classes/polls/HMSPollQuestionQuizOptionCreateParams.js +6 -0
  47. package/lib/commonjs/classes/polls/HMSPollQuestionQuizOptionCreateParams.js.map +1 -0
  48. package/lib/commonjs/classes/polls/HMSPollQuestionResponse.js +6 -0
  49. package/lib/commonjs/classes/polls/HMSPollQuestionResponse.js.map +1 -0
  50. package/lib/commonjs/classes/polls/HMSPollQuestionResponseCreateParams.js +6 -0
  51. package/lib/commonjs/classes/polls/HMSPollQuestionResponseCreateParams.js.map +1 -0
  52. package/lib/commonjs/classes/polls/HMSPollQuestionResponseResult.js +2 -0
  53. package/lib/commonjs/classes/polls/HMSPollQuestionResponseResult.js.map +1 -0
  54. package/lib/commonjs/classes/polls/HMSPollQuestionResult.js +2 -0
  55. package/lib/commonjs/classes/polls/HMSPollQuestionResult.js.map +1 -0
  56. package/lib/commonjs/classes/polls/HMSPollQuestionType.js +14 -0
  57. package/lib/commonjs/classes/polls/HMSPollQuestionType.js.map +1 -0
  58. package/lib/commonjs/classes/polls/HMSPollResponsePeerInfo.js +2 -0
  59. package/lib/commonjs/classes/polls/HMSPollResponsePeerInfo.js.map +1 -0
  60. package/lib/commonjs/classes/polls/HMSPollResult.js +6 -0
  61. package/lib/commonjs/classes/polls/HMSPollResult.js.map +1 -0
  62. package/lib/commonjs/classes/polls/HMSPollState.js +13 -0
  63. package/lib/commonjs/classes/polls/HMSPollState.js.map +1 -0
  64. package/lib/commonjs/classes/polls/HMSPollType.js +12 -0
  65. package/lib/commonjs/classes/polls/HMSPollType.js.map +1 -0
  66. package/lib/commonjs/classes/polls/HMSPollUpdateType.js +13 -0
  67. package/lib/commonjs/classes/polls/HMSPollUpdateType.js.map +1 -0
  68. package/lib/commonjs/classes/polls/HMSPollUserTrackingMode.js +13 -0
  69. package/lib/commonjs/classes/polls/HMSPollUserTrackingMode.js.map +1 -0
  70. package/lib/commonjs/hooks/polls.js +17 -0
  71. package/lib/commonjs/hooks/polls.js.map +1 -0
  72. package/lib/commonjs/index.js +56 -0
  73. package/lib/commonjs/index.js.map +1 -1
  74. package/lib/commonjs/stores/hms-interactivity-store.js +21 -0
  75. package/lib/commonjs/stores/hms-interactivity-store.js.map +1 -0
  76. package/lib/commonjs/stores/hms-polls-slice.js +19 -0
  77. package/lib/commonjs/stores/hms-polls-slice.js.map +1 -0
  78. package/lib/commonjs/stores/types.js.map +1 -1
  79. package/lib/commonjs/utils/emitter/EventEmitter.js +19 -0
  80. package/lib/commonjs/utils/emitter/EventEmitter.js.map +1 -1
  81. package/lib/module/classes/HMSInteractivityCenter.js +85 -0
  82. package/lib/module/classes/HMSInteractivityCenter.js.map +1 -0
  83. package/lib/module/classes/HMSInteractivityEncoder.js +26 -0
  84. package/lib/module/classes/HMSInteractivityEncoder.js.map +1 -0
  85. package/lib/module/classes/HMSPermissions.js +4 -0
  86. package/lib/module/classes/HMSPermissions.js.map +1 -1
  87. package/lib/module/classes/HMSPollsListenerActions.js +5 -0
  88. package/lib/module/classes/HMSPollsListenerActions.js.map +1 -0
  89. package/lib/module/classes/HMSSDK.js +8 -0
  90. package/lib/module/classes/HMSSDK.js.map +1 -1
  91. package/lib/module/classes/polls/HMSPoll.js +2 -0
  92. package/lib/module/classes/polls/HMSPoll.js.map +1 -0
  93. package/lib/module/classes/polls/HMSPollCategory.js +6 -0
  94. package/lib/module/classes/polls/HMSPollCategory.js.map +1 -0
  95. package/lib/module/classes/polls/HMSPollCreateParams.js +2 -0
  96. package/lib/module/classes/polls/HMSPollCreateParams.js.map +1 -0
  97. package/lib/module/classes/polls/HMSPollQuestion.js +2 -0
  98. package/lib/module/classes/polls/HMSPollQuestion.js.map +1 -0
  99. package/lib/module/classes/polls/HMSPollQuestionAnswer.js +2 -0
  100. package/lib/module/classes/polls/HMSPollQuestionAnswer.js.map +1 -0
  101. package/lib/module/classes/polls/HMSPollQuestionCreateParams.js +2 -0
  102. package/lib/module/classes/polls/HMSPollQuestionCreateParams.js.map +1 -0
  103. package/lib/module/classes/polls/HMSPollQuestionOption.js +2 -0
  104. package/lib/module/classes/polls/HMSPollQuestionOption.js.map +1 -0
  105. package/lib/module/classes/polls/HMSPollQuestionOptionCreateParams.js +2 -0
  106. package/lib/module/classes/polls/HMSPollQuestionOptionCreateParams.js.map +1 -0
  107. package/lib/module/classes/polls/HMSPollQuestionQuizOptionCreateParams.js +2 -0
  108. package/lib/module/classes/polls/HMSPollQuestionQuizOptionCreateParams.js.map +1 -0
  109. package/lib/module/classes/polls/HMSPollQuestionResponse.js +2 -0
  110. package/lib/module/classes/polls/HMSPollQuestionResponse.js.map +1 -0
  111. package/lib/module/classes/polls/HMSPollQuestionResponseCreateParams.js +2 -0
  112. package/lib/module/classes/polls/HMSPollQuestionResponseCreateParams.js.map +1 -0
  113. package/lib/module/classes/polls/HMSPollQuestionResponseResult.js +2 -0
  114. package/lib/module/classes/polls/HMSPollQuestionResponseResult.js.map +1 -0
  115. package/lib/module/classes/polls/HMSPollQuestionResult.js +2 -0
  116. package/lib/module/classes/polls/HMSPollQuestionResult.js.map +1 -0
  117. package/lib/module/classes/polls/HMSPollQuestionType.js +8 -0
  118. package/lib/module/classes/polls/HMSPollQuestionType.js.map +1 -0
  119. package/lib/module/classes/polls/HMSPollResponsePeerInfo.js +2 -0
  120. package/lib/module/classes/polls/HMSPollResponsePeerInfo.js.map +1 -0
  121. package/lib/module/classes/polls/HMSPollResult.js +2 -0
  122. package/lib/module/classes/polls/HMSPollResult.js.map +1 -0
  123. package/lib/module/classes/polls/HMSPollState.js +7 -0
  124. package/lib/module/classes/polls/HMSPollState.js.map +1 -0
  125. package/lib/module/classes/polls/HMSPollType.js +6 -0
  126. package/lib/module/classes/polls/HMSPollType.js.map +1 -0
  127. package/lib/module/classes/polls/HMSPollUpdateType.js +7 -0
  128. package/lib/module/classes/polls/HMSPollUpdateType.js.map +1 -0
  129. package/lib/module/classes/polls/HMSPollUserTrackingMode.js +7 -0
  130. package/lib/module/classes/polls/HMSPollUserTrackingMode.js.map +1 -0
  131. package/lib/module/hooks/polls.js +12 -0
  132. package/lib/module/hooks/polls.js.map +1 -0
  133. package/lib/module/index.js +7 -0
  134. package/lib/module/index.js.map +1 -1
  135. package/lib/module/stores/hms-interactivity-store.js +15 -0
  136. package/lib/module/stores/hms-interactivity-store.js.map +1 -0
  137. package/lib/module/stores/hms-polls-slice.js +12 -0
  138. package/lib/module/stores/hms-polls-slice.js.map +1 -0
  139. package/lib/module/stores/types.js.map +1 -1
  140. package/lib/module/utils/emitter/EventEmitter.js +19 -0
  141. package/lib/module/utils/emitter/EventEmitter.js.map +1 -1
  142. package/lib/typescript/classes/HMSInteractivityCenter.d.ts +35 -0
  143. package/lib/typescript/classes/HMSInteractivityEncoder.d.ts +4 -0
  144. package/lib/typescript/classes/HMSPermissions.d.ts +4 -0
  145. package/lib/typescript/classes/HMSPollsListenerActions.d.ts +3 -0
  146. package/lib/typescript/classes/HMSSDK.d.ts +3 -0
  147. package/lib/typescript/classes/polls/HMSPoll.d.ts +81 -0
  148. package/lib/typescript/classes/polls/HMSPollCategory.d.ts +10 -0
  149. package/lib/typescript/classes/polls/HMSPollCreateParams.d.ts +6 -0
  150. package/lib/typescript/classes/polls/HMSPollQuestion.d.ts +61 -0
  151. package/lib/typescript/classes/polls/HMSPollQuestionAnswer.d.ts +17 -0
  152. package/lib/typescript/classes/polls/HMSPollQuestionCreateParams.d.ts +25 -0
  153. package/lib/typescript/classes/polls/HMSPollQuestionOption.d.ts +21 -0
  154. package/lib/typescript/classes/polls/HMSPollQuestionOptionCreateParams.d.ts +3 -0
  155. package/lib/typescript/classes/polls/HMSPollQuestionQuizOptionCreateParams.d.ts +4 -0
  156. package/lib/typescript/classes/polls/HMSPollQuestionResponse.d.ts +47 -0
  157. package/lib/typescript/classes/polls/HMSPollQuestionResponseCreateParams.d.ts +2 -0
  158. package/lib/typescript/classes/polls/HMSPollQuestionResponseResult.d.ts +17 -0
  159. package/lib/typescript/classes/polls/HMSPollQuestionResult.d.ts +29 -0
  160. package/lib/typescript/classes/polls/HMSPollQuestionType.d.ts +18 -0
  161. package/lib/typescript/classes/polls/HMSPollResponsePeerInfo.d.ts +21 -0
  162. package/lib/typescript/classes/polls/HMSPollResult.d.ts +22 -0
  163. package/lib/typescript/classes/polls/HMSPollState.d.ts +14 -0
  164. package/lib/typescript/classes/polls/HMSPollType.d.ts +4 -0
  165. package/lib/typescript/classes/polls/HMSPollUpdateType.d.ts +5 -0
  166. package/lib/typescript/classes/polls/HMSPollUserTrackingMode.d.ts +14 -0
  167. package/lib/typescript/hooks/polls.d.ts +3 -0
  168. package/lib/typescript/index.d.ts +8 -0
  169. package/lib/typescript/stores/hms-interactivity-store.d.ts +9 -0
  170. package/lib/typescript/stores/hms-polls-slice.d.ts +5 -0
  171. package/lib/typescript/stores/types.d.ts +6 -0
  172. package/lib/typescript/utils/emitter/EventEmitter.d.ts +7 -0
  173. package/package.json +1 -1
  174. package/sdk-versions.json +2 -2
  175. package/src/classes/HMSInteractivityCenter.ts +126 -0
  176. package/src/classes/HMSInteractivityEncoder.ts +29 -0
  177. package/src/classes/HMSPermissions.ts +6 -0
  178. package/src/classes/HMSPollsListenerActions.ts +3 -0
  179. package/src/classes/HMSSDK.tsx +10 -0
  180. package/src/classes/polls/HMSPoll.ts +108 -0
  181. package/src/classes/polls/HMSPollCategory.ts +11 -0
  182. package/src/classes/polls/HMSPollCreateParams.ts +19 -0
  183. package/src/classes/polls/HMSPollQuestion.ts +92 -0
  184. package/src/classes/polls/HMSPollQuestionAnswer.ts +29 -0
  185. package/src/classes/polls/HMSPollQuestionCreateParams.ts +36 -0
  186. package/src/classes/polls/HMSPollQuestionOption.ts +24 -0
  187. package/src/classes/polls/HMSPollQuestionOptionCreateParams.ts +8 -0
  188. package/src/classes/polls/HMSPollQuestionQuizOptionCreateParams.ts +6 -0
  189. package/src/classes/polls/HMSPollQuestionResponse.ts +72 -0
  190. package/src/classes/polls/HMSPollQuestionResponseCreateParams.ts +6 -0
  191. package/src/classes/polls/HMSPollQuestionResponseResult.ts +19 -0
  192. package/src/classes/polls/HMSPollQuestionResult.ts +41 -0
  193. package/src/classes/polls/HMSPollQuestionType.ts +21 -0
  194. package/src/classes/polls/HMSPollResponsePeerInfo.ts +24 -0
  195. package/src/classes/polls/HMSPollResult.ts +26 -0
  196. package/src/classes/polls/HMSPollState.ts +16 -0
  197. package/src/classes/polls/HMSPollType.ts +4 -0
  198. package/src/classes/polls/HMSPollUpdateType.ts +5 -0
  199. package/src/classes/polls/HMSPollUserTrackingMode.ts +16 -0
  200. package/src/hooks/polls.ts +14 -0
  201. package/src/index.ts +9 -0
  202. package/src/stores/hms-interactivity-store.ts +18 -0
  203. package/src/stores/hms-polls-slice.ts +20 -0
  204. package/src/stores/types.ts +20 -3
  205. package/src/utils/emitter/EventEmitter.ts +26 -0
@@ -0,0 +1,223 @@
1
+ //
2
+ // HMSInteractivityDecoder.swift
3
+ // react-native-hms
4
+ //
5
+ // Created by Jatin Nagar on 18/01/24.
6
+ //
7
+
8
+ import Foundation
9
+ import HMSSDK
10
+
11
+ class HMSInteractivityDecoder {
12
+ static func getHMSPoll(_ poll: HMSPoll) -> [String: Any] {
13
+ var dict: [String: Any] = [
14
+ "anonymous": poll.anonymous,
15
+ "type": poll.category.rawValue,
16
+ "duration": poll.duration,
17
+ "pollId": poll.pollID,
18
+ "rolesThatCanViewResponses": HMSDecoder.getAllRoles(poll.rolesThatCanViewResponses),
19
+ "rolesThatCanVote": HMSDecoder.getAllRoles(poll.rolesThatCanVote),
20
+ "state": poll.state.rawValue,
21
+ "title": poll.title
22
+ ]
23
+ if let createdBy = poll.createdBy {
24
+ dict["createdBy"] = HMSDecoder.getHmsPeerSubset(createdBy)
25
+ }
26
+ if let mode = poll.mode {
27
+ dict["mode"] = mode.rawValue
28
+ }
29
+ if let questionCount = poll.questionCount {
30
+ dict["questionCount"] = questionCount
31
+ }
32
+ if let questions = poll.questions {
33
+ dict["questions"] = getHMSPollQuestions(questions)
34
+ }
35
+ if let result = poll.result {
36
+ dict["result"] = getHMSPollResult(result)
37
+ }
38
+ if let startedAt = poll.startedAt {
39
+ dict["startedAt"] = startedAt.timeIntervalSince1970 * 1000
40
+ }
41
+ if let startedBy = poll.startedBy {
42
+ dict["startedBy"] = HMSDecoder.getHmsPeerSubset(startedBy)
43
+ }
44
+ if let stoppedAt = poll.stoppedAt {
45
+ dict["stoppedAt"] = stoppedAt.timeIntervalSince1970 * 1000
46
+ }
47
+ if let stoppedBy = poll.stoppedBy {
48
+ dict["stoppedBy"] = HMSDecoder.getHmsPeerSubset(stoppedBy)
49
+ }
50
+ return dict
51
+ }
52
+
53
+ static func getHMSPollQuestions(_ hmsPollQuestions: [HMSPollQuestion]) -> [[String: AnyHashable]] {
54
+ var questions = [[String: AnyHashable]]()
55
+
56
+ hmsPollQuestions.forEach { question in
57
+ questions.append(getHMSPollQuestion(question))
58
+ }
59
+ return questions
60
+ }
61
+
62
+ static func getHMSPollQuestion(_ hmsPollQuestion: HMSPollQuestion) -> [String: AnyHashable] {
63
+ var dict: [String: AnyHashable] = [
64
+ "duration": hmsPollQuestion.duration,
65
+ "index": hmsPollQuestion.index,
66
+ "myResponses": getHMSPollQuestionResponses(hmsPollQuestion.myResponses),
67
+ "once": hmsPollQuestion.once,
68
+ "skippable": hmsPollQuestion.skippable,
69
+ "text": hmsPollQuestion.text,
70
+ "type": hmsPollQuestion.type.rawValue,
71
+ "voted": hmsPollQuestion.voted,
72
+ "weight": hmsPollQuestion.weight
73
+ ]
74
+ if let answer = hmsPollQuestion.answer {
75
+ dict["answer"] = getHMSPollQuestionAnswer(answer)
76
+ }
77
+ if let answerMaxLen = hmsPollQuestion.answerMaxLen {
78
+ dict["answerMaxLen"] = answerMaxLen
79
+ }
80
+ if let answerMinLen = hmsPollQuestion.answerMinLen {
81
+ dict["answerMinLen"] = answerMinLen
82
+ }
83
+ if let options = hmsPollQuestion.options {
84
+ dict["options"] = getHMSPollQuestionOptions(options)
85
+ }
86
+ if let responses = hmsPollQuestion.responses {
87
+ dict["responses"] = getHMSPollQuestionResponses(responses)
88
+ }
89
+ return dict
90
+ }
91
+
92
+ static func getHMSPollQuestionAnswer(_ hmsPollQuestionAnswer: HMSPollQuestionAnswer) -> [String: AnyHashable] {
93
+ var dict: [String: AnyHashable] = [
94
+ "hidden": hmsPollQuestionAnswer.hidden
95
+ ]
96
+ if let option = hmsPollQuestionAnswer.option {
97
+ dict["option"] = option
98
+ }
99
+ if let options = hmsPollQuestionAnswer.options {
100
+ dict["options"] = options
101
+ }
102
+ return dict
103
+ }
104
+
105
+ static func getHMSPollQuestionOptions(_ hmsPollQuestionOptions: [HMSPollQuestionOption]) -> [[String: AnyHashable]] {
106
+ var dict = [[String: AnyHashable]]()
107
+ hmsPollQuestionOptions.forEach { hmsPollQuestionOption in
108
+ dict.append(getHMSPollQuestionOption(hmsPollQuestionOption))
109
+ }
110
+ return dict
111
+ }
112
+
113
+ static func getHMSPollQuestionOption(_ hmsPollQuestionOption: HMSPollQuestionOption) -> [String: AnyHashable] {
114
+ return [
115
+ "text": hmsPollQuestionOption.text,
116
+ "index": hmsPollQuestionOption.index,
117
+ "voteCount": hmsPollQuestionOption.voteCount,
118
+ "weight": hmsPollQuestionOption.weight
119
+ ]
120
+ }
121
+
122
+ static func getHMSPollQuestionResponses(_ hmsPollQuestionResponses: [HMSPollQuestionResponse]) -> [[String: AnyHashable]] {
123
+ var dict = [[String: AnyHashable]]()
124
+ hmsPollQuestionResponses.forEach { hmsPollQuestionResponse in
125
+ dict.append(getHMSPollQuestionResponse(hmsPollQuestionResponse))
126
+ }
127
+ return dict
128
+ }
129
+
130
+ static func getHMSPollQuestionResponse(_ hmsPollQuestionResponse: HMSPollQuestionResponse) -> [String: AnyHashable] {
131
+ var dict: [String: AnyHashable] = [
132
+ "duration": hmsPollQuestionResponse.duration,
133
+ "option": hmsPollQuestionResponse.option,
134
+ "questionId": hmsPollQuestionResponse.questionID,
135
+ "skipped": hmsPollQuestionResponse.skipped,
136
+ "text": hmsPollQuestionResponse.text,
137
+ "type": hmsPollQuestionResponse.type.rawValue,
138
+ "update": hmsPollQuestionResponse.update
139
+ ]
140
+ if let options = hmsPollQuestionResponse.options {
141
+ dict["options"] = options
142
+ }
143
+ if let peerInfo = hmsPollQuestionResponse.peer {
144
+ dict["peer"] = getHMSPollResponsePeerInfo(peerInfo)
145
+ }
146
+ if let responseFinal = hmsPollQuestionResponse.responseFinal {
147
+ dict["responseFinal"] = responseFinal
148
+ }
149
+ return dict
150
+ }
151
+
152
+ static func getHMSPollResponsePeerInfo(_ hmsPollResponsePeerInfo: HMSPollResponsePeerInfo) -> [String: AnyHashable] {
153
+ var dict = [String: AnyHashable]()
154
+
155
+ if let customerUserID = hmsPollResponsePeerInfo.customerUserID {
156
+ dict["customerUserId"] = customerUserID
157
+ }
158
+ if let peerID = hmsPollResponsePeerInfo.peerID {
159
+ dict["peerId"] = peerID
160
+ }
161
+ if let userHash = hmsPollResponsePeerInfo.userHash {
162
+ dict["userHash"] = userHash
163
+ }
164
+ if let userName = hmsPollResponsePeerInfo.userName {
165
+ dict["userName"] = userName
166
+ }
167
+ return dict
168
+ }
169
+
170
+ static func getHMSPollResult(_ hmsPollResult: HMSPollResult) -> [String: AnyHashable] {
171
+ return [
172
+ "maxUserCount": hmsPollResult.maxUserCount,
173
+ "questions": getHMSPollQuestionResults(hmsPollResult.questions),
174
+ "totalResponse": hmsPollResult.totalResponse,
175
+ "userCount": hmsPollResult.userCount
176
+ ]
177
+ }
178
+
179
+ static func getHMSPollQuestionResults(_ hmsPollQuestionResults: [HMSPollQuestionResult]) -> [[String: AnyHashable]] {
180
+ var results = [[String: AnyHashable]]()
181
+
182
+ hmsPollQuestionResults.forEach { result in
183
+ results.append(getHMSPollQuestionResult(result))
184
+ }
185
+ return results
186
+ }
187
+
188
+ static func getHMSPollQuestionResult(_ hmsPollQuestionResult: HMSPollQuestionResult) -> [String: AnyHashable] {
189
+ var result: [String: AnyHashable] = [
190
+ "type": hmsPollQuestionResult.type,
191
+ "correctVotes": hmsPollQuestionResult.correctVotes,
192
+ "question": hmsPollQuestionResult.question,
193
+ "skippedVotes": hmsPollQuestionResult.skippedVotes,
194
+ "totalVotes": hmsPollQuestionResult.totalVotes
195
+ ]
196
+ if let optionVoteCounts = hmsPollQuestionResult.optionVoteCounts {
197
+ result["optionVoteCounts"] = optionVoteCounts
198
+ }
199
+ return result
200
+ }
201
+
202
+ static func getHMSPollQuestionResponseResults(_ hmsPollQuestionResponseResults: [HMSPollQuestionResponseResult]) -> [[String: AnyHashable]] {
203
+ var results = [[String: AnyHashable]]()
204
+
205
+ hmsPollQuestionResponseResults.forEach { result in
206
+ results.append(getHMSPollQuestionResponseResult(result))
207
+ }
208
+ return results
209
+ }
210
+
211
+ static func getHMSPollQuestionResponseResult(_ hmsPollQuestionResponseResult: HMSPollQuestionResponseResult) -> [String: AnyHashable] {
212
+ var result: [String: AnyHashable] = [
213
+ "question": hmsPollQuestionResponseResult.question
214
+ ]
215
+ if let correct = hmsPollQuestionResponseResult.correct {
216
+ result["correct"] = correct
217
+ }
218
+ if let error = hmsPollQuestionResponseResult.error {
219
+ result["error"] = error.localizedDescription
220
+ }
221
+ return result
222
+ }
223
+ }
@@ -0,0 +1,169 @@
1
+ //
2
+ // HMSInteractivityHelper.swift
3
+ // react-native-hms
4
+ //
5
+ // Created by Jatin Nagar on 09/01/24.
6
+ //
7
+
8
+ import Foundation
9
+ import HMSSDK
10
+
11
+ class HMSInteractivityHelper {
12
+ static func getPollBuilderFromDict(_ data: NSDictionary, sdkRoles: [HMSRole]?) -> HMSPollBuilder {
13
+ let pollBuilder = HMSPollBuilder()
14
+
15
+ if let title = data["title"] as? String {
16
+ _ = pollBuilder.withTitle(title)
17
+ }
18
+
19
+ if let anonymous = data["anonymous"] as? Bool {
20
+ _ = pollBuilder.withAnonymous(anonymous)
21
+ }
22
+
23
+ if let duration = data["duration"] as? Int {
24
+ _ = pollBuilder.withDuration(duration)
25
+ }
26
+
27
+ if let category = data["type"] as? Int {
28
+ if let pollCategory = HMSPollCategory.init(rawValue: category) {
29
+ _ = pollBuilder.withCategory(pollCategory)
30
+ } else {
31
+ print("unable to create `HMSPollCategory` instance from given `type` value: \(category)")
32
+ }
33
+ }
34
+
35
+ if let pollID = data["pollId"] as? String {
36
+ _ = pollBuilder.withPollID(pollID)
37
+ }
38
+
39
+ if let rolesStrThatCanViewResponses = data["rolesThatCanViewResponses"] as? [String] {
40
+ let roles = HMSHelper.getRolesFromRoleNames(rolesStrThatCanViewResponses, roles: sdkRoles)
41
+ _ = pollBuilder.withRolesThatCanViewResponses(roles)
42
+ }
43
+
44
+ if let rolesStrThatCanVote = data["rolesThatCanVote"] as? [String] {
45
+ let roles = HMSHelper.getRolesFromRoleNames(rolesStrThatCanVote, roles: sdkRoles)
46
+ _ = pollBuilder.withRolesThatCanVote(roles)
47
+ }
48
+
49
+ if let userTrackingMode = data["mode"] as? Int {
50
+ if let pollUserTrackingMode = HMSPollUserTrackingMode.init(rawValue: userTrackingMode) {
51
+ _ = pollBuilder.withUserTrackingMode(pollUserTrackingMode)
52
+ } else {
53
+ print("unable to create `HMSPollUserTrackingMode` instance from given `userTrackingMode` value: \(userTrackingMode)")
54
+ }
55
+ }
56
+
57
+ if let questions = data["questions"] as? [NSDictionary] {
58
+ addQuestionsToPollBuilder(questions: questions, pollBuilder: pollBuilder)
59
+ }
60
+
61
+ return pollBuilder
62
+ }
63
+
64
+ static func addQuestionsToPollBuilder(questions: [NSDictionary], pollBuilder: HMSPollBuilder) {
65
+ questions.forEach { question in
66
+ let pollQuestionBuilder = self.getPollQuestionBuilderFromDict(question)
67
+ _ = pollBuilder.addQuestion(with: pollQuestionBuilder)
68
+ }
69
+ }
70
+
71
+ static func getPollQuestionBuilderFromDict(_ data: NSDictionary) -> HMSPollQuestionBuilder {
72
+ let pollQuestionBuilder = HMSPollQuestionBuilder()
73
+
74
+ // // Commented because as of now, not passing any field from JS to use `withAnswerHidden` method of `HMSPollQuestionBuilder`
75
+ // if let answerHidden = data["answerHidden"] as? Bool {
76
+ // _ = pollQuestionBuilder.withAnswerHidden(answerHidden: answerHidden)
77
+ // }
78
+
79
+ if let canBeSkipped = data["skippable"] as? Bool {
80
+ _ = pollQuestionBuilder.withCanBeSkipped(canBeSkipped)
81
+ }
82
+
83
+ if let once = data["once"] as? Bool {
84
+ _ = pollQuestionBuilder.withCanChangeResponse(canChangeResponse: !once)
85
+ }
86
+
87
+ if let duration = data["duration"] as? Int {
88
+ _ = pollQuestionBuilder.withDuration(duration)
89
+ }
90
+
91
+ if let index = data["index"] as? Int {
92
+ _ = pollQuestionBuilder.withIndex(index)
93
+ }
94
+
95
+ if let maxLength = data["answerMaxLen"] as? Int {
96
+ _ = pollQuestionBuilder.withMaxLength(maxLength: maxLength)
97
+ }
98
+
99
+ if let minLength = data["answerMinLen"] as? Int {
100
+ _ = pollQuestionBuilder.withMinLength(minLength: minLength)
101
+ }
102
+
103
+ if let title = data["text"] as? String {
104
+ _ = pollQuestionBuilder.withTitle(title)
105
+ }
106
+
107
+ if let type = data["type"] as? Int {
108
+ if let questionType = HMSPollQuestionType.init(rawValue: type) {
109
+ _ = pollQuestionBuilder.withType(questionType)
110
+ } else {
111
+ print("unable to create `HMSPollQuestionType` instance from given `type` value: \(type)")
112
+ }
113
+ }
114
+
115
+ if let weight = data["weight"] as? Int {
116
+ _ = pollQuestionBuilder.withWeight(weight: weight)
117
+ }
118
+
119
+ if let options = data["options"] as? [NSDictionary] {
120
+ addOptionsToPollQuestionBuilder(options: options, pollQuestionBuilder: pollQuestionBuilder)
121
+ }
122
+
123
+ return pollQuestionBuilder
124
+ }
125
+
126
+ static func addOptionsToPollQuestionBuilder(options: [NSDictionary], pollQuestionBuilder: HMSPollQuestionBuilder) {
127
+ options.forEach { option in
128
+ guard let optionTitle = option["text"] as? String else {
129
+ print("\(#function) option title field not available!")
130
+ return
131
+ }
132
+
133
+ if let isCorrect = option["isCorrectAnswer"] as? Bool {
134
+ _ = pollQuestionBuilder.addQuizOption(with: optionTitle, isCorrect: isCorrect)
135
+ } else {
136
+ _ = pollQuestionBuilder.addOption(with: optionTitle)
137
+ }
138
+ }
139
+ }
140
+
141
+ static func getPollResponseBuilder(_ response: NSDictionary, poll: HMSPoll, pollQuestion: HMSPollQuestion) -> HMSPollResponseBuilder {
142
+ let pollResponseBuilder = HMSPollResponseBuilder(poll: poll)
143
+
144
+ switch pollQuestion.type {
145
+ case .longAnswer, .shortAnswer:
146
+ if let responseText = response["text"] as? String {
147
+ if let duration = response["duration"] as? Int {
148
+ pollResponseBuilder.addResponse(for: pollQuestion, text: responseText, duration: duration)
149
+ } else {
150
+ pollResponseBuilder.addResponse(for: pollQuestion, text: responseText)
151
+ }
152
+ }
153
+ case .multipleChoice, .singleChoice:
154
+ if let options = response["options"] as? [Int],
155
+ let pollQuestionOptions = pollQuestion.options {
156
+ let questionOptions = options.compactMap({optionIndex in pollQuestionOptions.first { pollQuestionOption in pollQuestionOption.index == optionIndex }})
157
+
158
+ if let duration = response["duration"] as? Int {
159
+ pollResponseBuilder.addResponse(for: pollQuestion, options: questionOptions, duration: duration)
160
+ } else {
161
+ pollResponseBuilder.addResponse(for: pollQuestion, options: questionOptions)
162
+ }
163
+ }
164
+ @unknown default:
165
+ print("@unknown default case: Invalid pollQuestionType")
166
+ }
167
+ return pollResponseBuilder
168
+ }
169
+ }
package/ios/HMSManager.m CHANGED
@@ -296,4 +296,21 @@ RCT_EXTERN_METHOD(peerListIteratorNext
296
296
  : (RCTPromiseResolveBlock)resolve
297
297
  : (RCTPromiseRejectBlock)reject)
298
298
 
299
+ #pragma mark - Interactivity Center - Polls/Quiz
300
+
301
+ RCT_EXTERN_METHOD(quickStartPoll
302
+ : (NSDictionary)data
303
+ : (RCTPromiseResolveBlock)resolve
304
+ : (RCTPromiseRejectBlock)reject)
305
+
306
+ RCT_EXTERN_METHOD(addResponseOnPollQuestion
307
+ : (NSDictionary)data
308
+ : (RCTPromiseResolveBlock)resolve
309
+ : (RCTPromiseRejectBlock)reject)
310
+
311
+ RCT_EXTERN_METHOD(stopPoll
312
+ : (NSDictionary)data
313
+ : (RCTPromiseResolveBlock)resolve
314
+ : (RCTPromiseRejectBlock)reject)
315
+
299
316
  @end
@@ -37,7 +37,7 @@ class HMSManager: RCTEventEmitter {
37
37
  }
38
38
 
39
39
  override func supportedEvents() -> [String]! {
40
- return [ON_JOIN, ON_PREVIEW, ON_ROOM_UPDATE, ON_PEER_UPDATE, ON_TRACK_UPDATE, ON_ERROR, ON_MESSAGE, ON_SPEAKER, RECONNECTING, RECONNECTED, ON_ROLE_CHANGE_REQUEST, ON_CHANGE_TRACK_STATE_REQUEST, ON_REMOVED_FROM_ROOM, ON_RTC_STATS, ON_LOCAL_AUDIO_STATS, ON_LOCAL_VIDEO_STATS, ON_REMOTE_AUDIO_STATS, ON_REMOTE_VIDEO_STATS, ON_AUDIO_DEVICE_CHANGED, HMSConstants.ON_SESSION_STORE_AVAILABLE, HMSConstants.ON_SESSION_STORE_CHANGED, HMSConstants.ON_PEER_LIST_UPDATED]
40
+ return [ON_JOIN, ON_PREVIEW, ON_ROOM_UPDATE, ON_PEER_UPDATE, ON_TRACK_UPDATE, ON_ERROR, ON_MESSAGE, ON_SPEAKER, RECONNECTING, RECONNECTED, ON_ROLE_CHANGE_REQUEST, ON_CHANGE_TRACK_STATE_REQUEST, ON_REMOVED_FROM_ROOM, ON_RTC_STATS, ON_LOCAL_AUDIO_STATS, ON_LOCAL_VIDEO_STATS, ON_REMOTE_AUDIO_STATS, ON_REMOTE_VIDEO_STATS, ON_AUDIO_DEVICE_CHANGED, HMSConstants.ON_SESSION_STORE_AVAILABLE, HMSConstants.ON_SESSION_STORE_CHANGED, HMSConstants.ON_PEER_LIST_UPDATED, HMSConstants.ON_POLL_UPDATE]
41
41
  }
42
42
 
43
43
  // MARK: - HMS SDK Delegate Callbacks
@@ -643,4 +643,33 @@ class HMSManager: RCTEventEmitter {
643
643
 
644
644
  hms?.peerListIteratorNext(data, resolve, reject)
645
645
  }
646
+
647
+ // MARK: - Interactivity Center - Polls/Quiz
648
+
649
+ @objc
650
+ func quickStartPoll(_ data: NSDictionary, _ resolve: RCTPromiseResolveBlock?, _ reject: RCTPromiseRejectBlock?) {
651
+ guard let rnsdk = HMSHelper.getHms(data, hmsCollection), let interactivity = rnsdk.interactivity else {
652
+ reject?("6004", "HMSRNSDK instance not found!", nil)
653
+ return
654
+ }
655
+ interactivity.quickStartPoll(data, resolve, reject)
656
+ }
657
+
658
+ @objc
659
+ func addResponseOnPollQuestion(_ data: NSDictionary, _ resolve: RCTPromiseResolveBlock?, _ reject: RCTPromiseRejectBlock?) {
660
+ guard let rnsdk = HMSHelper.getHms(data, hmsCollection), let interactivity = rnsdk.interactivity else {
661
+ reject?("6004", "HMSRNSDK instance not found!", nil)
662
+ return
663
+ }
664
+ interactivity.add(data, resolve, reject)
665
+ }
666
+
667
+ @objc
668
+ func stopPoll(_ data: NSDictionary, _ resolve: RCTPromiseResolveBlock?, _ reject: RCTPromiseRejectBlock?) {
669
+ guard let rnsdk = HMSHelper.getHms(data, hmsCollection), let interactivity = rnsdk.interactivity else {
670
+ reject?("6004", "HMSRNSDK instance not found!", nil)
671
+ return
672
+ }
673
+ interactivity.stop(data, resolve, reject)
674
+ }
646
675
  }
@@ -0,0 +1,89 @@
1
+ //
2
+ // HMSRNInteractivityCenter.swift
3
+ // react-native-hms
4
+ //
5
+ // Created by Jatin Nagar on 09/01/24.
6
+ //
7
+
8
+ import Foundation
9
+ import HMSSDK
10
+
11
+ class HMSRNInteractivityCenter {
12
+ weak var hmssdk: HMSSDK?
13
+ weak var hmsrnsdk: HMSRNSDK?
14
+
15
+ init(hmssdk: HMSSDK, hmsrnsdk: HMSRNSDK?) {
16
+ self.hmssdk = hmssdk
17
+ self.hmsrnsdk = hmsrnsdk
18
+
19
+ hmssdk.interactivityCenter.addPollUpdateListner { [weak self] updatedPoll, update in
20
+ guard let self = self else { return }
21
+ guard let enabledEvents = self.hmsrnsdk?.eventsEnableStatus, enabledEvents[HMSConstants.ON_POLL_UPDATE] == true else {
22
+ print("HMSConstants.ON_POLL_UPDATE event is not enabled")
23
+ return
24
+ }
25
+ self.hmsrnsdk?.delegate?.emitEvent(
26
+ HMSConstants.ON_POLL_UPDATE,
27
+ ["update": update.rawValue, "updatedPoll": HMSInteractivityDecoder.getHMSPoll(updatedPoll)]
28
+ )
29
+ }
30
+ }
31
+
32
+ func quickStartPoll(_ data: NSDictionary, _ resolve: RCTPromiseResolveBlock?, _ reject: RCTPromiseRejectBlock?) {
33
+ let pollBuilder = HMSInteractivityHelper.getPollBuilderFromDict(data, sdkRoles: hmssdk?.roles)
34
+
35
+ self.hmssdk?.interactivityCenter.quickStartPoll(with: pollBuilder) { _, error in
36
+ if let nonnilError = error {
37
+ reject?("6004", nonnilError.localizedDescription, nil)
38
+ return
39
+ }
40
+ resolve?(nil)
41
+ }
42
+ }
43
+
44
+ func add(_ data: NSDictionary, _ resolve: RCTPromiseResolveBlock?, _ reject: RCTPromiseRejectBlock?) {
45
+ guard let pollId = data["pollId"] as? String,
46
+ let poll = self.hmssdk?.interactivityCenter.polls.first(where: {poll in poll.pollID == pollId}) else {
47
+ reject?("6004", "Unable to find HMSPoll with given pollId", nil)
48
+ return
49
+ }
50
+ guard let pollQuestionIndex = data["pollQuestionIndex"] as? Int,
51
+ let pollQuestion = poll.questions?.first(where: {question in question.index == pollQuestionIndex}) else {
52
+ reject?("6004", "Unable to find HMSPollQuestion in poll with given question index", nil)
53
+ return
54
+ }
55
+ guard let responses = data["responses"] as? NSDictionary else {
56
+ reject?("6004", "responses field is required", nil)
57
+ return
58
+ }
59
+
60
+ let pollResponseBuilder = HMSInteractivityHelper.getPollResponseBuilder(responses, poll: poll, pollQuestion: pollQuestion)
61
+
62
+ self.hmssdk?.interactivityCenter.add(response: pollResponseBuilder) { pollQuestionResponseResult, error in
63
+ if let nonnilError = error {
64
+ reject?("6004", nonnilError.localizedDescription, nil)
65
+ return
66
+ }
67
+ if let pollQuestionResponseResult = pollQuestionResponseResult {
68
+ resolve?(HMSInteractivityDecoder.getHMSPollQuestionResponseResults(pollQuestionResponseResult))
69
+ } else {
70
+ resolve?(nil)
71
+ }
72
+ }
73
+ }
74
+
75
+ func stop(_ data: NSDictionary, _ resolve: RCTPromiseResolveBlock?, _ reject: RCTPromiseRejectBlock?) {
76
+ guard let pollId = data["pollId"] as? String,
77
+ let poll = self.hmssdk?.interactivityCenter.polls.first(where: {poll in poll.pollID == pollId}) else {
78
+ reject?("6004", "Unable to find HMSPoll with given pollId", nil)
79
+ return
80
+ }
81
+ self.hmssdk?.interactivityCenter.stop(poll: poll, completion: {success, error in
82
+ if let nonnilError = error {
83
+ reject?("6004", nonnilError.localizedDescription, nil)
84
+ return
85
+ }
86
+ resolve?(success)
87
+ })
88
+ }
89
+ }
@@ -12,6 +12,7 @@ import ReplayKit
12
12
  class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
13
13
 
14
14
  var hms: HMSSDK?
15
+ var interactivity: HMSRNInteractivityCenter?
15
16
 
16
17
  var delegate: HMSManager?
17
18
  var id: String = "12345"
@@ -26,7 +27,7 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
26
27
  private var isScreenShared: Bool? = false
27
28
  private var previewInProgress = false
28
29
  private var networkQualityUpdatesAttached = false
29
- private var eventsEnableStatus: [String: Bool] = [:]
30
+ internal var eventsEnableStatus: [String: Bool] = [:]
30
31
  private var sessionStore: HMSSessionStore?
31
32
  private var sessionStoreChangeObservers = [String: NSObjectProtocol]()
32
33
  private var peerListIterators = [String: HMSPeerListIterator]()
@@ -35,7 +36,8 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
35
36
  // MARK: - Setup
36
37
  init(data: NSDictionary?, delegate manager: HMSManager?, uid id: String) {
37
38
  preferredExtension = data?.value(forKey: "preferredExtension") as? String
38
-
39
+ self.delegate = manager
40
+ self.id = id
39
41
  DispatchQueue.main.async { [weak self] in
40
42
  self?.hms = HMSSDK.build { sdk in
41
43
  sdk.appGroup = data?.value(forKey: "appGroup") as? String
@@ -45,6 +47,12 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
45
47
  let audioSettings = HMSHelper.getLocalAudioSettings(trackSettings?.value(forKey: "audio") as? NSDictionary, sdk, self?.delegate, id)
46
48
  sdk.trackSettings = HMSTrackSettings(videoSettings: videoSettings, audioSettings: audioSettings)
47
49
  }
50
+ if let hms = self?.hms {
51
+ self?.interactivity = HMSRNInteractivityCenter(
52
+ hmssdk: hms,
53
+ hmsrnsdk: self
54
+ )
55
+ }
48
56
 
49
57
  NotificationCenter.default.addObserver(forName: UIApplication.willTerminateNotification,
50
58
  object: nil,
@@ -54,8 +62,6 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
54
62
  }
55
63
  }
56
64
  }
57
- self.delegate = manager
58
- self.id = id
59
65
  }
60
66
 
61
67
  deinit {
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Workspace
3
+ version = "1.0">
4
+ <FileRef
5
+ location = "self:">
6
+ </FileRef>
7
+ </Workspace>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>IDEDidComputeMac32BitWarning</key>
6
+ <true/>
7
+ </dict>
8
+ </plist>
@@ -0,0 +1,14 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>SchemeUserState</key>
6
+ <dict>
7
+ <key>Hmssdk.xcscheme_^#shared#^_</key>
8
+ <dict>
9
+ <key>orderHint</key>
10
+ <integer>0</integer>
11
+ </dict>
12
+ </dict>
13
+ </dict>
14
+ </plist>