@onyx-p/imlib-web 1.3.3 → 1.3.5
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/index.esm.js +100 -851
- package/index.umd.js +101 -855
- package/package.json +1 -1
- package/types/index.d.ts +2 -5
- package/types/model/baseMessage.d.ts +4 -2
- package/types/model/messages/fileMessage.d.ts +12 -13
- package/types/model/messages/gifMessage.d.ts +11 -12
- package/types/model/messages/imageMessage.d.ts +16 -16
- package/types/model/messages/recallCommandMessage.d.ts +5 -13
- package/types/model/messages/textMessage.d.ts +4 -8
- package/types/model/messages/voiceMessage.d.ts +9 -12
package/index.esm.js
CHANGED
@@ -8017,9 +8017,9 @@ var CmdIds;
|
|
8017
8017
|
CmdIds[CmdIds["DeletePrivateDialog"] = 1610682372] = "DeletePrivateDialog";
|
8018
8018
|
CmdIds[CmdIds["DeleteGroupDialog"] = 1610747908] = "DeleteGroupDialog";
|
8019
8019
|
CmdIds[CmdIds["GetDialogChangedStatus"] = 1610711094] = "GetDialogChangedStatus";
|
8020
|
+
CmdIds[CmdIds["HeartbeanResp"] = 268468225] = "HeartbeanResp";
|
8020
8021
|
CmdIds[CmdIds["NewMessagePush"] = 1610711040] = "NewMessagePush";
|
8021
8022
|
CmdIds[CmdIds["DialogChangedPush"] = 1610711096] = "DialogChangedPush";
|
8022
|
-
CmdIds[CmdIds["AppAllowLoginPush"] = 806453286] = "AppAllowLoginPush";
|
8023
8023
|
CmdIds[CmdIds["SessionKilledPush"] = 268468229] = "SessionKilledPush";
|
8024
8024
|
CmdIds[CmdIds["SignOutPish"] = 268439559] = "SignOutPish";
|
8025
8025
|
CmdIds[CmdIds["SignOutPish2"] = 268468231] = "SignOutPish2";
|
@@ -13394,7 +13394,9 @@ class WebSocketServer {
|
|
13394
13394
|
body: body,
|
13395
13395
|
deviceType: 7
|
13396
13396
|
};
|
13397
|
-
|
13397
|
+
if (cmdId !== CmdIds$1.Heartbean) {
|
13398
|
+
logger.info(`websocket send -> cmd: 0x${cmdId.toString(16)}, messageSeq: ${messageSeq}`);
|
13399
|
+
}
|
13398
13400
|
this.socket.send(buildWsPacketData(rpc_baseExports.NetworkRequest.encode(networkReq).finish()));
|
13399
13401
|
const respData = await new Promise(resolve => {
|
13400
13402
|
this.responseCallbacks.set(messageSeq, resolve);
|
@@ -13513,13 +13515,15 @@ class WebSocketServer {
|
|
13513
13515
|
return;
|
13514
13516
|
}
|
13515
13517
|
const messageSeq = Long.isLong(networkResponse.messageSeq) ? networkResponse.messageSeq.toNumber() : 0;
|
13516
|
-
|
13518
|
+
if (networkResponse.cmdId !== CmdIds$1.HeartbeanResp) {
|
13519
|
+
logger.info(`websocket recv ack -> messageSeq: ${messageSeq}`);
|
13520
|
+
}
|
13517
13521
|
const resolve = this.responseCallbacks.get(messageSeq);
|
13518
13522
|
if (isDef(resolve)) {
|
13519
13523
|
resolve(networkResponse.body);
|
13520
13524
|
this.responseCallbacks.delete(messageSeq);
|
13521
13525
|
} else {
|
13522
|
-
logger.
|
13526
|
+
logger.info(`websocket recv -> cmd: 0x${networkResponse.cmdId.toString(16)}, messageSeq: ${messageSeq}`);
|
13523
13527
|
this.watcher?.message(networkResponse.cmdId, networkResponse.body);
|
13524
13528
|
}
|
13525
13529
|
}
|
@@ -18712,331 +18716,6 @@ var RecallMessageStore = {
|
|
18712
18716
|
}
|
18713
18717
|
};
|
18714
18718
|
|
18715
|
-
const MessageSerializers = new Map();
|
18716
|
-
function registerMessageSerializer(aSerializer) {
|
18717
|
-
MessageSerializers.set(aSerializer.getObjectId(), aSerializer.decode.bind(aSerializer));
|
18718
|
-
}
|
18719
|
-
function decodeMessage(objectId, messageData) {
|
18720
|
-
const decodeFunc = MessageSerializers.get(objectId);
|
18721
|
-
const messageObject = decodeFunc ? decodeFunc(messageData) : null;
|
18722
|
-
return messageObject;
|
18723
|
-
}
|
18724
|
-
|
18725
|
-
class BaseMessage {
|
18726
|
-
content;
|
18727
|
-
isPersited;
|
18728
|
-
isCounted;
|
18729
|
-
isStatusMessage;
|
18730
|
-
constructor(content, isPersited = true, isCounted = true, isStatusMessage = false) {
|
18731
|
-
this.content = content;
|
18732
|
-
if (isStatusMessage) {
|
18733
|
-
this.isPersited = false;
|
18734
|
-
this.isCounted = false;
|
18735
|
-
} else {
|
18736
|
-
this.isPersited = isPersited;
|
18737
|
-
this.isCounted = isCounted;
|
18738
|
-
}
|
18739
|
-
this.isStatusMessage = isStatusMessage;
|
18740
|
-
}
|
18741
|
-
get objectId() {
|
18742
|
-
return this.constructor.getObjectId();
|
18743
|
-
}
|
18744
|
-
static getObjectId() {
|
18745
|
-
throw new Error('Method not implemented.');
|
18746
|
-
}
|
18747
|
-
static decode(aDecoder) {
|
18748
|
-
throw new Error('Method not implemented.');
|
18749
|
-
}
|
18750
|
-
encode() {
|
18751
|
-
throw new Error('Method not implemented.');
|
18752
|
-
}
|
18753
|
-
}
|
18754
|
-
|
18755
|
-
const MessageObjectIds = {
|
18756
|
-
TEXT: 0x00000000,
|
18757
|
-
IMAGE: 0x10001000,
|
18758
|
-
GIF: 0x1000100b,
|
18759
|
-
FILE: 0x1000100a,
|
18760
|
-
AUDIO: 0x10001001,
|
18761
|
-
CUST_COMMAND: 0x1000101d,
|
18762
|
-
CUST_STORAGE: 0x1000102d,
|
18763
|
-
CUST_NORMAL: 0x1000103d,
|
18764
|
-
CUST_STATUS: 0x1000104d,
|
18765
|
-
RECALL: 0x6001001d,
|
18766
|
-
CMD: 0x1000105d
|
18767
|
-
};
|
18768
|
-
|
18769
|
-
class TextMessage extends BaseMessage {
|
18770
|
-
constructor(content) {
|
18771
|
-
super(content);
|
18772
|
-
}
|
18773
|
-
static getObjectId() {
|
18774
|
-
return MessageObjectIds.TEXT;
|
18775
|
-
}
|
18776
|
-
static decode(aDecoder) {
|
18777
|
-
const {
|
18778
|
-
user,
|
18779
|
-
extra,
|
18780
|
-
content
|
18781
|
-
} = aDecoder;
|
18782
|
-
return new TextMessage({
|
18783
|
-
user,
|
18784
|
-
extra,
|
18785
|
-
content
|
18786
|
-
});
|
18787
|
-
}
|
18788
|
-
encode() {
|
18789
|
-
const {
|
18790
|
-
user,
|
18791
|
-
extra,
|
18792
|
-
content
|
18793
|
-
} = this.content;
|
18794
|
-
return {
|
18795
|
-
user,
|
18796
|
-
extra,
|
18797
|
-
content
|
18798
|
-
};
|
18799
|
-
}
|
18800
|
-
}
|
18801
|
-
|
18802
|
-
class IMConfig {
|
18803
|
-
_token = '';
|
18804
|
-
_uploadUrl = '';
|
18805
|
-
_downloadUrl = '';
|
18806
|
-
_cert = '';
|
18807
|
-
set imInitToken(val) {
|
18808
|
-
this._token = val;
|
18809
|
-
}
|
18810
|
-
get imInitToken() {
|
18811
|
-
return this._token;
|
18812
|
-
}
|
18813
|
-
get fileUploadUrl() {
|
18814
|
-
return this._uploadUrl;
|
18815
|
-
}
|
18816
|
-
get cert() {
|
18817
|
-
return this._cert;
|
18818
|
-
}
|
18819
|
-
get fileDownloadUrl() {
|
18820
|
-
return this._downloadUrl;
|
18821
|
-
}
|
18822
|
-
setFileServerInfo(uploadUrl, downloadUrl, cert) {
|
18823
|
-
this._uploadUrl = uploadUrl;
|
18824
|
-
this._downloadUrl = downloadUrl;
|
18825
|
-
this._cert = cert;
|
18826
|
-
}
|
18827
|
-
getFileAbsoluteUri(u) {
|
18828
|
-
if (!notEmptyString(u)) {
|
18829
|
-
return u;
|
18830
|
-
}
|
18831
|
-
if (u.startsWith('http')) {
|
18832
|
-
return u;
|
18833
|
-
}
|
18834
|
-
return this.fileDownloadUrl + u;
|
18835
|
-
}
|
18836
|
-
try2ExtractFileRelativeUri(u) {
|
18837
|
-
if (!notEmptyString(u)) {
|
18838
|
-
return u;
|
18839
|
-
}
|
18840
|
-
if (!u.startsWith(this.fileDownloadUrl)) {
|
18841
|
-
return u;
|
18842
|
-
}
|
18843
|
-
return u.substring(this.fileDownloadUrl.length);
|
18844
|
-
}
|
18845
|
-
}
|
18846
|
-
var imConfig = new IMConfig();
|
18847
|
-
|
18848
|
-
class ImageMessage extends BaseMessage {
|
18849
|
-
constructor(content) {
|
18850
|
-
super(content);
|
18851
|
-
}
|
18852
|
-
static getObjectId() {
|
18853
|
-
return MessageObjectIds.IMAGE;
|
18854
|
-
}
|
18855
|
-
static decode(aDecoder) {
|
18856
|
-
const {
|
18857
|
-
user,
|
18858
|
-
extra,
|
18859
|
-
thumbnailObjectKey,
|
18860
|
-
originalObjectKey,
|
18861
|
-
width,
|
18862
|
-
height
|
18863
|
-
} = aDecoder;
|
18864
|
-
return new ImageMessage({
|
18865
|
-
user,
|
18866
|
-
extra,
|
18867
|
-
content: thumbnailObjectKey,
|
18868
|
-
imageUri: imConfig.getFileAbsoluteUri(originalObjectKey),
|
18869
|
-
width,
|
18870
|
-
height
|
18871
|
-
});
|
18872
|
-
}
|
18873
|
-
encode() {
|
18874
|
-
const {
|
18875
|
-
user,
|
18876
|
-
extra,
|
18877
|
-
content,
|
18878
|
-
imageUri,
|
18879
|
-
width,
|
18880
|
-
height
|
18881
|
-
} = this.content;
|
18882
|
-
return {
|
18883
|
-
user,
|
18884
|
-
extra,
|
18885
|
-
thumbnailObjectKey: content,
|
18886
|
-
originalObjectKey: imConfig.try2ExtractFileRelativeUri(imageUri),
|
18887
|
-
width: width && Math.floor(width),
|
18888
|
-
height: height && Math.floor(height)
|
18889
|
-
};
|
18890
|
-
}
|
18891
|
-
}
|
18892
|
-
|
18893
|
-
class GIFMessage extends BaseMessage {
|
18894
|
-
constructor(content) {
|
18895
|
-
super(content);
|
18896
|
-
}
|
18897
|
-
static getObjectId() {
|
18898
|
-
return MessageObjectIds.GIF;
|
18899
|
-
}
|
18900
|
-
static decode(aDecoder) {
|
18901
|
-
const {
|
18902
|
-
user,
|
18903
|
-
extra,
|
18904
|
-
size,
|
18905
|
-
originalObjectKey,
|
18906
|
-
width,
|
18907
|
-
height
|
18908
|
-
} = aDecoder;
|
18909
|
-
return new GIFMessage({
|
18910
|
-
user,
|
18911
|
-
extra,
|
18912
|
-
gifDataSize: size,
|
18913
|
-
remoteUrl: imConfig.getFileAbsoluteUri(originalObjectKey),
|
18914
|
-
width,
|
18915
|
-
height
|
18916
|
-
});
|
18917
|
-
}
|
18918
|
-
encode() {
|
18919
|
-
const {
|
18920
|
-
user,
|
18921
|
-
extra,
|
18922
|
-
gifDataSize,
|
18923
|
-
remoteUrl,
|
18924
|
-
width,
|
18925
|
-
height
|
18926
|
-
} = this.content;
|
18927
|
-
return {
|
18928
|
-
user,
|
18929
|
-
extra,
|
18930
|
-
size: gifDataSize,
|
18931
|
-
originalObjectKey: imConfig.try2ExtractFileRelativeUri(remoteUrl),
|
18932
|
-
width: width && Math.floor(width),
|
18933
|
-
height: height && Math.floor(height),
|
18934
|
-
extension: 'gif'
|
18935
|
-
};
|
18936
|
-
}
|
18937
|
-
}
|
18938
|
-
|
18939
|
-
class HQVoiceMessage extends BaseMessage {
|
18940
|
-
constructor(content) {
|
18941
|
-
super(content);
|
18942
|
-
}
|
18943
|
-
static getObjectId() {
|
18944
|
-
return MessageObjectIds.AUDIO;
|
18945
|
-
}
|
18946
|
-
static decode(aDecoder) {
|
18947
|
-
const {
|
18948
|
-
user,
|
18949
|
-
extra,
|
18950
|
-
length,
|
18951
|
-
audioObjectKey,
|
18952
|
-
extension
|
18953
|
-
} = aDecoder;
|
18954
|
-
return new HQVoiceMessage({
|
18955
|
-
user,
|
18956
|
-
extra,
|
18957
|
-
remoteUrl: imConfig.getFileAbsoluteUri(audioObjectKey),
|
18958
|
-
duration: length,
|
18959
|
-
type: extension
|
18960
|
-
});
|
18961
|
-
}
|
18962
|
-
encode() {
|
18963
|
-
const {
|
18964
|
-
user,
|
18965
|
-
extra,
|
18966
|
-
remoteUrl,
|
18967
|
-
duration,
|
18968
|
-
type
|
18969
|
-
} = this.content;
|
18970
|
-
return {
|
18971
|
-
user,
|
18972
|
-
extra,
|
18973
|
-
length: duration,
|
18974
|
-
audioObjectKey: imConfig.try2ExtractFileRelativeUri(remoteUrl),
|
18975
|
-
extension: type
|
18976
|
-
};
|
18977
|
-
}
|
18978
|
-
}
|
18979
|
-
|
18980
|
-
class FileMessage extends BaseMessage {
|
18981
|
-
constructor(content) {
|
18982
|
-
super(content);
|
18983
|
-
}
|
18984
|
-
static getObjectId() {
|
18985
|
-
return MessageObjectIds.FILE;
|
18986
|
-
}
|
18987
|
-
static decode(aDecoder) {
|
18988
|
-
const {
|
18989
|
-
user,
|
18990
|
-
extra,
|
18991
|
-
title,
|
18992
|
-
extension,
|
18993
|
-
size,
|
18994
|
-
originalObjectKey
|
18995
|
-
} = aDecoder;
|
18996
|
-
return new FileMessage({
|
18997
|
-
user,
|
18998
|
-
extra,
|
18999
|
-
name: title,
|
19000
|
-
size,
|
19001
|
-
type: extension,
|
19002
|
-
fileUrl: imConfig.getFileAbsoluteUri(originalObjectKey)
|
19003
|
-
});
|
19004
|
-
}
|
19005
|
-
encode() {
|
19006
|
-
const {
|
19007
|
-
user,
|
19008
|
-
extra,
|
19009
|
-
name,
|
19010
|
-
size,
|
19011
|
-
type,
|
19012
|
-
fileUrl
|
19013
|
-
} = this.content;
|
19014
|
-
return {
|
19015
|
-
user,
|
19016
|
-
extra,
|
19017
|
-
title: name,
|
19018
|
-
originalObjectKey: imConfig.try2ExtractFileRelativeUri(fileUrl),
|
19019
|
-
extension: type,
|
19020
|
-
size
|
19021
|
-
};
|
19022
|
-
}
|
19023
|
-
}
|
19024
|
-
|
19025
|
-
class RecallCommandMessage extends BaseMessage {
|
19026
|
-
constructor(content) {
|
19027
|
-
super(content, true, false, false);
|
19028
|
-
}
|
19029
|
-
static getObjectId() {
|
19030
|
-
return MessageObjectIds.RECALL;
|
19031
|
-
}
|
19032
|
-
static decode(aDecoder) {
|
19033
|
-
return new RecallCommandMessage(aDecoder);
|
19034
|
-
}
|
19035
|
-
encode() {
|
19036
|
-
return this.content;
|
19037
|
-
}
|
19038
|
-
}
|
19039
|
-
|
19040
18719
|
class DialogSecretKey {
|
19041
18720
|
aesKeyRecord = new Map();
|
19042
18721
|
async getDialogAesKey(dialogId) {
|
@@ -19186,6 +18865,27 @@ const wordToUInt8Array = wordArray => {
|
|
19186
18865
|
return new Uint8Array(array);
|
19187
18866
|
};
|
19188
18867
|
|
18868
|
+
const MessageSerializers = new Map();
|
18869
|
+
function decodeMessage(objectId, messageData) {
|
18870
|
+
const decodeFunc = MessageSerializers.get(objectId);
|
18871
|
+
const messageObject = decodeFunc ? decodeFunc(messageData) : null;
|
18872
|
+
return messageObject;
|
18873
|
+
}
|
18874
|
+
|
18875
|
+
const MessageTypes = {
|
18876
|
+
TEXT: 0x00000000,
|
18877
|
+
IMAGE: 0x10001000,
|
18878
|
+
GIF: 0x1000100b,
|
18879
|
+
FILE: 0x1000100a,
|
18880
|
+
AUDIO: 0x10001001,
|
18881
|
+
CUST_COMMAND: 0x1000101d,
|
18882
|
+
CUST_STORAGE: 0x1000102d,
|
18883
|
+
CUST_NORMAL: 0x1000103d,
|
18884
|
+
CUST_STATUS: 0x1000104d,
|
18885
|
+
RECALL: 0x6001001d,
|
18886
|
+
CMD: 0x1000105d
|
18887
|
+
};
|
18888
|
+
|
19189
18889
|
const STATUSMESSAGE_ALIVE_TIMEMS = 6000;
|
19190
18890
|
function parse(orginalMsgs, callback) {
|
19191
18891
|
const msgs = new Map();
|
@@ -19241,12 +18941,9 @@ const parseSingleDialogMessages = (dialogId, originalMessageList, aesKey) => {
|
|
19241
18941
|
sendTime
|
19242
18942
|
} = mediaAttributeJson;
|
19243
18943
|
const recallContent = {
|
19244
|
-
|
19245
|
-
messageUId: msgId,
|
19246
|
-
conversationType: conversation.conversationType,
|
19247
|
-
targetId: dialogMessage.isOut ? conversation.targetId : accountStore.uid
|
18944
|
+
msgId: msgId
|
19248
18945
|
};
|
19249
|
-
mediaConstructor =
|
18946
|
+
mediaConstructor = MessageTypes.RECALL;
|
19250
18947
|
mediaAttributeJson = recallContent;
|
19251
18948
|
recallMessageUIds.add(msgId);
|
19252
18949
|
}
|
@@ -19392,7 +19089,7 @@ class ConversationStore {
|
|
19392
19089
|
messageDirection
|
19393
19090
|
} = message;
|
19394
19091
|
const isSelfSend = messageDirection === MessageDirection.SEND;
|
19395
|
-
const isRecall = messageType ===
|
19092
|
+
const isRecall = messageType === MessageTypes.RECALL;
|
19396
19093
|
const hasContent = isObject(content);
|
19397
19094
|
const key = {
|
19398
19095
|
conversationType,
|
@@ -19426,7 +19123,7 @@ class ConversationStore {
|
|
19426
19123
|
messageDirection,
|
19427
19124
|
content
|
19428
19125
|
} = message;
|
19429
|
-
if (messageDirection === MessageDirection.SEND || !isMentioned && messageType !==
|
19126
|
+
if (messageDirection === MessageDirection.SEND || !isMentioned && messageType !== MessageTypes.RECALL) {
|
19430
19127
|
return;
|
19431
19128
|
}
|
19432
19129
|
const key = this.getStoreKey({
|
@@ -19441,9 +19138,9 @@ class ConversationStore {
|
|
19441
19138
|
localMentionedUIdList.push(messageUId.toString());
|
19442
19139
|
}
|
19443
19140
|
}
|
19444
|
-
if (messageType ===
|
19141
|
+
if (messageType === MessageTypes.RECALL && conversationType === ConversationType.GROUP) {
|
19445
19142
|
const recallContent = content;
|
19446
|
-
const index = localMentionedUIdList.indexOf(recallContent.
|
19143
|
+
const index = localMentionedUIdList.indexOf(recallContent.msgId.toString());
|
19447
19144
|
if (index >= 0) {
|
19448
19145
|
localMentionedUIdList.splice(index, 1);
|
19449
19146
|
}
|
@@ -19565,7 +19262,7 @@ class ConversationStatus {
|
|
19565
19262
|
data
|
19566
19263
|
} = await getDialogChangedStatus(offset);
|
19567
19264
|
if (code === ErrorCode.SUCCESS) {
|
19568
|
-
if (data.setTime.toNumber() > 0) {
|
19265
|
+
if (Long.isLong(data.setTime) && data.setTime.toNumber() > 0) {
|
19569
19266
|
SecureStorageService.set(this.storageKey, data.setTime.toNumber());
|
19570
19267
|
}
|
19571
19268
|
if (data.briefDialog) {
|
@@ -20059,7 +19756,6 @@ class MessageLoader {
|
|
20059
19756
|
};
|
20060
19757
|
});
|
20061
19758
|
ConversationManager$1.get().loadConvsationsIfNotExist(cons);
|
20062
|
-
debugger;
|
20063
19759
|
ServerMessageParser.parse(msg, (done, outputMsgs) => {
|
20064
19760
|
const messages = [];
|
20065
19761
|
const conversations = [];
|
@@ -20069,7 +19765,7 @@ class MessageLoader {
|
|
20069
19765
|
l.forEach(m => {
|
20070
19766
|
if (m.messageDirection === MessageDirection.SEND && m.messageId && SentMessageStore.has(m.messageId)) {
|
20071
19767
|
SentMessageStore.remove(m.messageId);
|
20072
|
-
} else if (m.messageType ===
|
19768
|
+
} else if (m.messageType === MessageTypes.RECALL && RecallMessageStore.has(m.content.messageUId)) {
|
20073
19769
|
RecallMessageStore.remove(m.content.messageUId);
|
20074
19770
|
} else {
|
20075
19771
|
m.isOffLineMessage = isOffLineMessage;
|
@@ -20112,7 +19808,7 @@ class MessageLoader {
|
|
20112
19808
|
}
|
20113
19809
|
}
|
20114
19810
|
|
20115
|
-
const DEFAULT_SOCKET_URI = 'wss://
|
19811
|
+
const DEFAULT_SOCKET_URI = 'wss://imweb.mp.net:6443';
|
20116
19812
|
class LibLoader {
|
20117
19813
|
options;
|
20118
19814
|
connectionStatus = ConnectionStatus.DISCONNECTED;
|
@@ -20138,7 +19834,8 @@ class LibLoader {
|
|
20138
19834
|
onSuspend: undefined,
|
20139
19835
|
pullFinished: undefined,
|
20140
19836
|
batchMessage: undefined,
|
20141
|
-
conversationState: undefined
|
19837
|
+
conversationState: undefined,
|
19838
|
+
onPush: undefined
|
20142
19839
|
};
|
20143
19840
|
webSocketServer.setServerInfo(this.getWebSocketUrl());
|
20144
19841
|
webSocketServer.setCallback({
|
@@ -20157,14 +19854,7 @@ class LibLoader {
|
|
20157
19854
|
}
|
20158
19855
|
return DEFAULT_SOCKET_URI;
|
20159
19856
|
}
|
20160
|
-
registerMessage() {
|
20161
|
-
registerMessageSerializer(TextMessage);
|
20162
|
-
registerMessageSerializer(ImageMessage);
|
20163
|
-
registerMessageSerializer(GIFMessage);
|
20164
|
-
registerMessageSerializer(HQVoiceMessage);
|
20165
|
-
registerMessageSerializer(RecallCommandMessage);
|
20166
|
-
registerMessageSerializer(FileMessage);
|
20167
|
-
}
|
19857
|
+
registerMessage() {}
|
20168
19858
|
async connect() {
|
20169
19859
|
if (this.connectionStatus === ConnectionStatus.CONNECTED) {
|
20170
19860
|
return {
|
@@ -26844,6 +26534,56 @@ function requireProtobufjs () {
|
|
26844
26534
|
var protobufjsExports = requireProtobufjs();
|
26845
26535
|
var protobuf = /*@__PURE__*/getDefaultExportFromCjs(protobufjsExports);
|
26846
26536
|
|
26537
|
+
class BaseMessage {
|
26538
|
+
messageType;
|
26539
|
+
content;
|
26540
|
+
isPersited;
|
26541
|
+
isCounted;
|
26542
|
+
isStatusMessage;
|
26543
|
+
constructor(messageType, content, isPersited = true, isCounted = true, isStatusMessage = false) {
|
26544
|
+
this.messageType = messageType;
|
26545
|
+
this.content = content;
|
26546
|
+
if (isStatusMessage) {
|
26547
|
+
this.isPersited = false;
|
26548
|
+
this.isCounted = false;
|
26549
|
+
} else {
|
26550
|
+
this.isPersited = isPersited;
|
26551
|
+
this.isCounted = isCounted;
|
26552
|
+
}
|
26553
|
+
this.isStatusMessage = isStatusMessage;
|
26554
|
+
}
|
26555
|
+
get objectId() {
|
26556
|
+
return this.constructor.getObjectId();
|
26557
|
+
}
|
26558
|
+
static getObjectId() {
|
26559
|
+
throw new Error('Method not implemented.');
|
26560
|
+
}
|
26561
|
+
static decode(aDecoder) {
|
26562
|
+
throw new Error('Method not implemented.');
|
26563
|
+
}
|
26564
|
+
encode() {
|
26565
|
+
throw new Error('Method not implemented.');
|
26566
|
+
}
|
26567
|
+
}
|
26568
|
+
const registerMessageType$1 = (messageType, isPersited, isCounted, isStatusMessage) => {
|
26569
|
+
const defined = function (content) {
|
26570
|
+
return new BaseMessage(messageType, content, isPersited, isCounted, isStatusMessage);
|
26571
|
+
};
|
26572
|
+
return defined;
|
26573
|
+
};
|
26574
|
+
|
26575
|
+
const TextMessage = registerMessageType$1(MessageTypes.TEXT, true, true, false);
|
26576
|
+
|
26577
|
+
const ImageMessage = registerMessageType$1(MessageTypes.IMAGE, true, true, false);
|
26578
|
+
|
26579
|
+
const GIFMessage = registerMessageType$1(MessageTypes.GIF, true, true, false);
|
26580
|
+
|
26581
|
+
const VoiceMessage = registerMessageType$1(MessageTypes.AUDIO, true, true, false);
|
26582
|
+
|
26583
|
+
const FileMessage = registerMessageType$1(MessageTypes.FILE, true, true, false);
|
26584
|
+
|
26585
|
+
const RecallCommandMessage = registerMessageType$1(MessageTypes.RECALL, true, false, false);
|
26586
|
+
|
26847
26587
|
const transSentAttrs2IReceivedMessage = (message, options, sentStatus = SentStatus.SENDING) => ({
|
26848
26588
|
conversationType: options.conversation.conversationType,
|
26849
26589
|
targetId: options.conversation.targetId,
|
@@ -26875,411 +26615,10 @@ function generateMessageId() {
|
|
26875
26615
|
return 230000000000000 + UniqueLocalId;
|
26876
26616
|
}
|
26877
26617
|
|
26878
|
-
const getBlobUrl = blob => {
|
26879
|
-
const URL = window.URL || window.webkitURL;
|
26880
|
-
return URL ? URL.createObjectURL(blob) : '';
|
26881
|
-
};
|
26882
|
-
const getBlobExtension = blob => {
|
26883
|
-
const name = blob.name;
|
26884
|
-
if (notEmptyString(name)) {
|
26885
|
-
return name.substring(name.lastIndexOf('.') + 1);
|
26886
|
-
}
|
26887
|
-
return blob.type.indexOf('/') > 0 ? blob.type.substring(blob.type.lastIndexOf('/') + 1) : '';
|
26888
|
-
};
|
26889
|
-
const blob2ArrayBuffer = blob => {
|
26890
|
-
if (isPromise(blob.arrayBuffer)) {
|
26891
|
-
return blob.arrayBuffer();
|
26892
|
-
}
|
26893
|
-
return new Promise((resolve, reject) => {
|
26894
|
-
const reader = new FileReader();
|
26895
|
-
reader.addEventListener('load', event => {
|
26896
|
-
if (event.target) {
|
26897
|
-
resolve(event.target.result);
|
26898
|
-
} else {
|
26899
|
-
reject('null');
|
26900
|
-
}
|
26901
|
-
});
|
26902
|
-
reader.addEventListener('error', error => reject(error));
|
26903
|
-
reader.readAsArrayBuffer(blob);
|
26904
|
-
});
|
26905
|
-
};
|
26906
|
-
const revokeBlobUrl = url => {
|
26907
|
-
const URL = window.URL || window.webkitURL;
|
26908
|
-
URL.revokeObjectURL(url);
|
26909
|
-
};
|
26910
|
-
const dataURL2Blob = url => {
|
26911
|
-
const type = url.match(/data:([^;]+)/)[1];
|
26912
|
-
const base64 = url.replace(/^[^,]+,/, '');
|
26913
|
-
const bstr = window.atob(base64);
|
26914
|
-
let n = bstr.length;
|
26915
|
-
const u8arr = new Uint8Array(bstr.length);
|
26916
|
-
while (n--) {
|
26917
|
-
u8arr[n] = bstr.charCodeAt(n);
|
26918
|
-
}
|
26919
|
-
return new Blob([u8arr], {
|
26920
|
-
type
|
26921
|
-
});
|
26922
|
-
};
|
26923
|
-
|
26924
|
-
const COMPRESS_LENGTH_MAX = 1680;
|
26925
|
-
const COMPRESS_LENGTH_MIN = 160;
|
26926
|
-
const getImageObj = link => {
|
26927
|
-
return new Promise((resolve, reject) => {
|
26928
|
-
const handle = image => {
|
26929
|
-
if (image.width !== 0 || image.height !== 0) {
|
26930
|
-
resolve(image);
|
26931
|
-
} else {
|
26932
|
-
reject();
|
26933
|
-
}
|
26934
|
-
};
|
26935
|
-
const image = new Image();
|
26936
|
-
image.addEventListener('load', event => handle(event.target));
|
26937
|
-
image.addEventListener('error', reject);
|
26938
|
-
image.src = link;
|
26939
|
-
if (image.complete) {
|
26940
|
-
handle(image);
|
26941
|
-
return;
|
26942
|
-
}
|
26943
|
-
const intervalId = setInterval(() => {
|
26944
|
-
if (image.complete) {
|
26945
|
-
handle(image);
|
26946
|
-
clearInterval(intervalId);
|
26947
|
-
}
|
26948
|
-
}, 40);
|
26949
|
-
});
|
26950
|
-
};
|
26951
|
-
const compress = (image, quality = 1, mineType = 'image/jpeg') => {
|
26952
|
-
quality = Math.min(1, quality);
|
26953
|
-
const width = image.width;
|
26954
|
-
const height = image.height;
|
26955
|
-
let compressWidth = width;
|
26956
|
-
let compressHeight = height;
|
26957
|
-
if (quality < 1) {
|
26958
|
-
const isheight = width < height;
|
26959
|
-
const zoom = isheight ? height / COMPRESS_LENGTH_MAX : width / COMPRESS_LENGTH_MAX;
|
26960
|
-
if (width > COMPRESS_LENGTH_MAX && height > COMPRESS_LENGTH_MAX) {
|
26961
|
-
if (isheight) {
|
26962
|
-
compressHeight = COMPRESS_LENGTH_MAX;
|
26963
|
-
compressWidth = compressWidth / zoom;
|
26964
|
-
} else {
|
26965
|
-
compressWidth = COMPRESS_LENGTH_MAX;
|
26966
|
-
compressHeight = compressHeight / zoom;
|
26967
|
-
}
|
26968
|
-
} else if (width > COMPRESS_LENGTH_MAX && height > COMPRESS_LENGTH_MIN) {
|
26969
|
-
compressWidth = COMPRESS_LENGTH_MAX;
|
26970
|
-
compressHeight = compressHeight / zoom;
|
26971
|
-
if (compressHeight < COMPRESS_LENGTH_MIN) {
|
26972
|
-
compressHeight = COMPRESS_LENGTH_MIN;
|
26973
|
-
compressWidth = width / (height / COMPRESS_LENGTH_MIN);
|
26974
|
-
}
|
26975
|
-
} else if (height > COMPRESS_LENGTH_MAX && width > COMPRESS_LENGTH_MIN) {
|
26976
|
-
compressHeight = COMPRESS_LENGTH_MAX;
|
26977
|
-
compressWidth = compressWidth / zoom;
|
26978
|
-
if (compressWidth < COMPRESS_LENGTH_MIN) {
|
26979
|
-
compressWidth = COMPRESS_LENGTH_MIN;
|
26980
|
-
compressHeight = height / (width / COMPRESS_LENGTH_MIN);
|
26981
|
-
}
|
26982
|
-
}
|
26983
|
-
}
|
26984
|
-
compressWidth = Math.floor(compressWidth);
|
26985
|
-
compressHeight = Math.floor(compressHeight);
|
26986
|
-
const canvas = document.createElement('canvas');
|
26987
|
-
canvas.width = compressWidth;
|
26988
|
-
canvas.height = compressHeight;
|
26989
|
-
const ctx = canvas.getContext('2d');
|
26990
|
-
ctx.fillStyle = '#FFF';
|
26991
|
-
ctx.fillRect(0, 0, compressWidth, compressHeight);
|
26992
|
-
ctx.drawImage(image, 0, 0, width, height, 0, 0, compressWidth, compressHeight);
|
26993
|
-
if (!mineType || mineType == 'image/png') {
|
26994
|
-
mineType = 'image/jpeg';
|
26995
|
-
}
|
26996
|
-
return {
|
26997
|
-
imageFile: dataURL2Blob(canvas.toDataURL(mineType, Math.min(0.92, quality))),
|
26998
|
-
compressWidth,
|
26999
|
-
compressHeight
|
27000
|
-
};
|
27001
|
-
};
|
27002
|
-
const getThumbnail = (img, thumbnailConfig) => {
|
27003
|
-
const canvas = document.createElement('canvas');
|
27004
|
-
const context = canvas.getContext('2d');
|
27005
|
-
const pos = calcPosition(img.width, img.height, thumbnailConfig);
|
27006
|
-
canvas.width = pos.w > thumbnailConfig.maxWidth ? thumbnailConfig.maxWidth : pos.w;
|
27007
|
-
canvas.height = pos.h > thumbnailConfig.maxHeight ? thumbnailConfig.maxHeight : pos.h;
|
27008
|
-
context?.drawImage(img, pos.x, pos.y, pos.w, pos.h);
|
27009
|
-
try {
|
27010
|
-
let base64 = canvas.toDataURL('image/jpeg', thumbnailConfig.quality);
|
27011
|
-
const reg = new RegExp('^data:image/[^;]+;base64,');
|
27012
|
-
base64 = base64.replace(reg, '');
|
27013
|
-
return base64;
|
27014
|
-
} catch (e) {
|
27015
|
-
throw new Error(e);
|
27016
|
-
}
|
27017
|
-
};
|
27018
|
-
function calcPosition(width, height, thumbnailConfig) {
|
27019
|
-
const isheight = width < height;
|
27020
|
-
const scale = isheight ? height / width : width / height;
|
27021
|
-
let zoom;
|
27022
|
-
let x = 0;
|
27023
|
-
let y = 0;
|
27024
|
-
let w;
|
27025
|
-
let h;
|
27026
|
-
const gtScale = function () {
|
27027
|
-
if (isheight) {
|
27028
|
-
zoom = width / 100;
|
27029
|
-
w = 100;
|
27030
|
-
h = height / zoom;
|
27031
|
-
y = (h - thumbnailConfig.maxHeight) / 2;
|
27032
|
-
} else {
|
27033
|
-
zoom = height / 100;
|
27034
|
-
h = 100;
|
27035
|
-
w = width / zoom;
|
27036
|
-
x = (w - thumbnailConfig.maxWidth) / 2;
|
27037
|
-
}
|
27038
|
-
return {
|
27039
|
-
w: w,
|
27040
|
-
h: h,
|
27041
|
-
x: -x,
|
27042
|
-
y: -y
|
27043
|
-
};
|
27044
|
-
};
|
27045
|
-
const ltScale = function () {
|
27046
|
-
if (isheight) {
|
27047
|
-
zoom = height / thumbnailConfig.maxHeight;
|
27048
|
-
h = thumbnailConfig.maxHeight;
|
27049
|
-
w = width / zoom;
|
27050
|
-
} else {
|
27051
|
-
zoom = width / thumbnailConfig.maxWidth;
|
27052
|
-
w = thumbnailConfig.maxWidth;
|
27053
|
-
h = height / zoom;
|
27054
|
-
}
|
27055
|
-
return {
|
27056
|
-
w: w,
|
27057
|
-
h: h,
|
27058
|
-
x: -x,
|
27059
|
-
y: -y
|
27060
|
-
};
|
27061
|
-
};
|
27062
|
-
return scale > thumbnailConfig.scale ? gtScale() : ltScale();
|
27063
|
-
}
|
27064
|
-
|
27065
|
-
class Img {
|
27066
|
-
async create(file) {
|
27067
|
-
try {
|
27068
|
-
const blobUrl = getBlobUrl(file);
|
27069
|
-
const image = await getImageObj(blobUrl);
|
27070
|
-
revokeBlobUrl(blobUrl);
|
27071
|
-
const {
|
27072
|
-
imageFile: sentImageFile,
|
27073
|
-
compressWidth,
|
27074
|
-
compressHeight
|
27075
|
-
} = compress(image, 0.85, file.type);
|
27076
|
-
const config = {
|
27077
|
-
maxHeight: 160,
|
27078
|
-
maxWidth: 160,
|
27079
|
-
quality: 0.6,
|
27080
|
-
scale: 2.4
|
27081
|
-
};
|
27082
|
-
const thumbnail = getThumbnail(image, config);
|
27083
|
-
return {
|
27084
|
-
success: true,
|
27085
|
-
message: new ImageMessage({
|
27086
|
-
content: thumbnail,
|
27087
|
-
imageUri: getBlobUrl(sentImageFile),
|
27088
|
-
width: compressWidth,
|
27089
|
-
height: compressHeight
|
27090
|
-
}),
|
27091
|
-
file: sentImageFile
|
27092
|
-
};
|
27093
|
-
} catch (error) {
|
27094
|
-
return {
|
27095
|
-
success: false
|
27096
|
-
};
|
27097
|
-
}
|
27098
|
-
}
|
27099
|
-
updateMessageRemoteUrlProperty(msg, remoteUrl) {
|
27100
|
-
msg.content.imageUri = remoteUrl;
|
27101
|
-
}
|
27102
|
-
}
|
27103
|
-
class GIF {
|
27104
|
-
async create(file) {
|
27105
|
-
if (file.size > 2 * 1024 * 1024) {
|
27106
|
-
return {
|
27107
|
-
success: false
|
27108
|
-
};
|
27109
|
-
}
|
27110
|
-
try {
|
27111
|
-
const blobUrl = getBlobUrl(file);
|
27112
|
-
const image = await getImageObj(blobUrl);
|
27113
|
-
return {
|
27114
|
-
success: true,
|
27115
|
-
message: new GIFMessage({
|
27116
|
-
gifDataSize: file.size,
|
27117
|
-
remoteUrl: blobUrl,
|
27118
|
-
width: image.width,
|
27119
|
-
height: image.height
|
27120
|
-
}),
|
27121
|
-
file: file
|
27122
|
-
};
|
27123
|
-
} catch {
|
27124
|
-
return {
|
27125
|
-
success: false
|
27126
|
-
};
|
27127
|
-
}
|
27128
|
-
}
|
27129
|
-
updateMessageRemoteUrlProperty(message, remoteUrl) {
|
27130
|
-
message.content.remoteUrl = remoteUrl;
|
27131
|
-
}
|
27132
|
-
}
|
27133
|
-
let audioCtx;
|
27134
|
-
class Audio {
|
27135
|
-
create(file) {
|
27136
|
-
return blob2ArrayBuffer(file).then(this.getAudioInfo).then(info => {
|
27137
|
-
return {
|
27138
|
-
success: true,
|
27139
|
-
message: new HQVoiceMessage({
|
27140
|
-
remoteUrl: '',
|
27141
|
-
duration: info.duration,
|
27142
|
-
type: getBlobExtension(file)
|
27143
|
-
}),
|
27144
|
-
file
|
27145
|
-
};
|
27146
|
-
}).catch(() => {
|
27147
|
-
return {
|
27148
|
-
success: false
|
27149
|
-
};
|
27150
|
-
});
|
27151
|
-
}
|
27152
|
-
updateMessageRemoteUrlProperty(message, remoteUrl) {
|
27153
|
-
message.content.remoteUrl = remoteUrl;
|
27154
|
-
}
|
27155
|
-
getAudioInfo(buffer) {
|
27156
|
-
const ctx = audioCtx || new AudioContext();
|
27157
|
-
audioCtx = ctx;
|
27158
|
-
return new Promise((resolve, reject) => {
|
27159
|
-
ctx.decodeAudioData(buffer, function (audioBuffer) {
|
27160
|
-
resolve({
|
27161
|
-
duration: audioBuffer.duration,
|
27162
|
-
length: audioBuffer.length
|
27163
|
-
});
|
27164
|
-
}, reject);
|
27165
|
-
});
|
27166
|
-
}
|
27167
|
-
}
|
27168
|
-
class File {
|
27169
|
-
async create(file) {
|
27170
|
-
if (file.size > 100 * 1024 * 1024) {
|
27171
|
-
return {
|
27172
|
-
success: false
|
27173
|
-
};
|
27174
|
-
}
|
27175
|
-
return {
|
27176
|
-
success: true,
|
27177
|
-
message: new FileMessage({
|
27178
|
-
fileUrl: '',
|
27179
|
-
name: file.name,
|
27180
|
-
type: getBlobExtension(file),
|
27181
|
-
size: file.size
|
27182
|
-
}),
|
27183
|
-
file
|
27184
|
-
};
|
27185
|
-
}
|
27186
|
-
updateMessageRemoteUrlProperty(message, remoteUrl) {
|
27187
|
-
message.content.fileUrl = remoteUrl;
|
27188
|
-
}
|
27189
|
-
}
|
27190
|
-
var FileType;
|
27191
|
-
(function (FileType) {
|
27192
|
-
FileType[FileType["IMAGE"] = 1] = "IMAGE";
|
27193
|
-
FileType[FileType["GIF"] = 2] = "GIF";
|
27194
|
-
FileType[FileType["AUDIO"] = 3] = "AUDIO";
|
27195
|
-
FileType[FileType["VIDEO"] = 4] = "VIDEO";
|
27196
|
-
FileType[FileType["FILE"] = 5] = "FILE";
|
27197
|
-
FileType[FileType["SIGHT"] = 6] = "SIGHT";
|
27198
|
-
})(FileType || (FileType = {}));
|
27199
|
-
const getMediaMessageCreator = fileType => {
|
27200
|
-
let creator;
|
27201
|
-
switch (fileType) {
|
27202
|
-
case FileType.IMAGE:
|
27203
|
-
creator = new Img();
|
27204
|
-
break;
|
27205
|
-
case FileType.AUDIO:
|
27206
|
-
creator = new Audio();
|
27207
|
-
break;
|
27208
|
-
case FileType.GIF:
|
27209
|
-
creator = new GIF();
|
27210
|
-
break;
|
27211
|
-
case FileType.FILE:
|
27212
|
-
creator = new File();
|
27213
|
-
break;
|
27214
|
-
}
|
27215
|
-
return creator;
|
27216
|
-
};
|
27217
|
-
|
27218
|
-
class Upload {
|
27219
|
-
options;
|
27220
|
-
xhr;
|
27221
|
-
constructor(options) {
|
27222
|
-
this.options = options;
|
27223
|
-
}
|
27224
|
-
upload(file, callback) {
|
27225
|
-
const xhr = new XMLHttpRequest();
|
27226
|
-
xhr.timeout = (30 + file.size / 1024 / 512) * 1000;
|
27227
|
-
xhr.upload.onprogress = event => {
|
27228
|
-
callback.onProgress?.(event.loaded, event.total);
|
27229
|
-
};
|
27230
|
-
xhr.onreadystatechange = () => {
|
27231
|
-
if (xhr.readyState === 4) {
|
27232
|
-
const responseText = xhr.responseText || '{}';
|
27233
|
-
const responseData = JSON.parse(responseText);
|
27234
|
-
if (xhr.status === 200 && responseData.code === 200) {
|
27235
|
-
let result = {
|
27236
|
-
url: responseData.url
|
27237
|
-
};
|
27238
|
-
if (this.options.transformer) {
|
27239
|
-
result = this.options.transformer(result);
|
27240
|
-
}
|
27241
|
-
callback.onCompleted?.(result);
|
27242
|
-
} else {
|
27243
|
-
callback.onError?.('upload fail');
|
27244
|
-
}
|
27245
|
-
}
|
27246
|
-
};
|
27247
|
-
xhr.open('POST', this.options.uploadUrl, true);
|
27248
|
-
xhr.setRequestHeader('device', '7');
|
27249
|
-
xhr.setRequestHeader('cert', this.options.cert ?? '');
|
27250
|
-
const type = getBlobExtension(file);
|
27251
|
-
const fileName = genUId() + (type.length ? `.${type}` : '');
|
27252
|
-
const formData = new FormData();
|
27253
|
-
formData.append('file', file);
|
27254
|
-
formData.append('name', 'file');
|
27255
|
-
formData.append('fileName', fileName);
|
27256
|
-
formData.append('token', this.options.token);
|
27257
|
-
xhr.send(formData);
|
27258
|
-
this.xhr = xhr;
|
27259
|
-
}
|
27260
|
-
cancel() {
|
27261
|
-
this.xhr?.abort();
|
27262
|
-
}
|
27263
|
-
}
|
27264
|
-
function genUId() {
|
27265
|
-
let date = new Date().getTime();
|
27266
|
-
const uuid = 'xxxxxx4xxxyxxxxxxx'.replace(/[xy]/g, function (c) {
|
27267
|
-
const r = (date + Math.random() * 16) % 16 | 0;
|
27268
|
-
date = Math.floor(date / 16);
|
27269
|
-
return (c === 'x' ? r : r & 0x3 | 0x8).toString(16);
|
27270
|
-
});
|
27271
|
-
return uuid;
|
27272
|
-
}
|
27273
|
-
|
27274
26618
|
const MAX_MESSAGE_CONTENT_BYTES = 80 * 1024;
|
27275
|
-
const MEDIA_MESSAGES = [MessageObjectIds.IMAGE, MessageObjectIds.AUDIO, MessageObjectIds.GIF, MessageObjectIds.FILE];
|
27276
26619
|
async function sendMessage$1(conversation, message, options) {
|
27277
26620
|
return internal_sendMessage(conversation, message, options);
|
27278
26621
|
}
|
27279
|
-
const sendImageMessage$1 = createSendFunction.bind(null, FileType.IMAGE);
|
27280
|
-
const sendGIFMessage$1 = createSendFunction.bind(null, FileType.GIF);
|
27281
|
-
const sendHQVoiceMessage$1 = createSendFunction.bind(null, FileType.AUDIO);
|
27282
|
-
const sendFileMessage$1 = createSendFunction.bind(null, FileType.FILE);
|
27283
26622
|
const sendRecallMessage = async (conversation, options) => {
|
27284
26623
|
const dialogId = getFullDialogId(conversation);
|
27285
26624
|
RecallMessageStore.addMessage(options.messageUId);
|
@@ -27290,9 +26629,7 @@ const sendRecallMessage = async (conversation, options) => {
|
|
27290
26629
|
};
|
27291
26630
|
}
|
27292
26631
|
const recallCommandMessage = new RecallCommandMessage({
|
27293
|
-
|
27294
|
-
messageUId: options.messageUId,
|
27295
|
-
...conversation
|
26632
|
+
msgId: options.messageUId
|
27296
26633
|
});
|
27297
26634
|
const sentAttris = {
|
27298
26635
|
conversation,
|
@@ -27307,58 +26644,6 @@ const sendRecallMessage = async (conversation, options) => {
|
|
27307
26644
|
data: receivedMessage
|
27308
26645
|
};
|
27309
26646
|
};
|
27310
|
-
async function createSendFunction(fileType, conversation, msgBody, hooks, sendOptions) {
|
27311
|
-
const mediaMessageCreator = getMediaMessageCreator(fileType);
|
27312
|
-
if (!mediaMessageCreator) return {
|
27313
|
-
code: ErrorCode.NOT_SUPPORT
|
27314
|
-
};
|
27315
|
-
const {
|
27316
|
-
success,
|
27317
|
-
message: message1,
|
27318
|
-
file
|
27319
|
-
} = await mediaMessageCreator.create(msgBody.file);
|
27320
|
-
if (!success || !message1 || !file) {
|
27321
|
-
return {
|
27322
|
-
code: ErrorCode.MEDIA_EXCEPTION
|
27323
|
-
};
|
27324
|
-
}
|
27325
|
-
message1.content.user = msgBody.user;
|
27326
|
-
message1.content.extra = msgBody.extra;
|
27327
|
-
return internal_sendMessage(conversation, message1, sendOptions, {
|
27328
|
-
file,
|
27329
|
-
task: (message2, toBeUploadedFile) => {
|
27330
|
-
return new Promise(resolve => {
|
27331
|
-
const uploader = new Upload({
|
27332
|
-
token: imConfig.imInitToken,
|
27333
|
-
uploadUrl: imConfig.fileUploadUrl,
|
27334
|
-
cert: imConfig.cert,
|
27335
|
-
transformer: result => ({
|
27336
|
-
...result,
|
27337
|
-
url: imConfig.getFileAbsoluteUri(result.url)
|
27338
|
-
})
|
27339
|
-
});
|
27340
|
-
uploader.upload(toBeUploadedFile, {
|
27341
|
-
onProgress: (loaded, total) => hooks?.onProgress?.(Math.floor(loaded / total * 100)),
|
27342
|
-
onError: () => {
|
27343
|
-
resolve({
|
27344
|
-
finished: false,
|
27345
|
-
message: message2
|
27346
|
-
});
|
27347
|
-
},
|
27348
|
-
onCompleted: result => {
|
27349
|
-
mediaMessageCreator.updateMessageRemoteUrlProperty(message2, result.url);
|
27350
|
-
resolve({
|
27351
|
-
finished: true,
|
27352
|
-
message: hooks?.onComplete?.({
|
27353
|
-
url: result.url
|
27354
|
-
}) ?? message2
|
27355
|
-
});
|
27356
|
-
}
|
27357
|
-
});
|
27358
|
-
});
|
27359
|
-
}
|
27360
|
-
});
|
27361
|
-
}
|
27362
26647
|
async function internal_sendMessage(conversation, message, options, uploadOptions) {
|
27363
26648
|
const checkResult = beforeSend(conversation, message, options);
|
27364
26649
|
if (checkResult.code !== ErrorCode.SUCCESS || !checkResult.message || !checkResult.sentArgs) {
|
@@ -27430,7 +26715,7 @@ async function send(message, sentArgs) {
|
|
27430
26715
|
SentMessageStore.addMessage(sentArgs.messageId);
|
27431
26716
|
const baseParams = {
|
27432
26717
|
localId: sentArgs.messageId,
|
27433
|
-
mediaFlag:
|
26718
|
+
mediaFlag: false,
|
27434
26719
|
mediaConstructor: message.objectId,
|
27435
26720
|
mediaAttribute: '',
|
27436
26721
|
msgPreContent: '',
|
@@ -27586,10 +26871,6 @@ class IMClient extends EventEmitter {
|
|
27586
26871
|
}
|
27587
26872
|
getServerTime = getServerTime$1;
|
27588
26873
|
sendMessage = sendMessage$1;
|
27589
|
-
sendImageMessage = sendImageMessage$1;
|
27590
|
-
sendGIFMessage = sendGIFMessage$1;
|
27591
|
-
sendHQVoiceMessage = sendHQVoiceMessage$1;
|
27592
|
-
sendFileMessage = sendFileMessage$1;
|
27593
26874
|
recallMsg = sendRecallMessage;
|
27594
26875
|
async getRemoteHistoryMessages(conversation, options) {
|
27595
26876
|
const dialogId = getFullDialogId(conversation);
|
@@ -28887,6 +28168,12 @@ const setConversationToTop = async (options, isTop = true) => {
|
|
28887
28168
|
const getTopConversationList = () => {
|
28888
28169
|
return imClient.getTopConversationList();
|
28889
28170
|
};
|
28171
|
+
const registerMessageType = (messageType, isPersited, isCounted, isStatusMessage) => {
|
28172
|
+
const defined = function (content) {
|
28173
|
+
return new BaseMessage(messageType, content, isPersited, isCounted, isStatusMessage);
|
28174
|
+
};
|
28175
|
+
return defined;
|
28176
|
+
};
|
28890
28177
|
const sendMessage = async (conversation, message, options) => {
|
28891
28178
|
if (message instanceof BaseMessage === false) {
|
28892
28179
|
logger.warn('send message fail -> message parameter is not an instance of BaseMessage');
|
@@ -28904,44 +28191,6 @@ const sendTextMessage = (conversation, messageBody, options) => {
|
|
28904
28191
|
const message = new TextMessage(messageBody);
|
28905
28192
|
return sendMessage(conversation, message, options);
|
28906
28193
|
};
|
28907
|
-
const sendImageMessage = async (conversation, msgBody, hooks, sendOptions) => {
|
28908
|
-
assert('conversation', conversation, AssertRules.CONVERSATION, true);
|
28909
|
-
assert('msgBody.file', msgBody.file, file => file instanceof Blob && file.type.startsWith('image/'), true);
|
28910
|
-
const paramsStr = 'conversationType:' + conversation.conversationType + ',targetId:' + conversation.targetId;
|
28911
|
-
logger.debug('send message ->' + paramsStr);
|
28912
|
-
_logSendBefore(conversation);
|
28913
|
-
const response = await imClient.sendImageMessage(conversation, msgBody, hooks, sendOptions);
|
28914
|
-
_logSendError(conversation, response.code);
|
28915
|
-
return response;
|
28916
|
-
};
|
28917
|
-
const sendGIFMessage = async (conversation, msgBody, hooks, sendOptions) => {
|
28918
|
-
assert('conversation', conversation, AssertRules.CONVERSATION, true);
|
28919
|
-
assert('msgBody.file', msgBody.file, file => file instanceof Blob && file.type.endsWith('image/gif'), true);
|
28920
|
-
const paramsStr = 'conversationType:' + conversation.conversationType + ',targetId:' + conversation.targetId;
|
28921
|
-
logger.debug('send message ->' + paramsStr);
|
28922
|
-
_logSendBefore(conversation);
|
28923
|
-
const response = await imClient.sendGIFMessage(conversation, msgBody, hooks, sendOptions);
|
28924
|
-
_logSendError(conversation, response.code);
|
28925
|
-
return response;
|
28926
|
-
};
|
28927
|
-
const sendHQVoiceMessage = async (conversation, msgBody, hooks, sendOptions) => {
|
28928
|
-
assert('conversation', conversation, AssertRules.CONVERSATION, true);
|
28929
|
-
assert('msgBody.file', msgBody.file, file => file instanceof Blob, true);
|
28930
|
-
_logSendBefore(conversation);
|
28931
|
-
const response = await imClient.sendHQVoiceMessage(conversation, msgBody, hooks, sendOptions);
|
28932
|
-
_logSendError(conversation, response.code);
|
28933
|
-
return response;
|
28934
|
-
};
|
28935
|
-
const sendFileMessage = async (conversation, msgBody, hooks, sendOptions) => {
|
28936
|
-
assert('conversation', conversation, AssertRules.CONVERSATION, true);
|
28937
|
-
assert('msgBody.file', msgBody.file, file => file instanceof Blob, true);
|
28938
|
-
const paramsStr = 'conversationType:' + conversation.conversationType + ',targetId:' + conversation.targetId;
|
28939
|
-
logger.debug('send message ->' + paramsStr);
|
28940
|
-
_logSendBefore(conversation);
|
28941
|
-
const response = await imClient.sendFileMessage(conversation, msgBody, hooks, sendOptions);
|
28942
|
-
_logSendError(conversation, response.code);
|
28943
|
-
return response;
|
28944
|
-
};
|
28945
28194
|
const recallMessage = async (conversation, options) => {
|
28946
28195
|
assert('options.messageUId', options.messageUId, AssertRules.STRING, true);
|
28947
28196
|
assert('options.sentTime', options.sentTime, AssertRules.NUMBER, true);
|
@@ -29041,4 +28290,4 @@ const _logSendError = (conversation, errorCode) => {
|
|
29041
28290
|
}
|
29042
28291
|
};
|
29043
28292
|
|
29044
|
-
export { ConnectionStatus, ConversationType, ErrorCode, ErrorDesc, Events, FileMessage, GIFMessage, HQVoiceMessage, ImageMessage, LogLevel, MentionedType, MessageDirection, NotificationLevel, NotificationStatus, ReceivedStatus, SentStatus, TextMessage, addEventListener, clearAllMessagesUnreadStatus, clearHistoryMessages, clearMessagesUnreadStatus, clearTextMessageDraft, connect, deleteMessages, disconnect, getAllConversationState, getAllUnreadMentionedCount, getBlockedConversationList, getConnectionStatus, getConversation, getConversationList, getConversationNotificationLevel, getConversationNotificationStatus, getHistoryMessages, getRemoteHistoryMessages, getServerTime, getTextMessageDraft, getTopConversationList, getTotalUnreadCount, getUnreadCount, getUnreadMentionedCount, init, logOut, mockLogin, onceEventListener, recallMessage, removeConversation, removeEventListener, request, saveTextMessageDraft,
|
28293
|
+
export { ConnectionStatus, ConversationType, ErrorCode, ErrorDesc, Events, FileMessage, GIFMessage, VoiceMessage as HQVoiceMessage, ImageMessage, LogLevel, MentionedType, MessageDirection, NotificationLevel, NotificationStatus, ReceivedStatus, SentStatus, TextMessage, addEventListener, clearAllMessagesUnreadStatus, clearHistoryMessages, clearMessagesUnreadStatus, clearTextMessageDraft, connect, deleteMessages, disconnect, getAllConversationState, getAllUnreadMentionedCount, getBlockedConversationList, getConnectionStatus, getConversation, getConversationList, getConversationNotificationLevel, getConversationNotificationStatus, getHistoryMessages, getRemoteHistoryMessages, getServerTime, getTextMessageDraft, getTopConversationList, getTotalUnreadCount, getUnreadCount, getUnreadMentionedCount, init, logOut, mockLogin, onceEventListener, recallMessage, registerMessageType, removeConversation, removeEventListener, request, saveTextMessageDraft, sendMessage, sendTextMessage, setConversationNotificationStatus, setConversationToTop, setUserLogged };
|