UNPKG

tjc-sdk

Version:

TIANJI IM SDK

1,773 lines (1,655 loc) 2.11 MB
import Long from 'long'; import { EventEmitter } from 'events'; import 'buffer'; import { encode } from 'base64-arraybuffer'; import CustomMessageConfig from '../../src/tjc_custom_message/customMessageConfig'; import { promises } from 'fs'; import { ipcRenderer as ipcRenderer$4, ipcMain, BrowserWindow as BrowserWindow$4 } from 'electron'; import os from 'os'; import path$1 from 'path'; import DetectRTC from 'detectrtc'; var a = /*#__PURE__*/Object.freeze({ __proto__: null, get PttClient () { return PttClient; }, get default () { return self$5; } }); var r = /*#__PURE__*/Object.freeze({ __proto__: null, get TjcManager () { return TjcManager; }, get default () { return self$4; } }); const isNode$3 = typeof process !== 'undefined' && process.versions != null && process.versions.node != null; const isElectron$4 = isNode$3 && process.versions.electron != null; const isBrowser$3 = typeof window !== 'undefined' && typeof window.document !== 'undefined'; const isWeb$1 = isBrowser$3 && !isElectron$4; let ipcRenderer$3 = undefined; let BrowserWindow$3 = undefined; let remote$1 = undefined; if (isElectron$4) { try { const electron = require('electron'); ipcRenderer$3 = electron.ipcRenderer; BrowserWindow$3 = electron.BrowserWindow; remote$1 = electron.remote; } catch (e) { ipcRenderer$3 = undefined; BrowserWindow$3 = undefined; remote$1 = undefined; } } const platform$2 = { isNode: isNode$3, isElectron: isElectron$4, isBrowser: isBrowser$3, isWeb: isWeb$1, ipcRenderer: ipcRenderer$3, BrowserWindow: BrowserWindow$3, remote: remote$1 }; var platform$3 = /*#__PURE__*/Object.freeze({ __proto__: null, get BrowserWindow () { return BrowserWindow$3; }, default: platform$2, get ipcRenderer () { return ipcRenderer$3; }, isBrowser: isBrowser$3, isElectron: isElectron$4, isNode: isNode$3, isWeb: isWeb$1, platform: platform$2, get remote () { return remote$1; } }); function isElectron$3() { if (typeof process !== 'undefined' && process.versions && process.versions.electron) { return true; } return false; } function isBrowser$2() { return typeof window !== 'undefined' && typeof window.document !== 'undefined'; } function isNode$2() { return !!(typeof process !== 'undefined' && process.versions && process.versions.node); } let _ipcRenderer$1 = null; let _BrowserWindow$1 = null; if (isElectron$3()) { try { const electron = require('electron'); _ipcRenderer$1 = electron.ipcRenderer; _BrowserWindow$1 = electron.BrowserWindow; } catch (e) { console.warn('Failed to load electron modules:', e); } } const ipcRenderer$2 = _ipcRenderer$1; const BrowserWindow$2 = _BrowserWindow$1; const platform$1 = { isElectron: isElectron$3, isBrowser: isBrowser$2, isNode: isNode$2, ipcRenderer: ipcRenderer$2, BrowserWindow: BrowserWindow$2 }; module.exports = { // Default configuration for AV defaultConfig: { // Add any default configuration here audioInput: true, audioOutput: true, videoInput: true, defaultVideoWidth: 640, defaultVideoHeight: 480, defaultFrameRate: 15 } }; var config = { urlRedirect: null // 添加其他配置项 }; var e$1 = /*#__PURE__*/Object.freeze({ __proto__: null, default: config }); const isNode$1 = typeof process !== 'undefined' && process.versions != null && process.versions.node != null; const isElectron$2 = isNode$1 && process.versions.electron != null; const isBrowser$1 = typeof window !== 'undefined' && typeof window.document !== 'undefined'; const isWeb = isBrowser$1 && !isElectron$2; let ipcRenderer$1 = undefined; let BrowserWindow$1 = undefined; let remote = undefined; if (isElectron$2) { try { const electron = require('electron'); ipcRenderer$1 = electron.ipcRenderer; BrowserWindow$1 = electron.BrowserWindow; remote = electron.remote; } catch (e) { ipcRenderer$1 = undefined; BrowserWindow$1 = undefined; remote = undefined; } } const platform = { isNode: isNode$1, isElectron: isElectron$2, isBrowser: isBrowser$1, isWeb, ipcRenderer: ipcRenderer$1, BrowserWindow: BrowserWindow$1, remote }; var s$2 = /*#__PURE__*/Object.freeze({ __proto__: null, get BrowserWindow () { return BrowserWindow$1; }, default: platform, get ipcRenderer () { return ipcRenderer$1; }, isBrowser: isBrowser$1, isElectron: isElectron$2, isNode: isNode$1, isWeb: isWeb, platform: platform, get remote () { return remote; } }); const MessageContentType = { // 基本消息类型 Unknown: 0, Text: 1, Image: 2, Voice: 3, Location: 4, File: 5, Video: 6, Sticker: 7, Link: 8, Card: 9, Composite: 10, Typing: 11, Recall: 12, Delete: 13, Articles: 14, MixMultiMediaText: 15, MixFileText: 16, MarkUnread: 17, StreamingTextGenerating: 18, StreamingTextGenerated: 19, EnterChannelChat: 20, LeaveChannelChat: 21, ChannelMenuEvent: 22, // 工具方法 isValidType(type) { return type >= this.Unknown && type <= this.ChannelMenuEvent; }, getTypeName(type) { for (const [key, value] of Object.entries(this)) { if (value === type && typeof value === 'number') { return key; } } return 'Unknown'; } }; var t$1 = /*#__PURE__*/Object.freeze({ __proto__: null, MessageContentType: MessageContentType, default: MessageContentType }); /* * Copyright (c) 2020 TianjiChat. All rights reserved. */ class ConversationType { static Single = 0; static Group = 1; static ChatRoom = 2; static Channel = 3; static SecretChat = 5; } var r$1 = /*#__PURE__*/Object.freeze({ __proto__: null, default: ConversationType }); /* * Copyright (c) 2020 TianjiChat. All rights reserved. */ /** * "conversation":{ "conversationType": 0, "target": "UZUWUWuu", "line": 0, } */ class Conversation { type = ConversationType.Single; conversationType = this.type; // 这行是为了做一个兼容处理 target = ''; line = 0; constructor(type, target, line = 0) { this.type = type; this.conversationType = type; this.target = target; this.line = line; } equal(conversation) { if (!conversation) { return false; } return this.type === conversation.type && this.target === conversation.target && this.line === conversation.line; } } var o = /*#__PURE__*/Object.freeze({ __proto__: null, default: Conversation }); /* * Copyright (c) 2020 TianjiChat. All rights reserved. */ /* { "uid": "uiuJuJcc", "name": "13888888888", "displayName": "imndx", "gender": 0, "portrait": "https://avatars.io/gravatar/uiuJuJcc", "mobile": "13888888888", "email": "", "address": "", "company": "", "social": "", "extra": "", "type": -472579968, "updateDt": 1550652404513 } */ class UserInfo { uid = ''; name = ''; displayName = ''; groupAlias = ''; friendAlias = ''; gender = 0; portrait = ''; mobile = ''; email = ''; address = ''; social = ''; extra = ''; type = 0; //0 normal; 1 robot; 2 thing; //0 normal; 1 deleted; deleted = 0; updateDt = 0; } /* * Copyright (c) 2020 TianjiChat. All rights reserved. */ class NullUserInfo extends UserInfo { constructor(userId) { super(); this.uid = userId; //this.name = '<' + userId + '>'; this.name = '用户'; this.displayName = this.name; this.portrait = ''; } } var i$1 = /*#__PURE__*/Object.freeze({ __proto__: null, default: NullUserInfo }); /* * Copyright (c) 2020 TianjiChat. All rights reserved. */ // 说明 // 1. 由于PC SDK 和 Web SDK 对java long类型的处理不一致 ,故引入本系列函数 // 2. PC SDK,messageUid转换为long类型(可参考long.js),其他所有时间相关的字段,都转换成number // 3. Web SDK,messageUid 以及所有时间相关的字段都转换为long类型 // 4. 为了将UI层代码统一,对所有相关字段进行比较 、运算等操作时,都必须由本序列函数处理 /** * 比较数值大小 * @param {Long | number | string} a * @param {Long | number | string} b * @return {number} 相等返回0,a 大于 b 返回1,a 小于 b 返回-1 */ function compare(a, b) { const longA = Long.fromValue(a); const longB = Long.fromValue(b); return longA.compare(longB); } /** * 判断数值是否相等 * @param {Long | number | string} a * @param {Long | number | string} b * @return {boolean} 相等返回true;否则返回false */ function eq(a, b) { if (!_isLong(a) || !_isLong(b)) { return false; } return compare(a, b) === 0; } /** * 判断数值a是否大于b * @param {Long | number | string} a * @param {Long | number | string} b * @return {boolean} a大于b返回true;否则返回false */ function gt(a, b) { if (!_isLong(a) || !_isLong(b)) { return false; } return compare(a, b) === 1; } /** * 判断数值a是否大于或等于b * @param {Long | number | string} a * @param {Long | number | string} b * @return {boolean} a大于或等于b返回true;否则返回false */ function gte(a, b) { if (!_isLong(a) || !_isLong(b)) { return false; } return compare(a, b) >= 0; } /** * 判断数值a是否小于b * @param {Long | number | string} a * @param {Long | number | string} b * @return {boolean} a小于b返回true;否则返回false */ function lt(a, b) { if (!_isLong(a) || !_isLong(b)) { return false; } return compare(a, b) === -1; } /** * 判断数值a是否小于或等于b * @param {Long | number | string} a * @param {Long | number | string} b * @return {boolean} a小于或者等于b返回true;否则返回false */ function lte(a, b) { if (!_isLong(a) || !_isLong(b)) { return false; } return compare(a, b) <= 0; } /** * 将数值l转换成string类型 * @param {Long | number | string} l * @return {string} 数值表示 */ function stringValue(l) { const longl = Long.fromValue(l); return longl.toString(); } /** * 将数值l转换成Long类型 * @param {Long | number | string} l * @return {Long} 数值表示 */ function longValue(value) { return Long.fromValue(value); } /** * 将数值l转换成number类型 * @param {Long | number | string} l * @return {number|l} 如果数值l小于等于{@code Number.MAX_SAFE_INTEGER}则返回对应的number,否则原样返回 */ function numberValue(l) { if (lte(l, Number.MAX_SAFE_INTEGER)) { const longl = Long.fromValue(l); return longl.toNumber(); } else { console.log(l, 'is large than Number.MAX_SAFE_INTEGER, do nothing'); return l; } } /** * * 由于Java long类型,在js里面,不能用number类型表示,故js里面采用js long对象表示 * java long数据和js long对象序列成json格式的字符串时,格式并一样,为了处理跨平台需求, * 将序列化后的json格式字符串 * java long "uid":12345678 * * 当Java long类型的值,需要序列化为json字符串进行传输时,js long对象序列化出来的 */ function _patchToJavaLong(jsonStr, key) { if (!jsonStr) { return jsonStr; } let reg = new RegExp(`"${key}":"([0-9]+)"`, 'g'); return jsonStr.replace(reg, `\"${key}\":$1`); } function _reverseToJsLongString(jsonStr, key) { if (!jsonStr) { return jsonStr; } let reg = new RegExp(`"${key}":([0-9]+)`, 'g'); return jsonStr.replace(reg, `\"${key}\":\"$1\"`); } function _isLong(val) { try { Long.fromValue(val); return true; } catch (e) { return false; } } function int64ToUint8Array(value) { let long = Long.fromValue(value); let byteArray = new Uint8Array(8); for (let i = 0; i < 8; i++) { byteArray[i] = long.and(0xff).toNumber(); long = long.shiftRight(8); } return byteArray; } function uint8ArrayToInt64(array) { let value = Long.fromNumber(0); for (let i = 7; i >= 0; i--) { value = value.shiftLeft(8).or(array[i]); } return value; } const LongUtil = { compare, eq, gt, gte, lt, lte, stringValue, longValue, numberValue, int64ToUint8Array, uint8ArrayToInt64 }; var n$1 = /*#__PURE__*/Object.freeze({ __proto__: null, LongUtil: LongUtil, _patchToJavaLong: _patchToJavaLong, _reverseToJsLongString: _reverseToJsLongString, compare: compare, default: LongUtil, eq: eq, gt: gt, gte: gte, int64ToUint8Array: int64ToUint8Array, longValue: longValue, lt: lt, lte: lte, numberValue: numberValue, stringValue: stringValue, uint8ArrayToInt64: uint8ArrayToInt64 }); /* 视频属性 (Profile) 定义 视频属性 枚举值 分辨率(宽x高) 帧率(fps) 码率(kbps) 120P 0 160x120 15 120 120P_3 2 120x120 15 100 180P 10 320x180 15 280 180P_3 12 180x180 15 200 180P_4 13 240x180 15 240 240P 20 320x240 15 360 240P_3 22 240x240 15 280 240P_4 24 424x240 15 400 360P 30 640x360 15 800 360P_3 32 360x360 15 520 360P_4 33 640x360 30 1200 360P_6 35 360x360 30 780 360P_7 36 480x360 15 1000 360P_8 37 480x360 30 1500 480P 40 640x480 15 1000 480P_3 42 480x480 15 800 480P_4 43 640x480 30 1500 480P_6 45 480x480 30 1200 480P_8 47 848x480 15 1200 480P_9 48 848x480 30 1800 720P 50 1280x720 15 2400 720P_3 52 1280x720 30 3699 720P_5 54 960x720 15 1920 720P_6 55 960x720 30 2880 1080P 60 1920×1080 15 4200 1080P_3 60 1920×1080 30 6300 1080P_5 60 1920×1080 60 9560 */ class VideoProfile { static VP120P = 0; static VP120P_3 = 2; static VP180P = 10; static VP180P_3 = 12; static VP180P_4 = 13; static VP240P = 20; static VP240P_3 = 22; static VP240P_4 = 23; static VP360P = 30; static VP360P_3 = 32; static VP360P_4 = 33; static VP360P_6 = 35; static VP360P_7 = 36; static VP360P_8 = 37; static VP480P = 40; static VP480P_3 = 42; static VP480P_4 = 43; static VP480P_6 = 45; static VP480P_8 = 47; static VP480P_9 = 48; static VP720P = 50; static VP720P_3 = 52; static VP720P_5 = 54; static VP720P_6 = 55; static VP1080P = 60; static VP1080P_3 = 62; static VP1080P_5 = 64; static VPDEFAULT = VideoProfile.VP360P; width; height; fps; bitrate; constructor(width, height, fps, bitrate) { this.width = width; this.height = height; this.fps = fps; this.bitrate = bitrate; } static getVideoProfile(videoProfile) { switch (videoProfile) { // 120P 0 160x120 15 65 // 120P_3 2 120x120 15 50 case VideoProfile.VP120P: return new VideoProfile(160, 120, 15, 120); case VideoProfile.VP120P_3: return new VideoProfile(120, 120, 15, 100); // 180P 10 320x180 15 140 // 180P_3 12 180x180 15 100 // 180P_4 13 240x180 15 120 case VideoProfile.VP180P: return new VideoProfile(320, 180, 15, 280); case VideoProfile.VP180P_3: return new VideoProfile(180, 180, 15, 200); case VideoProfile.VP180P_4: return new VideoProfile(240, 180, 15, 240); // 240P 20 320x240 15 200 // 240P_3 22 240x240 15 140 // 240P_4 24 424x240 15 220 case VideoProfile.VP240P: return new VideoProfile(320, 240, 15, 360); case VideoProfile.VP240P_3: return new VideoProfile(240, 240, 15, 240); case VideoProfile.VP240P_4: return new VideoProfile(424, 240, 15, 400); // 360P 30 640x360 15 400 // 360P_3 32 360x360 15 260 // 360P_4 33 640x360 30 600 // 360P_6 35 360x360 30 400 // 360P_7 36 480x360 15 320 // 360P_8 37 480x360 30 490 case VideoProfile.VP360P: return new VideoProfile(640, 360, 15, 800); case VideoProfile.VP360P_3: return new VideoProfile(360, 360, 15, 520); case VideoProfile.VP360P_4: return new VideoProfile(640, 360, 30, 1200); case VideoProfile.VP360P_6: return new VideoProfile(360, 360, 30, 780); case VideoProfile.VP360P_7: return new VideoProfile(480, 360, 15, 1000); case VideoProfile.VP360P_8: return new VideoProfile(480, 360, 30, 1500); // 480P 40 640x480 15 500 // 480P_3 42 480x480 15 400 // 480P_4 43 640x480 30 750 // 480P_6 45 480x480 30 600 // 480P_8 47 848x480 15 610 // 480P_9 48 848x480 30 930 case VideoProfile.VP480P: return new VideoProfile(640, 480, 15, 1000); case VideoProfile.VP480P_3: return new VideoProfile(480, 480, 15, 800); case VideoProfile.VP480P_4: return new VideoProfile(640, 480, 30, 1500); case VideoProfile.VP480P_6: return new VideoProfile(480, 480, 30, 1200); case VideoProfile.VP480P_8: return new VideoProfile(848, 480, 15, 1200); case VideoProfile.VP480P_9: return new VideoProfile(848, 480, 30, 1800); // 720P 50 1280x720 15 1130 // 720P_3 52 1280x720 30 1710 // 720P_5 54 960x720 15 910 // 720P_6 55 960x720 30 1380 case VideoProfile.VP720P: return new VideoProfile(1280, 720, 15, 2400); case VideoProfile.VP720P_3: return new VideoProfile(1280, 720, 30, 3600); case VideoProfile.VP720P_5: return new VideoProfile(960, 720, 15, 1920); case VideoProfile.VP720P_6: //1080P 60 1920 * 1080 15 2080 //1080P_3 62 1920 * 1080 30 3150 //1080P_5 64 1920 * 1080 60 4780 return new VideoProfile(960, 720, 30, 2880); case VideoProfile.VP1080P: return new VideoProfile(1920, 1080, 15, 4200); case VideoProfile.VP1080P_3: return new VideoProfile(1920, 1080, 30, 6300); case VideoProfile.VP1080P_5: return new VideoProfile(1920, 1080, 60, 9560); default: return VideoProfile.getVideoProfile(VideoProfile.VPDEFAULT); } } } var p$1 = /*#__PURE__*/Object.freeze({ __proto__: null, default: VideoProfile }); /* * Copyright (c) 2020 TianjiChat. All rights reserved. */ class TjcAVEngineKit { /** * CallSession 相关回调 * @deprecated 可能被移除,请勿直接设置,可通过{@link setup}参数直接传入 */ sessionCallback; /** * 音视频window显示的时候调用 */ setup(sessionCallback) {} /** * 返回当前音视频通话session * 仅在音视频窗口调用有效 */ getCurrentSession() {} static MAX_AUDIO_PARTICIPANT_COUNT = 16; static MAX_VIDEO_PARTICIPANT_COUNT = 9; // 是否禁用双流模式 static DISABLE_DUAL_STREAM = false; /** 屏幕分享替换模式。为ture时,屏幕分享会替换摄像头的数据流。为false时,屏幕分享会再单独发起一路,不会影响摄像头的输入。 */ static SCREEN_SHARING_REPLACE_MODE = true; /** * 是否启用 datachannel * @type {boolean} */ static ENABLE_DATA_CHANNEL = true; /** 禁止双流模式下,小流低帧率。默认为false,小流的帧率为8fps。当为true时使用 {@link SMALL_STREAM_FPS}, 或者使用同大流一样的帧率 */ static DISABLE_SMALL_STREAM_LOW_FPS = false; /** * 小流分辨率,宽度 */ static SMALL_STREAM_WIDTH = 200; /** * 小流分辨率, 高度 */ static SMALL_STREAM_HEIGHT = 200; /** * 小流 fps */ static SMALL_STREAM_FPS = 8; static VIDEO_PROFILE = VideoProfile.VPDEFAULT; // 可参考 {@link videoProfile} 里面的bitrate,仅非替换模式生效。 // 屏幕共享的分辨率等,需通过{@link startScreenShare} 设置 static SCREEN_SHARE_MAX_BITRATE = 3600; /** * 高级版音视频 SDK 有效 * 是否强制使用 TCP 传输媒体数据 * 启用时,janus 的配置里面,需要将 ice_tcp 置为 true * 注意,强制使用 TCP 传输媒体数据,在网络丢包比较严重时,效果可能不太好 * @type {boolean} */ static FORCE_MEDIA_OVER_TCP = false; /** * 没有麦克风和音频输出设备时,是否允许发起或参加音视频通话 * @type {boolean} */ static ENABLE_VOIP_WHEN_NO_MIC_AND_SPEAKER = true; /** * 高级版音视频 SDK 有效 * 是否强制采用 relay 模式 * 具体请参考 {@link https://docs.tianjichat.cn/blogs/%E9%9F%B3%E8%A7%86%E9%A2%91%E9%AB%98%E7%BA%A7%E7%89%88%E7%9A%84%E5%8D%95%E7%AB%AF%E5%8F%A3%E5%8C%96%E5%92%8C%E5%BC%BA%E5%88%B6TCP%E5%8C%96.html} * @type {boolean} */ static FORCE_RELAY = false; // 没有摄像头时的占位视频 // 200 x 200,1s,无声,黑屏 static DUMMY_VIDEO_URI = 'data:video/mp4;base64,AAAAIGZ0eXBpc29tAAACAGlzb21pc28yYXZjMW1wNDEAAAAIZnJlZQAABZJtZGF0AAACrgYF//+q3EXpvebZSLeWLNgg2SPu73gyNjQgLSBjb3JlIDE2MSByMzAyNyA0MTIxMjc3IC0gSC4yNjQvTVBFRy00IEFWQyBjb2RlYyAtIENvcHlsZWZ0IDIwMDMtMjAyMCAtIGh0dHA6Ly93d3cudmlkZW9sYW4ub3JnL3gyNjQuaHRtbCAtIG9wdGlvbnM6IGNhYmFjPTEgcmVmPTMgZGVibG9jaz0xOjA6MCBhbmFseXNlPTB4MzoweDExMyBtZT1oZXggc3VibWU9NyBwc3k9MSBwc3lfcmQ9MS4wMDowLjAwIG1peGVkX3JlZj0xIG1lX3JhbmdlPTE2IGNocm9tYV9tZT0xIHRyZWxsaXM9MS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AAAsAAAAAQAAAGJ1ZHRhAAAAWm1ldGEAAAAAAAAAIWhkbHIAAAAAAAAAAG1kaXJhcHBsAAAAAAAAAAAAAAAALWlsc3QAAAAlqXRvbwAAAB1kYXRhAAAAAQAAAABMYXZmNTguNDUuMTAw'; } var a$1 = /*#__PURE__*/Object.freeze({ __proto__: null, default: TjcAVEngineKit }); /* * Copyright (c) 2020 TianjiChat. All rights reserved. */ class EventType { // function (message) {} static SendMessage = 'sendMsg'; // function (message, hasMore) {} static ReceiveMessage = 'receiveMsg'; // function (Map(userId, receiveTime)) {} static MessageReceived = 'msgReceived'; // function ([readEntry]) {} static MessageRead = 'msgRead'; // 主动调用recallMessage时,也会触发 // function (operator, messageUid) {} static RecallMessage = 'recallMsg'; // 远程删除消息时触发 // function (messageUid) {} static MessageDeleted = 'msgDeleted'; // function (messageId) {} // 本地主动删除消息时触发 static DeleteMessage = 'deleteMsg'; // function (message) {} static MessageStatusUpdate = 'msgStatusUpdate'; // function (message) {} static MessageContentUpdate = 'msgContentUpdate'; // function (connectionStatus) {} static ConnectionStatusChanged = 'connectionStatusChanged'; // function (host/ip/port) {} static ConnectToServer = 'connectToServer'; // function (host/ip/port/mainNw) {} static ConnectedToServer = 'connectedToServer'; // function (userInfos) {} static UserInfosUpdate = 'userInfosUpdate'; // function (channelInfos) {} static ChannelInfosUpdate = 'channelInfosUpdate'; // function (groupInfos) {} static GroupInfosUpdate = 'groupInfosUpdate'; // function (updatedFriendIds) {} static FriendListUpdate = 'friendListUpdate'; // function ([newFriendRequests]) {} static FriendRequestUpdate = 'friendRequestUpdate'; // function (conversationInfo) {} static ConversationInfoUpdate = 'conversationInfoUpdate'; // function () {} static SettingUpdate = 'settingUpdate'; // function (groupId, GroupMember[]) {} static GroupMembersUpdate = 'groupMembersUpdate'; // function (event) {} static ConferenceEvent = 'conferenceEvent'; // function (UserOnlineState[]) {} static UserOnlineEvent = 'onlineEvent'; // function (targetId, playedMessageId) {} static SecretChatStartBurn = 'secretChatStartBurn'; // function ([messageId]) {} static SecretChatMessageBurned = 'secretChatMessageBurned'; // function (targetId) {} static SecretChatStateChange = 'secretChatStateChange'; // function (domainInfo) {} static DomainInfoUpdate = 'domainInfoUpdate'; } var t = /*#__PURE__*/Object.freeze({ __proto__: null, default: EventType }); // 使用 Buffer 来处理 base64 const c$2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; function btoa$1(e) { for (var t, r, o = String(e), n = 0, a = c$2, i = ""; o.charAt(0 | n) || (a = "=", n % 1); i += a.charAt(63 & t >> 8 - n % 1 * 8)) { if (255 < (r = o.charCodeAt(n += 0.75))) throw new Error("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range."); t = t << 8 | r; } return i; } function atob$1(e) { var t = String(e).replace(/[=]+$/, ""); if (t.length % 4 == 1) throw new Error("'atob' failed: The string to be decoded is not correctly encoded."); for (var r, o, n = 0, a = 0, i = ""; o = t.charAt(a++); ~o && (r = n % 4 ? 64 * r + o : o, n++ % 4) ? i += String.fromCharCode(255 & r >> (-2 * n & 6)) : 0) o = c$2.indexOf(o); return i; } /** * URL 安全的 base64 解码 * @param {string} str URL 安全的 base64 字符串 * @returns {string} 标准 base64 字符串 */ function unescape(str) { return (str + '==='.slice((str.length + 3) % 4)).replace(/-/g, '+').replace(/_/g, '/'); } /** * URL 安全的 base64 编码 * @param {string} str 标准 base64 字符串 * @returns {string} URL 安全的 base64 字符串 */ function escape(str) { return str.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, ''); } /* * Copyright (c) 2020 TianjiChat. All rights reserved. */ /** * "content": { "type": 1, "searchableContent": "1234", "pushContent": "", "content": "", "binaryContent": "", "localContent": "", "mediaType": 0, "remoteMediaUrl": "", "localMediaPath": "", "mentionedType": 0, "mentionedTargets": [ ] }, */ class MessagePayload { type; searchableContent; pushContent; pushData; content; binaryContent; // base64 string, 图片时,不包含头部信息:data:image/png;base64, localContent; mediaType; remoteMediaUrl; localMediaPath; mentionedType = 0; mentionedTargets = []; extra; // 仅超级群有效,消息是否已完整服务器加载 notLoaded = 0; } /* * Copyright (c) 2020 TianjiChat. All rights reserved. */ class MessageContent { type = MessageContentType.Unknown; //0 普通消息, 1 部分提醒, 2 提醒全部 mentionedType = 0; //提醒对象,mentionedType 1时有效 mentionedTargets = []; extra; pushContent; // 仅超级群有效,消息是否已完整服务器加载 notLoaded = 0; constructor(type, mentionedType = 0, mentionedTargets = []) { this.type = type; this.mentionedType = mentionedType; this.mentionedTargets = mentionedTargets; } digest() { return ''; } /** * return MessagePayload in json format */ encode() { return ''; } /** * * @param {object} payload object json.parse from message#content */ decode(payload) { // 默认实现 } toString() { return `[MessageContent type=${MessageContentType.getTypeName(this.type)}]`; } } var n = /*#__PURE__*/Object.freeze({ __proto__: null, default: MessageContent }); /* * Copyright (c) 2020 TianjiChat. All rights reserved. */ class NotificationMessageContent extends MessageContent { // message#protoMessageToMessage时设置 fromSelf = false; constructor(type) { super(type); } digest(message) { var desc = ''; try { desc = this.formatNotification(message); } catch (error) { console.log('disgest', error); } return desc; } formatNotification(message) { return '..nofication..'; } } class QuoteInfo { messageUid; userId; userDisplayName; messageDigest; static initWithMessage(message) { let info = new QuoteInfo(); if (message) { info.messageUid = message.messageUid; info.userId = message.from; let userInfo = self$4.getUserInfo(message.from, false); info.userDisplayName = userInfo.displayName; info.messageDigest = message.messageContent.digest(); if (info.messageDigest.length > 48) { info.messageDigest = info.messageDigest.substr(0, 48); } } return info; } encode() { let obj = { u: stringValue(this.messageUid), i: this.userId, n: this.userDisplayName, d: this.messageDigest }; return obj; } decode(obj) { if (obj.messageUid) { this.messageUid = Long.fromValue(obj.messageUid); this.userId = obj.userId; this.userDisplayName = obj.userDisplayName; this.messageDigest = obj.messageDigest; } else { this.messageUid = Long.fromValue(obj.u || obj.messageUid); this.userId = obj.i; this.userDisplayName = obj.n; this.messageDigest = obj.d; } } } /* * Copyright (c) 2020 TianjiChat. All rights reserved. */ class TextMessageContent extends MessageContent { content; quoteInfo; constructor(content, mentionedType = 0, mentionedTargets = []) { super(MessageContentType.Text, mentionedType, mentionedTargets); this.content = content; } digest() { return this.content; } encode() { let payload = super.encode(); payload.searchableContent = this.content; if (this.quoteInfo) { let obj = { "quote": this.quoteInfo.encode() }; // JSON.parse 和 JSON.stringify 不能处理java long let orgStr = JSON.stringify(obj); let str = orgStr.replace(/"u":"([0-9]+)"/, "\"u\":$1"); payload.binaryContent = self$4.utf8_to_b64(str); } return payload; } decode(payload) { super.decode(payload); this.content = payload.searchableContent; if (payload.binaryContent && payload.binaryContent.length > 0) { // JSON.parse 和 JSON.stringify 不能处理java long let quoteInfoStr = self$4.b64_to_utf8(payload.binaryContent); // FIXME node 环境,decodeURIComponent 方法,有时候会在最后添加上@字符,目前尚未找到原因,先规避 quoteInfoStr = quoteInfoStr.substring(0, quoteInfoStr.lastIndexOf('}') + 1); quoteInfoStr = quoteInfoStr.replace(/"u":([0-9]+),/, '"u":"$1",'); let obj = JSON.parse(quoteInfoStr).quote; this.quoteInfo = new QuoteInfo(); this.quoteInfo.decode(obj); } } setQuoteInfo(quoteInfo) { this.quoteInfo = quoteInfo; } } /* * Copyright (c) 2020 TianjiChat. All rights reserved. */ class PTextMessageContent extends TextMessageContent { constructor(content, mentionedType = 0, mentionedTargets = []) { super(content, mentionedType, mentionedTargets); this.type = MessageContentType.P_Text; } } var Config = { urlRedirect: null // 添加其他配置项 }; /* * Copyright (c) 2020 TianjiChat. All rights reserved. */ class MediaMessageContent extends MessageContent { file; remotePath = ''; localPath = ''; mediaType = 0; /** * * @param {number} messageType 消息类型 * @param {number} mediaType 媒体类型 * @param {File | string} fileOrLocalPath File类型,或者dataUri或者本地路径,本地路径是必须是绝对路径 * @param {string} remotePath 远端地址 */ constructor(messageType, mediaType = 0, fileOrLocalPath, remotePath) { super(messageType); this.mediaType = mediaType; if (!fileOrLocalPath) { this.localPath = ''; this.remotePath = remotePath; } else if (typeof fileOrLocalPath === "string" && !fileOrLocalPath.startsWith("http")) { this.localPath = fileOrLocalPath; this.remotePath = remotePath; } else { this.file = fileOrLocalPath; if (fileOrLocalPath && fileOrLocalPath.path) { this.localPath = fileOrLocalPath.path; // attention: 粘贴的时候,path是空字符串,故采用了这个trick if (this.localPath.indexOf(fileOrLocalPath.name) < 0) { this.localPath += fileOrLocalPath.name; } } } } encode() { let payload = super.encode(); payload.localMediaPath = this.localPath; payload.remoteMediaUrl = this.remotePath ? this.remotePath : ''; payload.mediaType = this.mediaType; if (Config.urlRedirect) { this.remotePath = Config.urlRedirect(payload.remoteMediaUrl); } return payload; } decode(payload) { super.decode(payload); this.localPath = payload.localMediaPath; this.remotePath = payload.remoteMediaUrl; if (Config.urlRedirect) { this.remotePath = Config.urlRedirect(payload.remoteMediaUrl); } this.mediaType = payload.mediaType; } } /* * Copyright (c) 2020 TianjiChat. All rights reserved. */ class MessageContentMediaType { static General = 0; static Image = 1; static Voice = 2; static Video = 3; static File = 4; static Portrait = 5; static Favorite = 6; static Sticker = 7; static Moments = 8; } /* * Copyright (c) 2020 TianjiChat. All rights reserved. */ class ImageMessageContent extends MediaMessageContent { // base64 encoded, 不包含头部:data:image/png;base64, thumbnail; imageWidth; imageHeight; constructor(fileOrLocalPath, remotePath, thumbnail) { super(MessageContentType.Image, MessageContentMediaType.Image, fileOrLocalPath, remotePath); this.thumbnail = thumbnail; } digest() { return '[图片]'; } encode() { let payload = super.encode(); payload.mediaType = MessageContentMediaType.Image; payload.binaryContent = this.thumbnail; if (this.imageWidth) { let obj = { w: this.imageWidth, h: this.imageHeight }; payload.content = JSON.stringify(obj); } return payload; } decode(payload) { super.decode(payload); this.thumbnail = payload.binaryContent; if (payload.content) { let obj = JSON.parse(payload.content); this.imageWidth = obj['w']; this.imageHeight = obj['h']; } } } /* * Copyright (c) 2020 TianjiChat. All rights reserved. */ class PersistFlag { static No_Persist = 0; static Persist = 1; static Persist_And_Count = 3; static Transparent = 4; } var i = /*#__PURE__*/Object.freeze({ __proto__: null, default: PersistFlag }); /* * Copyright (c) 2020 TianjiChat. All rights reserved. */ class TipNotificationMessageContent extends NotificationMessageContent { tip = ''; constructor(tip) { super(MessageContentType.Tip_Notification); this.tip = tip; } formatNotification() { return this.tip; } digest() { return this.tip; } encode() { let payload = super.encode(); payload.content = this.tip; return payload; } decode(payload) { super.decode(payload); this.tip = payload.content; } } /* * Copyright (c) 2020 TianjiChat. All rights reserved. */ class UnknownMessageContent extends MessageContent { originalPayload; constructor(originalPayload) { super(MessageContentType.Unknown); this.originalPayload = originalPayload; } encode() { return this.originalPayload; } decode(paylaod) { this.originalPayload = paylaod; } digest() { return '未知类型消息'; } } /* * Copyright (c) 2020 TianjiChat. All rights reserved. */ class UnsupportMessageContent extends MessageContent { digest() { return '尚不支持该类型消息, 请手机查看 : ' + this.type; } } /* * Copyright (c) 2020 TianjiChat. All rights reserved. */ class GroupNotificationContent extends NotificationMessageContent { groupId = ''; constructor(type) { super(type); } } /* * Copyright (c) 2020 TianjiChat. All rights reserved. */ class ChangeGroupNameNotification extends GroupNotificationContent { operator = ''; name = ''; constructor(operator, name) { super(MessageContentType.ChangeGroupName_Notification); this.operator = operator; this.name = name; } formatNotification() { if (this.fromSelf) { return '您修改群名称为:' + this.name; } else { return self$4.getGroupMemberDisplayName(this.groupId, this.operator) + '修改群名称为:' + this.name; } } encode() { let payload = super.encode(); let obj = { g: this.groupId, n: this.name, o: this.operator }; payload.binaryContent = self$4.utf8_to_b64(JSON.stringify(obj)); return payload; } decode(payload) { super.decode(payload); let json = self$4.b64_to_utf8(payload.binaryContent); let obj = JSON.parse(json); this.groupId = obj.g; this.operator = obj.o; this.name = obj.n; } } /* * Copyright (c) 2020 TianjiChat. All rights reserved. */ class KickoffGroupMemberNotification extends GroupNotificationContent { operator = ''; kickedMembers = []; constructor(operator, kickedMembers) { super(MessageContentType.KickOffGroupMember_Notification); this.operator = operator; this.kickedMembers = kickedMembers; } formatNotification() { let notifyStr; if (this.fromSelf) { notifyStr = '您把 '; } else { notifyStr = self$4.getGroupMemberDisplayName(this.groupId, this.operator) + '把 '; } let kickedMembersStr = ''; let userInfos = self$4.getUserInfos(this.kickedMembers, this.groupId); userInfos.forEach(userInfo => { if (userInfo.uid === self$4.getUserId()) { kickedMembersStr += ' 您'; } else { kickedMembersStr += ' ' + userInfo.displayName; } }); return notifyStr + kickedMembersStr + ' 移除了群组'; } encode() { let payload = super.encode(); let obj = { g: this.groupId, ms: this.kickedMembers, o: this.operateUser }; payload.binaryContent = self$4.utf8_to_b64(JSON.stringify(obj)); return payload; } decode(payload) { super.decode(payload); let json = self$4.b64_to_utf8(payload.binaryContent); let obj = JSON.parse(json); this.groupId = obj.g; this.operator = obj.o; this.kickedMembers = obj.ms; } } /* * Copyright (c) 2020 TianjiChat. All rights reserved. */ class KickoffGroupMemberVisiableNotification extends GroupNotificationContent { operator = ''; kickedMembers = []; constructor(operator, kickedMembers) { super(MessageContentType.KickOffGroupMember_Visible_Notification); this.operator = operator; this.kickedMembers = kickedMembers; } formatNotification() { let notifyStr; if (this.fromSelf) { notifyStr = '您把 '; } else { notifyStr = self$4.getGroupMemberDisplayName(this.groupId, this.operator) + '把 '; } let kickedMembersStr = ''; let userInfos = self$4.getUserInfos(this.kickedMembers, this.groupId); userInfos.forEach(userInfo => { if (userInfo.uid === self$4.getUserId()) { kickedMembersStr += ' 您'; } else { kickedMembersStr += ' ' + userInfo.displayName; } }); return notifyStr + kickedMembersStr + ' 移除了群组'; } encode() { let payload = super.encode(); let obj = { g: this.groupId, ms: this.kickedMembers, o: this.operateUser }; payload.binaryContent = self$4.utf8_to_b64(JSON.stringify(obj)); return payload; } decode(payload) { super.decode(payload); let json = self$4.b64_to_utf8(payload.binaryContent); let obj = JSON.parse(json); this.groupId = obj.g; this.operator = obj.o; this.kickedMembers = obj.ms; } } /* * Copyright (c) 2020 TianjiChat. All rights reserved. */ class AddGroupMemberNotification extends GroupNotificationContent { invitor = ''; invitees = []; constructor(invitor, invitees) { super(MessageContentType.AddGroupMember_Notification); this.invitor = invitor; this.invitees = invitees; } formatNotification() { let notifyStr; if (this.invitees.length === 1 && this.invitees[0] === this.invitor) { if (this.fromSelf) { return '您加入了群组'; } else { return self$4.getGroupMemberDisplayName(this.groupId, this.invitor) + ' 加入了群组'; } } if (this.fromSelf) { notifyStr = '您邀请:'; } else { notifyStr = self$4.getGroupMemberDisplayName(this.groupId, this.invitor) + '邀请:'; } let membersStr = ''; let userInfos = self$4.getUserInfos(this.invitees, this.groupId); userInfos.forEach(m => { membersStr += ' ' + m.displayName; }); return notifyStr + membersStr + '加入了群组'; } encode() { let payload = super.encode(); let obj = { g: this.groupId, o: this.invitor, ms: this.invitees }; payload.binaryContent = self$4.utf8_to_b64(JSON.stringify(obj)); return payload; } decode(payload) { super.decode(payload); let json = self$4.b64_to_utf8(payload.binaryContent); let obj = JSON.parse(json); this.groupId = obj.g; this.invitor = obj.o; this.invitees = obj.ms; } } /* * Copyright (c) 2020 TianjiChat. All rights reserved. */ class ChangeGroupPortraitNotification extends GroupNotificationContent { operator = ''; constructor(operator) { super(MessageContentType.ChangeGroupPortrait_Notification); this.operator = operator; } formatNotification() { if (this.fromSelf) { return '您修改群头像'; } else { return self$4.getGroupMemberDisplayName(this.groupId, this.operator) + '修改了群头像'; } } encode() { let payload = super.encode(); let obj = { g: this.groupId, n: this.name }; payload.binaryContent = self$4.utf8_to_b64(JSON.stringify(obj)); return payload; } decode(payload) { super.decode(payload); let json = self$4.b64_to_utf8(payload.binaryContent); let obj = JSON.parse(json); this.groupId = obj.g; this.operator = obj.o; } } /* * Copyright (c) 2020 TianjiChat. All rights reserved. */ class CreateGroupNotification extends GroupNotificationContent { creator = ''; groupName = ''; constructor(creator, groupName) { super(MessageContentType.CreateGroup_Notification); this.creator = creator; this.groupName = groupName; } formatNotification() { if (this.fromSelf) { return '您创建了群组 ' + this.groupName; } else { return self$4.getUserDisplayName(this.creator) + '创建了群组 ' + this.groupName; } } encode() { let payload = super.encode(); let obj = { g: this.groupId, n: this.groupName, o: this.creator }; payload.binaryContent = self$4.utf8_to_b64(JSON.stringify(obj)); return payload; } decode(payload) { super.decode(payload); let json = self$4.b64_to_utf8(payload.binaryContent); let obj = JSON.parse(json); this.groupId = obj.g; this.creator = obj.o; this.groupName = obj.n; } } /* * Copyright (c) 2020 TianjiChat. All rights reserved. */ class DismissGroupNotification extends GroupNotificationContent { operator = ''; constructor(operator) { super(MessageContentType.DismissGroup_Notification); this.operator = operator; } formatNotification() { if (this.fromSelf) { return '您解散了群组'; } else { return self$4.getGroupMemberDisplayName(this.groupId, this.operator) + '解散了群组'; } } encode() { let payload = super.encode(); let obj = { g: this.groupId, o: this.operator }; payload.binaryContent = self$4.utf8_to_b64(JSON.stringify(obj)); return payload; } decode(payload) { super.decode(payload); let json = self$4.b64_to_utf8(payload.binaryContent); let obj = JSON.parse(json); this.groupId = obj.g; this.operator = obj.o; } } /* * Copyright (c) 2020 TianjiChat. All rights reserved. */ class ModifyGroupAliasNotification extends GroupNotificationContent { operator = ''; alias = ''; memberId = ''; constructor(creator, alias) { super(MessageContentType.ModifyGroupAlias_Notification); this.operator = creator; this.alias = alias; } formatNotification() { let notificationStr = ''; if (this.fromSelf) { notificationStr += '你'; } else { let userInfo = self$4.getUserInfo(this.operator, false, this.groupId); if (userInfo.friendAlias) { notificationStr += userInfo.friendAlias; } else if (userInfo.displayName) { notificationStr += userInfo.displayName; } else { notificationStr += this.operator; } } notificationStr += '修改'; if (this.memberId) { let userInfo = self$4.getUserInfo(this.memberId, false); if (userInfo.friendAlias) { notificationStr += userInfo.friendAlias; } else if (userInfo.displayName) { notificationStr += userInfo.displayName; } else { notificationStr += this.memberId; } notificationStr += '的'; } notificationStr += '群昵称为'; notificationStr += this.alias; return notificationStr; } encode() { let payload = super.encode(); let obj = { g: this.groupId, n: this.alias, o: this.operator, m: this.memberId }; payload.binaryContent = self$4.utf8_to_b64(JSON.stringify(obj)); return payload; } decode(payload) { super.decode(payload); let json = self$4.b64_to_utf8(payload.binaryContent); let obj = JSON.parse(json); this.groupId = obj.g; this.operator = obj.o; this.alias = obj.n; this.memberId = obj.m; } } /* * Copyright (c) 2020 TianjiChat. All rights reserved. */ class ModifyGroupExtraNotification extends GroupNotificationContent { operator = ''; groupExtra = ''; constructor(creator, groupExtra) { super(MessageContentType.ModifyGroupExtra_Notification); this.operator = creator; this.groupExtra = groupExtra; } formatNotification() { let notificationStr = ''; if (this.fromSelf) { notificationStr += '你'; } else { let userInfo = self$4.getUserInfo(this.operator, false, this.groupId); if (userInfo.friendAlias) { notificationStr += userInfo.friendAlias; } else if (userInfo.displayName) { notificationStr += userInfo.displayName; } else { notificationStr += this.operator; } } notificationStr += '修改'; notificationStr += '群附加信息为'; notificationStr += this.groupExtra; return notificationStr; } encode() { let payload = super.encode(); let obj = { g: this.groupId, n: this.groupExtra, o: this.operator }; payload.binaryContent = self$4.utf8_to_b64(JSON.stringify(obj)); return payload; } decode(payload) { super.decode(payload); let json = self$4.b64_to_utf8(payload.binaryContent); let obj = JSON.parse(json); this.groupId = obj.g; this.operator = obj.o; this.groupExtra = obj.n; } } /* * Copyright (c) 2020 TianjiChat. All rights reserved. */ class ModifyGroupMemberExtraNotification extends GroupNotificationContent { operator = ''; groupMemberExtra = ''; memberId = ''; constructor(creator, groupMemberExtra) { super(MessageContentType.ModifyGroupMemberExtra_Notification); this.operator = creator; this.groupMemberExtra = groupMemberExtra; } formatNotification() { let notificationStr = ''; if (this.fromSelf) { notificationStr += '你'; } else { let userInfo = self$4.getUserInfo(this.operator, false, this.groupId); if (userInfo.friendAlias) { notificationStr += userInfo.friendAlias; } else if (userInfo.displayName) { notificationStr += userInfo.displayName; } else { notificationStr += this.operator; } } notificationStr += '修改'; if (this.memberId) { let userInfo = self$4.getUserInfo(this.memberId, false); if (userInfo.friendAlias) { notificationStr += userInfo.friendAlias; } else if (userInfo.displayName) { notificationStr += userInfo.displayName; } else { notificationStr += this.memberId; } notificationStr += '的'; } notificationStr += '群成员信息为'; notificationStr += this.groupMemberExtra; return notificationStr; } encode() { let payload = super.encode(); let obj = { g: this.groupId, n: this.groupMemberExtra, o: this.operator, m: this.memberId }; payload.binaryContent = self$4.utf8_to_b64(JSON.stringify(obj)); return payload; } decode(payload) {