@cometchat/chat-uikit-react-native 5.5.3 → 5.6.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.
- package/android/build.gradle +5 -0
- package/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +78 -3
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +47 -4
- package/android/src/main/java/com/reactnativecometchatuikit/SafeFileName.java +78 -0
- package/android/src/main/java/com/reactnativecometchatuikit/SoundPlayer.java +209 -119
- package/ios/CCLocalFileGuard.h +19 -0
- package/ios/CCLocalFileGuard.m +34 -0
- package/ios/FileManager.m +70 -6
- package/ios/RichTextEditorView.swift +96 -1
- package/ios/SoundPlayer.m +152 -6
- package/ios/VideoManager.m +1 -1
- package/package.json +18 -3
- package/react-native-cometchat-ui-kit.podspec +1 -1
- package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +167 -79
- package/src/CometChatConversations/CometChatConversations.tsx +240 -117
- package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +4 -0
- package/src/CometChatGroups/CometChatGroups.tsx +61 -52
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +173 -85
- package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +7 -3
- package/src/CometChatMessageHeader/listners.ts +76 -56
- package/src/CometChatMessageList/CometChatMessageList.tsx +1423 -205
- package/src/CometChatNotificationFeed/CometChatNotificationFeed.tsx +71 -7
- package/src/CometChatPinnedMessages/CometChatPinnedMessages.tsx +74 -2
- package/src/CometChatSavedMessages/CometChatSavedMessages.tsx +69 -4
- package/src/CometChatSearch/CometChatSearch.tsx +353 -101
- package/src/CometChatThreadHeader/CometChatThreadHeader.tsx +23 -1
- package/src/CometChatUsers/CometChatUsers.tsx +2 -0
- package/src/calls/CometChatCallButtons/CometChatCallButtons.tsx +19 -0
- package/src/extensions/LinkPreview/LinkPreviewBubble.tsx +48 -47
- package/src/extensions/Stickers/StickersExtensionDecorator.tsx +2 -0
- package/src/index.ts +6 -0
- package/src/shared/CometChatUiKit/CometChatUIKit.ts +85 -2
- package/src/shared/CometChatUiKit/UIKitSettings.ts +20 -0
- package/src/shared/events/CometChatUIEventHandler/Listener.ts +10 -0
- package/src/shared/events/index.ts +4 -0
- package/src/shared/events/offline.ts +28 -0
- package/src/shared/formatters/CometChatMentionsFormatter/CometChatMentionsFormatter.tsx +5 -3
- package/src/shared/framework/MessageDataSource.tsx +34 -14
- package/src/shared/index.ts +2 -0
- package/src/shared/offline/OfflineHub.ts +651 -0
- package/src/shared/offline/OfflineMediaBubble.tsx +49 -0
- package/src/shared/offline/OfflineViews.tsx +218 -0
- package/src/shared/offline/conversationPins.ts +137 -0
- package/src/shared/offline/conversations.ts +325 -0
- package/src/shared/offline/frameProbe.ts +24 -0
- package/src/shared/offline/gate.ts +94 -0
- package/src/shared/offline/groupActions.ts +81 -0
- package/src/shared/offline/identity.ts +162 -0
- package/src/shared/offline/index.ts +76 -0
- package/src/shared/offline/media.ts +247 -0
- package/src/shared/offline/notices.ts +90 -0
- package/src/shared/offline/reconcile.ts +296 -0
- package/src/shared/offline/searchOutcome.ts +62 -0
- package/src/shared/offline/send.ts +430 -0
- package/src/shared/offline/stateContract.ts +85 -0
- package/src/shared/offline/threadReplies.ts +125 -0
- package/src/shared/offline/twoPhase.ts +372 -0
- package/src/shared/offline/unsentActions.ts +168 -0
- package/src/shared/offline/useOfflineMediaUri.ts +87 -0
- package/src/shared/offline/useOfflineReconnect.ts +25 -0
- package/src/shared/offline/useOfflineSessionEnded.ts +22 -0
- package/src/shared/offline/useOfflineUploadTray.ts +76 -0
- package/src/shared/offline/usePresenceHidden.ts +33 -0
- package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +24 -1
- package/src/shared/services/UploadQueueService.ts +106 -1
- package/src/shared/utils/MessageReceiptUtils.ts +8 -0
- package/src/shared/utils/SavedMessagesHelper.ts +18 -1
- package/src/shared/utils/catchUpCursor.ts +36 -0
- package/src/shared/utils/failedMessageRetry.ts +73 -0
- package/src/shared/utils/messageIdentity.ts +38 -0
- package/src/shared/views/CometChatAttachmentViewer/CometChatAttachmentViewer.tsx +34 -5
- package/src/shared/views/CometChatAudiosBubble/CometChatAudiosBubble.tsx +10 -2
- package/src/shared/views/CometChatFileBubble/CometChatFileBubble.tsx +13 -27
- package/src/shared/views/CometChatFilesBubble/CometChatFilesBubble.tsx +60 -11
- package/src/shared/views/CometChatImagesBubble/CometChatImagesBubble.tsx +27 -2
- package/src/shared/views/CometChatList/CometChatList.tsx +468 -7
- package/src/shared/views/CometChatMediaViewer/CometChatMediaViewer.tsx +27 -5
- package/src/shared/views/CometChatMessageInput/CometChatMessageInput.tsx +1 -0
- package/src/shared/views/CometChatReactionList/CometChatReactionList.tsx +56 -10
- package/src/shared/views/CometChatStatusIndicator/CometChatStatusIndicator.tsx +4 -0
- package/src/shared/views/CometChatVideosBubble/CometChatVideosBubble.tsx +36 -2
- package/src/shared/views/CometChatVoiceNoteBubble/CometChatVoiceNoteBubble.tsx +24 -12
- package/src/theme/type.ts +17 -0
|
@@ -832,6 +832,11 @@ class RichTextView: UITextView {
|
|
|
832
832
|
return true
|
|
833
833
|
}
|
|
834
834
|
}
|
|
835
|
+
// Allow the spelling correction so tapping a floating spell-check suggestion replaces the
|
|
836
|
+
// misspelled word. Only this selector, not all of super (keeps Look Up/Share/system B/I/U hidden).
|
|
837
|
+
if action == NSSelectorFromString("replace:") {
|
|
838
|
+
return super.canPerformAction(action, withSender: sender)
|
|
839
|
+
}
|
|
835
840
|
return false
|
|
836
841
|
}
|
|
837
842
|
|
|
@@ -1188,6 +1193,9 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
|
|
|
1188
1193
|
/// emoji, a paste, an IME commit — and without this the anchor below treats every one of those
|
|
1189
1194
|
/// as "the user moved the caret" and disarms the pending colour mid-sentence (ENG-38257).
|
|
1190
1195
|
private var lastKnownTextLength: Int = 0
|
|
1196
|
+
/// The text as of the last keyboard edit, so colourEditThatBypassedInheritance can find what
|
|
1197
|
+
/// the next edit changed.
|
|
1198
|
+
private var lastEditSnapshot: NSAttributedString?
|
|
1191
1199
|
|
|
1192
1200
|
/// Caret-armed consumer inline colour (no selection). A UIColor cannot live in a
|
|
1193
1201
|
/// `Set<String>` cleanly, so the value lives here while `ExternalColorPendingKey` goes into
|
|
@@ -1510,6 +1518,7 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
|
|
|
1510
1518
|
// A captured inheritance would otherwise be painted onto the first character of the
|
|
1511
1519
|
// next message, which is the same leak by a different route.
|
|
1512
1520
|
clearPendingInherit()
|
|
1521
|
+
lastEditSnapshot = nil
|
|
1513
1522
|
// Reset typingAttributes to plain so next typed text has no ghost formatting
|
|
1514
1523
|
let paragraphStyle = NSMutableParagraphStyle()
|
|
1515
1524
|
paragraphStyle.lineHeightMultiple = RichTextEditorView.defaultLineHeightMultiple
|
|
@@ -1575,6 +1584,78 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
|
|
|
1575
1584
|
clearPendingInherit()
|
|
1576
1585
|
}
|
|
1577
1586
|
|
|
1587
|
+
/// Colours a keyboard edit that bypassed the inheritance capture in shouldChangeTextIn.
|
|
1588
|
+
///
|
|
1589
|
+
/// iOS makes the double-space full stop by swapping the space for ". " without that capture
|
|
1590
|
+
/// taking effect, so the full stop and the space after it came out in the default colour and
|
|
1591
|
+
/// broke the coloured run — at the end of the text and mid-text alike (ENG-40922). This diffs
|
|
1592
|
+
/// the text against the last edit and gives the changed run the colour the shouldChangeTextIn
|
|
1593
|
+
/// rules would have: an armed colour first, else the run it replaced, else the character before.
|
|
1594
|
+
///
|
|
1595
|
+
/// Only keyboard-sized edits (a few characters) are considered, so a programmatic change that
|
|
1596
|
+
/// slipped between two snapshots — a send, setText from JS — is never mistaken for one.
|
|
1597
|
+
private func colourEditThatBypassedInheritance() {
|
|
1598
|
+
guard let now = textView.attributedText else { return }
|
|
1599
|
+
let before = lastEditSnapshot
|
|
1600
|
+
lastEditSnapshot = NSAttributedString(attributedString: now)
|
|
1601
|
+
// No snapshot yet means nothing was typed since the composer was last empty, so the old
|
|
1602
|
+
// text is empty — the first keystroke still gets diffed rather than skipped.
|
|
1603
|
+
let old = before ?? NSAttributedString()
|
|
1604
|
+
guard !pendingExternalForegroundCleared,
|
|
1605
|
+
!pendingStyles.contains("code"), !pendingStyles.contains("codeBlock") else { return }
|
|
1606
|
+
|
|
1607
|
+
let oldS = old.string as NSString, newS = now.string as NSString
|
|
1608
|
+
let minLen = min(oldS.length, newS.length)
|
|
1609
|
+
var prefix = 0
|
|
1610
|
+
while prefix < minLen && oldS.character(at: prefix) == newS.character(at: prefix) { prefix += 1 }
|
|
1611
|
+
var suffix = 0
|
|
1612
|
+
while suffix < minLen - prefix &&
|
|
1613
|
+
oldS.character(at: oldS.length - 1 - suffix) == newS.character(at: newS.length - 1 - suffix) { suffix += 1 }
|
|
1614
|
+
let oldRun = NSRange(location: prefix, length: oldS.length - prefix - suffix)
|
|
1615
|
+
var newRun = NSRange(location: prefix, length: newS.length - prefix - suffix)
|
|
1616
|
+
guard newRun.length > 0, newRun.length <= 3, oldRun.length <= 3 else { return }
|
|
1617
|
+
|
|
1618
|
+
func isColoured(_ r: NSRange) -> Bool {
|
|
1619
|
+
var found = false
|
|
1620
|
+
now.enumerateAttribute(ExternalForegroundKey, in: r) { v, _, stop in
|
|
1621
|
+
if v != nil { found = true; stop.pointee = true }
|
|
1622
|
+
}
|
|
1623
|
+
return found
|
|
1624
|
+
}
|
|
1625
|
+
// An insertion next to identical characters is ambiguous: a space typed beside an existing
|
|
1626
|
+
// space diffs as if the existing one were new, and colouring that one recolours text the
|
|
1627
|
+
// user did not touch. A keyboard insertion always ends at the caret, so among the equally
|
|
1628
|
+
// valid positions (sliding left through equal characters) take the one ending there.
|
|
1629
|
+
// Pure insertions only — a replacement has a definite position.
|
|
1630
|
+
if oldRun.length == 0 {
|
|
1631
|
+
var leftmost = newRun.location
|
|
1632
|
+
while leftmost > 0,
|
|
1633
|
+
newS.character(at: leftmost - 1) == newS.character(at: leftmost - 1 + newRun.length) {
|
|
1634
|
+
leftmost -= 1
|
|
1635
|
+
}
|
|
1636
|
+
let atCaret = textView.selectedRange.location - newRun.length
|
|
1637
|
+
if textView.selectedRange.length == 0, atCaret >= leftmost, atCaret <= newRun.location {
|
|
1638
|
+
newRun.location = atCaret
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
// Leave it alone if the run already carries a colour — the normal rules ran.
|
|
1642
|
+
guard !isColoured(newRun) else { return }
|
|
1643
|
+
|
|
1644
|
+
let source: [NSAttributedString.Key: Any]? =
|
|
1645
|
+
oldRun.length > 0 ? old.attributes(at: oldRun.location, effectiveRange: nil)
|
|
1646
|
+
: (newRun.location > 0 ? now.attributes(at: newRun.location - 1, effectiveRange: nil) : nil)
|
|
1647
|
+
let armed = pendingStyles.contains(ExternalColorPendingKey) ? pendingExternalForeground : nil
|
|
1648
|
+
guard source?[MentionMarkerKey] == nil, source?[LinkURLAttributeKey] == nil,
|
|
1649
|
+
let colour = armed ?? source?[ExternalForegroundKey] as? UIColor else { return }
|
|
1650
|
+
|
|
1651
|
+
let wasInternal = isInternalChange
|
|
1652
|
+
isInternalChange = true
|
|
1653
|
+
textView.textStorage.addAttribute(ExternalForegroundKey, value: colour, range: newRun)
|
|
1654
|
+
textView.textStorage.addAttribute(.foregroundColor, value: colour, range: newRun)
|
|
1655
|
+
isInternalChange = wasInternal
|
|
1656
|
+
lastEditSnapshot = NSAttributedString(attributedString: textView.attributedText)
|
|
1657
|
+
}
|
|
1658
|
+
|
|
1578
1659
|
func textViewDidChangeSelection(_ textView: UITextView) {
|
|
1579
1660
|
let range = textView.selectedRange
|
|
1580
1661
|
if range.length > 0 {
|
|
@@ -1609,7 +1690,12 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
|
|
|
1609
1690
|
// emoji, a paste, or an IME commit. Comparing against a hardcoded +1 classified all of
|
|
1610
1691
|
// those as a deliberate caret move and disarmed the colour, so text typed from the first
|
|
1611
1692
|
// autocorrection onwards sent as plain (ENG-38257).
|
|
1612
|
-
|
|
1693
|
+
//
|
|
1694
|
+
// Deleting at the anchor is editing too: a backspace moves the caret back by exactly the
|
|
1695
|
+
// characters removed. Counting only forward moves read it as a caret jump and dropped the
|
|
1696
|
+
// colour — accept a suggestion, backspace its trailing space, double-space for a full
|
|
1697
|
+
// stop, and everything after it sent plain (ENG-40922).
|
|
1698
|
+
let isTypingAdvance = insertedCount != 0 && range.location == pendingStylesInsertPos + insertedCount
|
|
1613
1699
|
if range.location != pendingStylesInsertPos && !isTypingAdvance {
|
|
1614
1700
|
// Preserve "codeBlock" across cursor movements — it's a persistent
|
|
1615
1701
|
// block-level style that should survive until explicitly toggled off
|
|
@@ -2625,6 +2711,7 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
|
|
|
2625
2711
|
// Before anything reads or snapshots the text: give the characters the keyboard just
|
|
2626
2712
|
// inserted the formatting they inherited (see applyPendingInheritedColour).
|
|
2627
2713
|
applyPendingInheritedColour()
|
|
2714
|
+
colourEditThatBypassedInheritance()
|
|
2628
2715
|
|
|
2629
2716
|
// Clear pending styles after text was typed (typingAttributes already applied them).
|
|
2630
2717
|
// Preserve inline styles (bold, italic, underline, strikethrough) — they persist
|
|
@@ -6022,7 +6109,15 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
|
|
|
6022
6109
|
|
|
6023
6110
|
isInternalChange = true
|
|
6024
6111
|
let savedTypingAttrs = textView.typingAttributes
|
|
6112
|
+
// Assigning attributedText moves the caret to the end. JS pushes mention ranges after
|
|
6113
|
+
// every content change, so editing mid-text — a double-space full stop, for one — sent
|
|
6114
|
+
// the caret to the end of the message (ENG-40922). The string is unchanged here, only
|
|
6115
|
+
// its attributes, so the old caret is still valid.
|
|
6116
|
+
let savedSelection = textView.selectedRange
|
|
6025
6117
|
textView.attributedText = mutableAttr
|
|
6118
|
+
if NSMaxRange(savedSelection) <= mutableAttr.length {
|
|
6119
|
+
textView.selectedRange = savedSelection
|
|
6120
|
+
}
|
|
6026
6121
|
textView.typingAttributes = savedTypingAttrs
|
|
6027
6122
|
// If a deferred restore is pending (from autoContinueListOnEnter),
|
|
6028
6123
|
// use those attrs instead — they carry the user's active formatting.
|
package/ios/SoundPlayer.m
CHANGED
|
@@ -2,12 +2,129 @@
|
|
|
2
2
|
#import <React/RCTBridgeModule.h>
|
|
3
3
|
#import "SoundPlayer.h"
|
|
4
4
|
#import "AVFoundation/AVFoundation.h"
|
|
5
|
+
#import <WebKit/WebKit.h>
|
|
6
|
+
#import <React/RCTUtils.h>
|
|
7
|
+
|
|
8
|
+
// AVAudioPlayer can't decode WebM/Opus — which is what browser MediaRecorder produces (the web UI Kit
|
|
9
|
+
// sends voice notes as WebM, sometimes under a .wav name). WebKit can, so those clips fall back to a
|
|
10
|
+
// hidden WKWebView <audio>. Everything AVAudioPlayer can open keeps the native path.
|
|
11
|
+
@interface CCWebAudioHandler : NSObject <WKScriptMessageHandler>
|
|
12
|
+
@property (nonatomic, copy) void (^onMessage)(NSDictionary *msg);
|
|
13
|
+
@end
|
|
14
|
+
@implementation CCWebAudioHandler
|
|
15
|
+
- (void)userContentController:(WKUserContentController *)ucc didReceiveScriptMessage:(WKScriptMessage *)message {
|
|
16
|
+
if ([message.body isKindOfClass:[NSDictionary class]] && self.onMessage) self.onMessage(message.body);
|
|
17
|
+
}
|
|
18
|
+
@end
|
|
19
|
+
|
|
20
|
+
// Duration: a MediaRecorder WebM has no duration header (audio.duration === Infinity) until you seek
|
|
21
|
+
// past the end, so dur() forces that seek once, then rewinds.
|
|
22
|
+
static NSString *const kWebAudioJS =
|
|
23
|
+
@"var a=new Audio();function post(m){window.webkit.messageHandlers.cc.postMessage(m)}"
|
|
24
|
+
"a.onended=function(){post({t:'end'})};"
|
|
25
|
+
"a.ontimeupdate=function(){if(!a._p)post({t:'pos',v:a.currentTime})};"
|
|
26
|
+
"a.onerror=function(){post({t:'err'})};"
|
|
27
|
+
"function dur(cb){if(isFinite(a.duration)&&a.duration>0)return cb(a.duration);a._p=true;"
|
|
28
|
+
"a.addEventListener('timeupdate',function h(){if(isFinite(a.duration)){a.removeEventListener('timeupdate',h);a._p=false;a.currentTime=0;cb(a.duration)}});a.currentTime=1e7}"
|
|
29
|
+
"function start(u,play){a.onloadedmetadata=function(){dur(function(d){post({t:'dur',v:d});"
|
|
30
|
+
"if(play)a.play().then(function(){post({t:'played'})}).catch(function(){post({t:'err'})})})};a.src=u;a.load()}";
|
|
5
31
|
|
|
6
32
|
|
|
7
33
|
@implementation CometChatSoundPlayer {
|
|
8
34
|
AVAudioPlayer *audioPlayer;
|
|
9
35
|
bool hasListeners;
|
|
10
36
|
NSString *currentUrl;
|
|
37
|
+
// WebM fallback player (see CCWebAudioHandler). Created and torn down with dispatch_sync on the
|
|
38
|
+
// main queue, so the method queue never sees a half-started player (a pause right after play
|
|
39
|
+
// used to find webPlayer == nil and fall through to audioPlayer).
|
|
40
|
+
WKWebView *webPlayer;
|
|
41
|
+
BOOL webPlaying;
|
|
42
|
+
double webPosition;
|
|
43
|
+
NSMutableSet<WKWebView *> *probes;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Hidden web view that loads `url` and reports {t:dur|played|pos|end|err} to `onMessage`.
|
|
47
|
+
- (WKWebView *)webAudioFor:(NSString *)url play:(BOOL)play onMessage:(void (^)(NSDictionary *))onMessage {
|
|
48
|
+
CCWebAudioHandler *handler = [CCWebAudioHandler new];
|
|
49
|
+
handler.onMessage = onMessage;
|
|
50
|
+
WKWebViewConfiguration *config = [WKWebViewConfiguration new];
|
|
51
|
+
config.allowsInlineMediaPlayback = YES;
|
|
52
|
+
config.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
|
|
53
|
+
[config.userContentController addScriptMessageHandler:handler name:@"cc"];
|
|
54
|
+
NSData *json = [NSJSONSerialization dataWithJSONObject:@[url] options:0 error:nil];
|
|
55
|
+
NSString *arg = [[NSString alloc] initWithData:json encoding:NSUTF8StringEncoding]; // ["<escaped url>"]
|
|
56
|
+
NSString *js = [NSString stringWithFormat:@"%@;start(%@[0],%@);", kWebAudioJS, arg, play ? @"true" : @"false"];
|
|
57
|
+
[config.userContentController addUserScript:[[WKUserScript alloc] initWithSource:js injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES]];
|
|
58
|
+
WKWebView *web = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 1, 1) configuration:config];
|
|
59
|
+
web.alpha = 0.01; // in a window so WebKit doesn't throttle it, but invisible
|
|
60
|
+
[RCTKeyWindow() addSubview:web];
|
|
61
|
+
[web loadHTMLString:@"<html><body></body></html>" baseURL:[NSURL URLWithString:@"https://localhost/"]];
|
|
62
|
+
return web;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
- (void)stopWebPlayer {
|
|
66
|
+
RCTUnsafeExecuteOnMainQueueSync(^{
|
|
67
|
+
[self->webPlayer evaluateJavaScript:@"a.pause()" completionHandler:nil];
|
|
68
|
+
[self->webPlayer.configuration.userContentController removeScriptMessageHandlerForName:@"cc"];
|
|
69
|
+
[self->webPlayer removeFromSuperview];
|
|
70
|
+
self->webPlayer = nil;
|
|
71
|
+
self->webPlaying = NO;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// One-shot duration probe for a clip AVAudioPlayer couldn't open.
|
|
76
|
+
- (void)probeWebDuration:(NSString *)url resolve:(RCTResponseSenderBlock)resolve {
|
|
77
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
78
|
+
if (!self->probes) self->probes = [NSMutableSet new];
|
|
79
|
+
__block WKWebView *probe = nil;
|
|
80
|
+
__block BOOL done = NO;
|
|
81
|
+
void (^finish)(int) = ^(int duration) { // main queue only; resolves once, tears the probe down
|
|
82
|
+
if (done) return;
|
|
83
|
+
done = YES;
|
|
84
|
+
resolve(@[[NSString stringWithFormat:@"{\"duration\":%d}", duration]]);
|
|
85
|
+
[probe.configuration.userContentController removeScriptMessageHandlerForName:@"cc"];
|
|
86
|
+
[probe removeFromSuperview];
|
|
87
|
+
[self->probes removeObject:probe];
|
|
88
|
+
};
|
|
89
|
+
probe = [self webAudioFor:url play:NO onMessage:^(NSDictionary *msg) {
|
|
90
|
+
if ([msg[@"t"] isEqual:@"dur"]) finish([msg[@"v"] intValue]);
|
|
91
|
+
else if ([msg[@"t"] isEqual:@"err"]) finish(0);
|
|
92
|
+
}];
|
|
93
|
+
[self->probes addObject:probe];
|
|
94
|
+
// A stalled load sends neither dur nor err: give up after 10 s instead of leaking the web view.
|
|
95
|
+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ finish(0); });
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
- (void)playWeb:(NSString *)url resolve:(RCTResponseSenderBlock)resolve {
|
|
100
|
+
RCTUnsafeExecuteOnMainQueueSync(^{
|
|
101
|
+
__block BOOL resolved = NO;
|
|
102
|
+
__block int duration = 0;
|
|
103
|
+
self->webPosition = 0;
|
|
104
|
+
self->webPlayer = [self webAudioFor:url play:YES onMessage:^(NSDictionary *msg) {
|
|
105
|
+
NSString *t = msg[@"t"];
|
|
106
|
+
if ([t isEqual:@"dur"]) {
|
|
107
|
+
duration = [msg[@"v"] intValue];
|
|
108
|
+
} else if ([t isEqual:@"played"]) {
|
|
109
|
+
self->webPlaying = YES;
|
|
110
|
+
if (!resolved) { resolved = YES; resolve(@[[NSString stringWithFormat:@"{\"success\":1, \"duration\":%d}", duration]]); }
|
|
111
|
+
} else if ([t isEqual:@"pos"]) {
|
|
112
|
+
self->webPosition = [msg[@"v"] doubleValue];
|
|
113
|
+
} else if ([t isEqual:@"end"]) {
|
|
114
|
+
self->webPlaying = NO;
|
|
115
|
+
if (self->hasListeners) [self sendEventWithName:@"soundPlayStatus" body:@{@"url": url}];
|
|
116
|
+
} else if ([t isEqual:@"err"]) {
|
|
117
|
+
if (!resolved) {
|
|
118
|
+
resolved = YES;
|
|
119
|
+
resolve(@[@"{\"success\":0, \"error\":\"Unsupported audio format\"}"]);
|
|
120
|
+
} else {
|
|
121
|
+
// Failed mid-clip (e.g. network drop): end it like a finished clip so the bubble resets.
|
|
122
|
+
self->webPlaying = NO;
|
|
123
|
+
if (self->hasListeners) [self sendEventWithName:@"soundPlayStatus" body:@{@"url": url}];
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}];
|
|
127
|
+
});
|
|
11
128
|
}
|
|
12
129
|
|
|
13
130
|
- (void)startObserving {
|
|
@@ -46,6 +163,10 @@ RCT_EXPORT_METHOD(prepareMediaPlayer:(NSString *) url
|
|
|
46
163
|
}
|
|
47
164
|
currentUrl = url;
|
|
48
165
|
audioPlayer = [[AVAudioPlayer alloc] initWithData:data error:nil];
|
|
166
|
+
if (!audioPlayer && data) {
|
|
167
|
+
[self probeWebDuration:url resolve:resolve];
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
49
170
|
[audioPlayer setDelegate: self];
|
|
50
171
|
int duration = [audioPlayer duration];
|
|
51
172
|
NSString *response = [NSString stringWithFormat:@"{\"duration\":%d}", duration];
|
|
@@ -85,12 +206,15 @@ RCT_EXPORT_METHOD(play:(NSString *) url
|
|
|
85
206
|
[audioPlayer stop];
|
|
86
207
|
[self sendEventWithName:@"soundPlayStatus" body:@{@"url": currentUrl}];
|
|
87
208
|
}
|
|
209
|
+
if (webPlayer) {
|
|
210
|
+
if (webPlaying && currentUrl) [self sendEventWithName:@"soundPlayStatus" body:@{@"url": currentUrl}];
|
|
211
|
+
[self stopWebPlayer];
|
|
212
|
+
}
|
|
88
213
|
currentUrl = url;
|
|
89
214
|
NSError *playerError = nil;
|
|
90
215
|
audioPlayer = [[AVAudioPlayer alloc] initWithData:data error:&playerError];
|
|
91
216
|
if (!audioPlayer) {
|
|
92
|
-
|
|
93
|
-
resolve(@[response]);
|
|
217
|
+
[self playWeb:url resolve:resolve];
|
|
94
218
|
return;
|
|
95
219
|
}
|
|
96
220
|
[audioPlayer setDelegate: self];
|
|
@@ -106,7 +230,12 @@ RCT_EXPORT_METHOD(play:(NSString *) url
|
|
|
106
230
|
// NOT seek. Matches Android's playAt(seconds) → seekTo().
|
|
107
231
|
RCT_EXPORT_METHOD(playAt:(NSInteger) atTime resolver:(RCTResponseSenderBlock)resolve) {
|
|
108
232
|
bool res = NO;
|
|
109
|
-
if (
|
|
233
|
+
if (webPlayer) {
|
|
234
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
235
|
+
[self->webPlayer evaluateJavaScript:[NSString stringWithFormat:@"a.currentTime=%ld", (long)atTime] completionHandler:nil];
|
|
236
|
+
});
|
|
237
|
+
res = YES;
|
|
238
|
+
} else if (audioPlayer != nil) {
|
|
110
239
|
audioPlayer.currentTime = (NSTimeInterval)atTime;
|
|
111
240
|
res = YES;
|
|
112
241
|
}
|
|
@@ -115,11 +244,18 @@ RCT_EXPORT_METHOD(playAt:(NSInteger) atTime resolver:(RCTResponseSenderBlock)res
|
|
|
115
244
|
}
|
|
116
245
|
|
|
117
246
|
RCT_EXPORT_METHOD(resume) {
|
|
247
|
+
if (webPlayer) {
|
|
248
|
+
webPlaying = YES;
|
|
249
|
+
dispatch_async(dispatch_get_main_queue(), ^{ [self->webPlayer evaluateJavaScript:@"a.play()" completionHandler:nil]; });
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
118
252
|
[audioPlayer play];
|
|
119
253
|
}
|
|
120
254
|
|
|
121
255
|
RCT_EXPORT_METHOD(getPosition:(RCTResponseSenderBlock) resolve) {
|
|
122
|
-
if (
|
|
256
|
+
if (webPlayer && webPlaying) {
|
|
257
|
+
resolve(@[[NSString stringWithFormat:@"{\"position\":%f}", webPosition]]);
|
|
258
|
+
} else if ([audioPlayer isPlaying]) {
|
|
123
259
|
NSString *response = [NSString stringWithFormat:@"{\"position\":%f}", [audioPlayer currentTime]];
|
|
124
260
|
resolve(@[response]);
|
|
125
261
|
} else {
|
|
@@ -128,7 +264,11 @@ RCT_EXPORT_METHOD(getPosition:(RCTResponseSenderBlock) resolve) {
|
|
|
128
264
|
}
|
|
129
265
|
|
|
130
266
|
RCT_EXPORT_METHOD(pause: (RCTResponseSenderBlock) resolve) {
|
|
131
|
-
if (
|
|
267
|
+
if (webPlayer && webPlaying) {
|
|
268
|
+
webPlaying = NO;
|
|
269
|
+
dispatch_async(dispatch_get_main_queue(), ^{ [self->webPlayer evaluateJavaScript:@"a.pause()" completionHandler:nil]; });
|
|
270
|
+
resolve(@[@"{\"success\": true}"]);
|
|
271
|
+
} else if ([audioPlayer isPlaying]) {
|
|
132
272
|
[audioPlayer pause];
|
|
133
273
|
resolve(@[@"{\"success\": true}"]);
|
|
134
274
|
} else {
|
|
@@ -137,6 +277,10 @@ RCT_EXPORT_METHOD(pause: (RCTResponseSenderBlock) resolve) {
|
|
|
137
277
|
}
|
|
138
278
|
|
|
139
279
|
RCT_EXPORT_METHOD(releaseMediaPlayer) {
|
|
280
|
+
// Stopping a clip that is playing must say so, or its bubble stays on "playing".
|
|
281
|
+
BOOL wasPlaying = (webPlayer && webPlaying) || [audioPlayer isPlaying];
|
|
282
|
+
if (wasPlaying && currentUrl && hasListeners) [self sendEventWithName:@"soundPlayStatus" body:@{@"url": currentUrl}];
|
|
283
|
+
if (webPlayer) [self stopWebPlayer];
|
|
140
284
|
if (audioPlayer) {
|
|
141
285
|
[audioPlayer stop];
|
|
142
286
|
audioPlayer = nil;
|
|
@@ -145,7 +289,9 @@ RCT_EXPORT_METHOD(releaseMediaPlayer) {
|
|
|
145
289
|
}
|
|
146
290
|
|
|
147
291
|
RCT_EXPORT_METHOD(getCurrentTime: (RCTResponseSenderBlock)resolve) {
|
|
148
|
-
if (
|
|
292
|
+
if (webPlayer && webPlaying) {
|
|
293
|
+
resolve(@[[NSString stringWithFormat:@"{\"time\": %f}", webPosition]]);
|
|
294
|
+
} else if ([audioPlayer isPlaying]) {
|
|
149
295
|
NSString *response = [NSString stringWithFormat:@"{\"time\": %f}",[audioPlayer currentTime]];
|
|
150
296
|
resolve(@[response]);
|
|
151
297
|
} else {
|
package/ios/VideoManager.m
CHANGED
|
@@ -16,7 +16,7 @@ RCT_EXPORT_MODULE(VideoManager);
|
|
|
16
16
|
QLPreviewController* previewCtrl = [[QLPreviewController alloc] init];
|
|
17
17
|
[previewCtrl setDataSource: self];
|
|
18
18
|
[[previewCtrl navigationController] setTitle:@""];
|
|
19
|
-
[previewCtrl setModalPresentationStyle:
|
|
19
|
+
[previewCtrl setModalPresentationStyle:UIModalPresentationFullScreen];
|
|
20
20
|
UIViewController *presentedViewController = RCTPresentedViewController();
|
|
21
21
|
[presentedViewController presentViewController:previewCtrl animated:YES completion:nil];
|
|
22
22
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cometchat/chat-uikit-react-native",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.6.0",
|
|
4
4
|
"description": "Ready-to-use Chat UI Components for React Native",
|
|
5
5
|
"main": "src/index",
|
|
6
6
|
"module": "src/index",
|
|
@@ -28,6 +28,11 @@
|
|
|
28
28
|
"test:native:ios": "cd ios-tests && UDID=$(xcrun simctl list devices available | grep -m1 iPhone | grep -oE '[0-9A-F-]{36}'); if [ -z \"$UDID\" ]; then echo \"No iPhone simulator is available. Install one via Xcode > Settings > Components.\" >&2; exit 1; fi; xcodebuild test -scheme RichTextEditorKit-Package -destination \"platform=iOS Simulator,id=$UDID\"",
|
|
29
29
|
"typescript": "tsc --noEmit",
|
|
30
30
|
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
31
|
+
"lint:offline": "eslint \"src/shared/offline/**/*.{ts,tsx}\"",
|
|
32
|
+
"api:check": "bash ./scripts/api-check.sh",
|
|
33
|
+
"sdk-floor:check": "bash ./scripts/sdk-floor-typecheck.sh",
|
|
34
|
+
"integrator:check": "bash ./scripts/integrator-compile-check.sh",
|
|
35
|
+
"probe:check": "bash ./scripts/probe-strip-check.sh",
|
|
31
36
|
"release": "release-it",
|
|
32
37
|
"format": "prettier --write ./src/**/*.{ts,tsx}"
|
|
33
38
|
},
|
|
@@ -87,15 +92,25 @@
|
|
|
87
92
|
"react-native-localize": "*",
|
|
88
93
|
"react-native-safe-area-context": "*",
|
|
89
94
|
"react-native-svg": "*",
|
|
90
|
-
"react-native-video": "*"
|
|
95
|
+
"react-native-video": "*",
|
|
96
|
+
"react-native-fs": "*"
|
|
97
|
+
},
|
|
98
|
+
"peerDependenciesMeta": {
|
|
99
|
+
"react-native-fs": {
|
|
100
|
+
"optional": true
|
|
101
|
+
}
|
|
91
102
|
},
|
|
92
103
|
"jest": {
|
|
93
104
|
"preset": "@react-native/jest-preset",
|
|
94
105
|
"modulePathIgnorePatterns": [
|
|
95
106
|
"<rootDir>/lib/"
|
|
96
107
|
],
|
|
108
|
+
"setupFiles": [
|
|
109
|
+
"<rootDir>/jest/setup.js"
|
|
110
|
+
],
|
|
97
111
|
"moduleNameMapper": {
|
|
98
|
-
"\\.(wav|mp3|m4a|aac|ogg)$": "<rootDir>/jest/assetMock.js"
|
|
112
|
+
"\\.(wav|mp3|m4a|aac|ogg)$": "<rootDir>/jest/assetMock.js",
|
|
113
|
+
"^@react-native-async-storage/async-storage$": "<rootDir>/jest/asyncStorageMock.js"
|
|
99
114
|
}
|
|
100
115
|
},
|
|
101
116
|
"commitlint": {
|
|
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
|
|
|
16
16
|
s.source_files = "ios/**/*.{h,m,mm,swift}"
|
|
17
17
|
|
|
18
18
|
s.static_framework = true # Set static_framework for the main spec if needed
|
|
19
|
-
s.frameworks = ["PhotosUI"]
|
|
19
|
+
s.frameworks = ["PhotosUI", "WebKit"]
|
|
20
20
|
|
|
21
21
|
s.subspec "Video" do |ss|
|
|
22
22
|
ss.source_files = "ios/Video/*.{h,m}"
|