@onyx-p/imlib-web 1.4.5 → 1.4.7

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 CHANGED
@@ -19173,12 +19173,16 @@ const transBriefDialog2IReceivedConversation = dialog => {
19173
19173
  if (!conversation) {
19174
19174
  return;
19175
19175
  }
19176
+ dialog.dialogTitle;
19177
+ dialog.smallAvatarUrl;
19176
19178
  const conversationObj = {
19177
19179
  ...conversation,
19178
19180
  unreadMessageCount: 0,
19179
19181
  notificationStatus: dialog.muteFlag ? NotificationStatus.OPEN : NotificationStatus.CLOSE,
19180
19182
  notificationLevel: dialog.muteFlag ? NotificationLevel.NOT_MESSAGE_NOTIFICATION : NotificationLevel.ALL_MESSAGE,
19181
19183
  isTop: !!dialog.stickyFlag,
19184
+ dialogTitle: dialog.dialogTitle,
19185
+ smallAvatarUrl: dialog.smallAvatarUrl,
19182
19186
  lastUnreadTime: '0'
19183
19187
  };
19184
19188
  return conversationObj;
@@ -26754,6 +26758,24 @@ function calcPosition(width, height, thumbnailConfig) {
26754
26758
  return scale > thumbnailConfig.scale ? gtScale() : ltScale();
26755
26759
  }
26756
26760
 
26761
+ function formatDurationSeconds(timeSeconds) {
26762
+ const seconds = Math.max(0, timeSeconds);
26763
+ const secondsPart = seconds % 60;
26764
+ const minutesPart = Math.floor(seconds / 60 % 60);
26765
+ const hoursPart = Math.floor(seconds / 3600);
26766
+ if (hoursPart > 0) {
26767
+ return `${hoursPart}:${minutesPart.toString().padStart(2, '0')}:${secondsPart.toString().padStart(2, '0')}`;
26768
+ } else {
26769
+ return `${minutesPart}:${secondsPart.toString().padStart(2, '0')}`;
26770
+ }
26771
+ }
26772
+
26773
+ const DefaultThumbnailConfig = {
26774
+ maxHeight: 500,
26775
+ maxWidth: 500,
26776
+ quality: 0.6,
26777
+ scale: 2.4
26778
+ };
26757
26779
  class Img {
26758
26780
  async create(file) {
26759
26781
  try {
@@ -26765,13 +26787,7 @@ class Img {
26765
26787
  compressWidth,
26766
26788
  compressHeight
26767
26789
  } = compress(image, 0.85, file.type);
26768
- const config = {
26769
- maxHeight: 160,
26770
- maxWidth: 160,
26771
- quality: 0.6,
26772
- scale: 2.4
26773
- };
26774
- const thumbnail = getThumbnail(image, config);
26790
+ const thumbnail = getThumbnail(image, DefaultThumbnailConfig);
26775
26791
  return {
26776
26792
  success: true,
26777
26793
  message: new ImageMessage({
@@ -26908,6 +26924,66 @@ class File {
26908
26924
  return content;
26909
26925
  }
26910
26926
  }
26927
+ class Sight {
26928
+ async create(file) {
26929
+ try {
26930
+ if (file.size > 100 * 1024 * 1024) {
26931
+ return {
26932
+ success: false
26933
+ };
26934
+ }
26935
+ const videoUrl = getBlobUrl(file);
26936
+ const video = document.createElement('video');
26937
+ video.src = videoUrl;
26938
+ await new Promise((resolve, reject) => {
26939
+ video.onloadedmetadata = resolve;
26940
+ video.onerror = reject;
26941
+ });
26942
+ const duration = video.duration;
26943
+ const width = video.videoWidth;
26944
+ const height = video.videoHeight;
26945
+ const scale = Math.min(DefaultThumbnailConfig.maxWidth / width, DefaultThumbnailConfig.maxHeight / height, DefaultThumbnailConfig.scale);
26946
+ const thumbnailWidth = Math.floor(width * scale);
26947
+ const thumbnailHeight = Math.floor(height * scale);
26948
+ const canvas = document.createElement('canvas');
26949
+ canvas.width = thumbnailWidth;
26950
+ canvas.height = thumbnailHeight;
26951
+ const ctx = canvas.getContext('2d');
26952
+ ctx?.drawImage(video, 0, 0, thumbnailWidth, thumbnailHeight);
26953
+ const thumbnailBlob = await new Promise(resolve => {
26954
+ canvas.toBlob(blob => resolve(blob), 'image/jpeg', DefaultThumbnailConfig.quality);
26955
+ });
26956
+ revokeBlobUrl(videoUrl);
26957
+ return {
26958
+ success: true,
26959
+ message: new VideoMessage({
26960
+ videoObjectKey: "",
26961
+ thumbnailObjectKey: "",
26962
+ during: formatDurationSeconds(duration),
26963
+ width,
26964
+ height,
26965
+ extension: getBlobExtension(file)
26966
+ }),
26967
+ files: [file, thumbnailBlob]
26968
+ };
26969
+ } catch (error) {
26970
+ return {
26971
+ success: false
26972
+ };
26973
+ }
26974
+ }
26975
+ updateMessageRemoteUrlProperty(messageContent, uploadedResult) {
26976
+ let content = deepClone(messageContent);
26977
+ const {
26978
+ urls: [videoObjectKey, thumbnailObjectKey],
26979
+ encryptedKey
26980
+ } = uploadedResult;
26981
+ content.videoObjectKey = videoObjectKey;
26982
+ content.thumbnailObjectKey = thumbnailObjectKey;
26983
+ content.encryptKey = encryptedKey;
26984
+ return content;
26985
+ }
26986
+ }
26911
26987
  var FileType;
26912
26988
  (function (FileType) {
26913
26989
  FileType[FileType["IMAGE"] = 1] = "IMAGE";
@@ -26932,6 +27008,9 @@ const getMediaMessageCreator = fileType => {
26932
27008
  case FileType.FILE:
26933
27009
  creator = new File();
26934
27010
  break;
27011
+ case FileType.SIGHT:
27012
+ creator = new Sight();
27013
+ break;
26935
27014
  }
26936
27015
  return creator;
26937
27016
  };
@@ -26943,7 +27022,8 @@ async function sendMessage$1(conversation, message, options) {
26943
27022
  const sendImageMessage$1 = createSendFunction.bind(null, FileType.IMAGE);
26944
27023
  const sendGIFMessage$1 = createSendFunction.bind(null, FileType.GIF);
26945
27024
  const sendHQVoiceMessage$1 = createSendFunction.bind(null, FileType.AUDIO);
26946
- const sendFileMessage$1 = createSendFunction.bind(null, FileType.FILE);
27025
+ const sendSightMessage$1 = createSendFunction.bind(null, FileType.AUDIO);
27026
+ const sendFileMessage$1 = createSendFunction.bind(null, FileType.SIGHT);
26947
27027
  const sendRecallMessage = async (conversation, options) => {
26948
27028
  const dialogId = getFullDialogId(conversation);
26949
27029
  RecallMessageStore.addMessage(options.messageUId);
@@ -27089,7 +27169,7 @@ async function send(message, sentArgs) {
27089
27169
  SentMessageStore.addMessage(sentArgs.messageId);
27090
27170
  const baseParams = {
27091
27171
  localId: Long.fromString(sentArgs.messageId),
27092
- mediaFlag: false,
27172
+ mediaFlag: message.messageType !== MessageTypes.TEXT,
27093
27173
  mediaConstructor: message.messageType,
27094
27174
  msgPreContent: '',
27095
27175
  msgPostContent: postEncryptedString,
@@ -27226,6 +27306,7 @@ class IMClient extends EventEmitter {
27226
27306
  sendGIFMessage = sendGIFMessage$1;
27227
27307
  sendHQVoiceMessage = sendHQVoiceMessage$1;
27228
27308
  sendFileMessage = sendFileMessage$1;
27309
+ sendSightMessage = sendSightMessage$1;
27229
27310
  recallMsg = sendRecallMessage;
27230
27311
  async getRemoteHistoryMessages(conversation, options) {
27231
27312
  const dialogId = getFullDialogId(conversation);
@@ -28323,7 +28404,6 @@ const getConversationList = async options => {
28323
28404
  code,
28324
28405
  data
28325
28406
  } = await imClient.getConversationList(options?.count ?? 20, null, options?.startTime ?? 0, options?.order ?? 0);
28326
- debugger;
28327
28407
  if (code !== ErrorCode.SUCCESS) {
28328
28408
  logger.warn('get conversation list fail ->' + code + ':' + ErrorDesc(code));
28329
28409
  }
@@ -28590,6 +28670,15 @@ const sendFileMessage = async (conversation, msgBody, hooks, sendOptions) => {
28590
28670
  _logSendError(conversation, response.code);
28591
28671
  return response;
28592
28672
  };
28673
+ const sendSightMessage = async (conversation, msgBody, hooks, sendOptions) => {
28674
+ assert('conversation', conversation, AssertRules.CONVERSATION, true);
28675
+ assert('uploader', imConfig.getUploader(), AssertRules.OBJECT, true);
28676
+ assert('msgBody.file', msgBody.file, file => file instanceof Blob && file.type === 'video/mp4', true);
28677
+ _logSendBefore(conversation);
28678
+ const response = await imClient.sendSightMessage(conversation, msgBody, hooks, sendOptions);
28679
+ _logSendError(conversation, response.code);
28680
+ return response;
28681
+ };
28593
28682
  const recallMessage = async (conversation, options) => {
28594
28683
  assert('options.messageUId', options.messageUId, AssertRules.STRING, true);
28595
28684
  assert('options.sentTime', options.sentTime, AssertRules.NUMBER, true);
@@ -28689,4 +28778,4 @@ const _logSendError = (conversation, errorCode) => {
28689
28778
  }
28690
28779
  };
28691
28780
 
28692
- export { ConnectionStatus, ConversationType, ErrorCode, ErrorDesc, Events, FileMessage, GIFMessage, VoiceMessage as HQVoiceMessage, ImageMessage, LogLevel, MentionedType, MessageDirection, MessageTypes, NotificationLevel, NotificationStatus, ReceivedStatus, SentStatus, TextMessage, VideoMessage, 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, sendFileMessage, sendGIFMessage, sendHQVoiceMessage, sendImageMessage, sendMessage, sendTextMessage, setConversationNotificationStatus, setConversationToTop, setUserLogged };
28781
+ export { ConnectionStatus, ConversationType, ErrorCode, ErrorDesc, Events, FileMessage, GIFMessage, VoiceMessage as HQVoiceMessage, ImageMessage, LogLevel, MentionedType, MessageDirection, MessageTypes, NotificationLevel, NotificationStatus, ReceivedStatus, SentStatus, TextMessage, VideoMessage, 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, sendFileMessage, sendGIFMessage, sendHQVoiceMessage, sendImageMessage, sendMessage, sendSightMessage, sendTextMessage, setConversationNotificationStatus, setConversationToTop, setUserLogged };
package/index.umd.js CHANGED
@@ -19179,12 +19179,16 @@
19179
19179
  if (!conversation) {
19180
19180
  return;
19181
19181
  }
19182
+ dialog.dialogTitle;
19183
+ dialog.smallAvatarUrl;
19182
19184
  const conversationObj = {
19183
19185
  ...conversation,
19184
19186
  unreadMessageCount: 0,
19185
19187
  notificationStatus: dialog.muteFlag ? exports.NotificationStatus.OPEN : exports.NotificationStatus.CLOSE,
19186
19188
  notificationLevel: dialog.muteFlag ? exports.NotificationLevel.NOT_MESSAGE_NOTIFICATION : exports.NotificationLevel.ALL_MESSAGE,
19187
19189
  isTop: !!dialog.stickyFlag,
19190
+ dialogTitle: dialog.dialogTitle,
19191
+ smallAvatarUrl: dialog.smallAvatarUrl,
19188
19192
  lastUnreadTime: '0'
19189
19193
  };
19190
19194
  return conversationObj;
@@ -26760,6 +26764,24 @@
26760
26764
  return scale > thumbnailConfig.scale ? gtScale() : ltScale();
26761
26765
  }
26762
26766
 
26767
+ function formatDurationSeconds(timeSeconds) {
26768
+ const seconds = Math.max(0, timeSeconds);
26769
+ const secondsPart = seconds % 60;
26770
+ const minutesPart = Math.floor(seconds / 60 % 60);
26771
+ const hoursPart = Math.floor(seconds / 3600);
26772
+ if (hoursPart > 0) {
26773
+ return `${hoursPart}:${minutesPart.toString().padStart(2, '0')}:${secondsPart.toString().padStart(2, '0')}`;
26774
+ } else {
26775
+ return `${minutesPart}:${secondsPart.toString().padStart(2, '0')}`;
26776
+ }
26777
+ }
26778
+
26779
+ const DefaultThumbnailConfig = {
26780
+ maxHeight: 500,
26781
+ maxWidth: 500,
26782
+ quality: 0.6,
26783
+ scale: 2.4
26784
+ };
26763
26785
  class Img {
26764
26786
  async create(file) {
26765
26787
  try {
@@ -26771,13 +26793,7 @@
26771
26793
  compressWidth,
26772
26794
  compressHeight
26773
26795
  } = compress(image, 0.85, file.type);
26774
- const config = {
26775
- maxHeight: 160,
26776
- maxWidth: 160,
26777
- quality: 0.6,
26778
- scale: 2.4
26779
- };
26780
- const thumbnail = getThumbnail(image, config);
26796
+ const thumbnail = getThumbnail(image, DefaultThumbnailConfig);
26781
26797
  return {
26782
26798
  success: true,
26783
26799
  message: new ImageMessage({
@@ -26914,6 +26930,66 @@
26914
26930
  return content;
26915
26931
  }
26916
26932
  }
26933
+ class Sight {
26934
+ async create(file) {
26935
+ try {
26936
+ if (file.size > 100 * 1024 * 1024) {
26937
+ return {
26938
+ success: false
26939
+ };
26940
+ }
26941
+ const videoUrl = getBlobUrl(file);
26942
+ const video = document.createElement('video');
26943
+ video.src = videoUrl;
26944
+ await new Promise((resolve, reject) => {
26945
+ video.onloadedmetadata = resolve;
26946
+ video.onerror = reject;
26947
+ });
26948
+ const duration = video.duration;
26949
+ const width = video.videoWidth;
26950
+ const height = video.videoHeight;
26951
+ const scale = Math.min(DefaultThumbnailConfig.maxWidth / width, DefaultThumbnailConfig.maxHeight / height, DefaultThumbnailConfig.scale);
26952
+ const thumbnailWidth = Math.floor(width * scale);
26953
+ const thumbnailHeight = Math.floor(height * scale);
26954
+ const canvas = document.createElement('canvas');
26955
+ canvas.width = thumbnailWidth;
26956
+ canvas.height = thumbnailHeight;
26957
+ const ctx = canvas.getContext('2d');
26958
+ ctx?.drawImage(video, 0, 0, thumbnailWidth, thumbnailHeight);
26959
+ const thumbnailBlob = await new Promise(resolve => {
26960
+ canvas.toBlob(blob => resolve(blob), 'image/jpeg', DefaultThumbnailConfig.quality);
26961
+ });
26962
+ revokeBlobUrl(videoUrl);
26963
+ return {
26964
+ success: true,
26965
+ message: new VideoMessage({
26966
+ videoObjectKey: "",
26967
+ thumbnailObjectKey: "",
26968
+ during: formatDurationSeconds(duration),
26969
+ width,
26970
+ height,
26971
+ extension: getBlobExtension(file)
26972
+ }),
26973
+ files: [file, thumbnailBlob]
26974
+ };
26975
+ } catch (error) {
26976
+ return {
26977
+ success: false
26978
+ };
26979
+ }
26980
+ }
26981
+ updateMessageRemoteUrlProperty(messageContent, uploadedResult) {
26982
+ let content = deepClone(messageContent);
26983
+ const {
26984
+ urls: [videoObjectKey, thumbnailObjectKey],
26985
+ encryptedKey
26986
+ } = uploadedResult;
26987
+ content.videoObjectKey = videoObjectKey;
26988
+ content.thumbnailObjectKey = thumbnailObjectKey;
26989
+ content.encryptKey = encryptedKey;
26990
+ return content;
26991
+ }
26992
+ }
26917
26993
  var FileType;
26918
26994
  (function (FileType) {
26919
26995
  FileType[FileType["IMAGE"] = 1] = "IMAGE";
@@ -26938,6 +27014,9 @@
26938
27014
  case FileType.FILE:
26939
27015
  creator = new File();
26940
27016
  break;
27017
+ case FileType.SIGHT:
27018
+ creator = new Sight();
27019
+ break;
26941
27020
  }
26942
27021
  return creator;
26943
27022
  };
@@ -26949,7 +27028,8 @@
26949
27028
  const sendImageMessage$1 = createSendFunction.bind(null, FileType.IMAGE);
26950
27029
  const sendGIFMessage$1 = createSendFunction.bind(null, FileType.GIF);
26951
27030
  const sendHQVoiceMessage$1 = createSendFunction.bind(null, FileType.AUDIO);
26952
- const sendFileMessage$1 = createSendFunction.bind(null, FileType.FILE);
27031
+ const sendSightMessage$1 = createSendFunction.bind(null, FileType.AUDIO);
27032
+ const sendFileMessage$1 = createSendFunction.bind(null, FileType.SIGHT);
26953
27033
  const sendRecallMessage = async (conversation, options) => {
26954
27034
  const dialogId = getFullDialogId(conversation);
26955
27035
  RecallMessageStore.addMessage(options.messageUId);
@@ -27095,7 +27175,7 @@
27095
27175
  SentMessageStore.addMessage(sentArgs.messageId);
27096
27176
  const baseParams = {
27097
27177
  localId: Long.fromString(sentArgs.messageId),
27098
- mediaFlag: false,
27178
+ mediaFlag: message.messageType !== MessageTypes.TEXT,
27099
27179
  mediaConstructor: message.messageType,
27100
27180
  msgPreContent: '',
27101
27181
  msgPostContent: postEncryptedString,
@@ -27232,6 +27312,7 @@
27232
27312
  sendGIFMessage = sendGIFMessage$1;
27233
27313
  sendHQVoiceMessage = sendHQVoiceMessage$1;
27234
27314
  sendFileMessage = sendFileMessage$1;
27315
+ sendSightMessage = sendSightMessage$1;
27235
27316
  recallMsg = sendRecallMessage;
27236
27317
  async getRemoteHistoryMessages(conversation, options) {
27237
27318
  const dialogId = getFullDialogId(conversation);
@@ -28329,7 +28410,6 @@
28329
28410
  code,
28330
28411
  data
28331
28412
  } = await imClient.getConversationList(options?.count ?? 20, null, options?.startTime ?? 0, options?.order ?? 0);
28332
- debugger;
28333
28413
  if (code !== exports.ErrorCode.SUCCESS) {
28334
28414
  logger.warn('get conversation list fail ->' + code + ':' + ErrorDesc(code));
28335
28415
  }
@@ -28596,6 +28676,15 @@
28596
28676
  _logSendError(conversation, response.code);
28597
28677
  return response;
28598
28678
  };
28679
+ const sendSightMessage = async (conversation, msgBody, hooks, sendOptions) => {
28680
+ assert('conversation', conversation, AssertRules.CONVERSATION, true);
28681
+ assert('uploader', imConfig.getUploader(), AssertRules.OBJECT, true);
28682
+ assert('msgBody.file', msgBody.file, file => file instanceof Blob && file.type === 'video/mp4', true);
28683
+ _logSendBefore(conversation);
28684
+ const response = await imClient.sendSightMessage(conversation, msgBody, hooks, sendOptions);
28685
+ _logSendError(conversation, response.code);
28686
+ return response;
28687
+ };
28599
28688
  const recallMessage = async (conversation, options) => {
28600
28689
  assert('options.messageUId', options.messageUId, AssertRules.STRING, true);
28601
28690
  assert('options.sentTime', options.sentTime, AssertRules.NUMBER, true);
@@ -28742,6 +28831,7 @@
28742
28831
  exports.sendHQVoiceMessage = sendHQVoiceMessage;
28743
28832
  exports.sendImageMessage = sendImageMessage;
28744
28833
  exports.sendMessage = sendMessage;
28834
+ exports.sendSightMessage = sendSightMessage;
28745
28835
  exports.sendTextMessage = sendTextMessage;
28746
28836
  exports.setConversationNotificationStatus = setConversationNotificationStatus;
28747
28837
  exports.setConversationToTop = setConversationToTop;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onyx-p/imlib-web",
3
- "version": "1.4.5",
3
+ "version": "1.4.7",
4
4
  "main": "index.umd.js",
5
5
  "module": "index.esm.js",
6
6
  "types": "types/index.d.ts",
package/types/index.d.ts CHANGED
@@ -195,6 +195,10 @@ export declare const sendHQVoiceMessage: (conversation: IConversationOption, msg
195
195
  * 发送文件消息
196
196
  */
197
197
  export declare const sendFileMessage: (conversation: IConversationOption, msgBody: ISendBody, hooks?: IUploadHooks, sendOptions?: IUploadMessageOption) => IPromiseResult<IReceivedMessage>;
198
+ /**
199
+ * 发送短视频消息
200
+ */
201
+ export declare const sendSightMessage: (conversation: IConversationOption, msgBody: ISendBody, hooks?: IUploadHooks, sendOptions?: IUploadMessageOption) => IPromiseResult<IReceivedMessage>;
198
202
  /**
199
203
  * 撤回消息
200
204
  * @param options
@@ -47,4 +47,12 @@ export default interface IReceivedConversation {
47
47
  * @ 消息未读数
48
48
  */
49
49
  unreadMentionedCount?: number;
50
+ /**
51
+ * 会话名称
52
+ */
53
+ dialogTitle?: string | null;
54
+ /**
55
+ * 会话头像
56
+ */
57
+ smallAvatarUrl?: string | null;
50
58
  }