zhuhao_dev #170
|
@ -1,7 +1,16 @@
|
|||
appId: com.electron.app
|
||||
productName: AIx
|
||||
directories:
|
||||
output: dist
|
||||
buildResources: build
|
||||
win:
|
||||
executableName: AIx
|
||||
icon: resources/logo2.ico
|
||||
extraFiles:
|
||||
- from: ./node_modules/im_electron_sdk/lib/
|
||||
to: ./resources
|
||||
filter:
|
||||
- '**/*'
|
||||
files:
|
||||
- '!**/.vscode/*'
|
||||
- '!src/*'
|
||||
|
@ -10,9 +19,6 @@ files:
|
|||
- '!{.env,.env.*,.npmrc,pnpm-lock.yaml}'
|
||||
asarUnpack:
|
||||
- resources/**
|
||||
win:
|
||||
executableName: AIx
|
||||
icon: resources/logo2.ico
|
||||
nsis:
|
||||
oneClick: false
|
||||
allowToChangeInstallationDirectory: true
|
||||
|
|
|
@ -13,6 +13,11 @@ asarUnpack:
|
|||
win:
|
||||
executableName: AIx
|
||||
icon: resources/logo2.ico
|
||||
extraFiles:
|
||||
- from: ./node_modules/im_electron_sdk/lib/
|
||||
to: ./resources
|
||||
filter:
|
||||
- '**/*'
|
||||
nsis:
|
||||
oneClick: false
|
||||
allowToChangeInstallationDirectory: true
|
||||
|
|
|
@ -13,6 +13,11 @@ asarUnpack:
|
|||
win:
|
||||
executableName: AIx
|
||||
icon: resources/logo2.ico
|
||||
extraFiles:
|
||||
- from: ./node_modules/im_electron_sdk/lib/
|
||||
to: ./resources
|
||||
filter:
|
||||
- '**/*'
|
||||
nsis:
|
||||
oneClick: false
|
||||
allowToChangeInstallationDirectory: true
|
||||
|
|
62
package.json
62
package.json
|
@ -64,50 +64,7 @@
|
|||
"windicss": "^3.5.6"
|
||||
},
|
||||
"build": {
|
||||
"files": [
|
||||
"src/app",
|
||||
"bundle",
|
||||
"icon"
|
||||
],
|
||||
"appId": "aix-win",
|
||||
"mac": {
|
||||
"gatekeeperAssess": false,
|
||||
"hardenedRuntime": true,
|
||||
"entitlements": "./signing/entitlements.mac.plist",
|
||||
"entitlementsInherit": "./signing/entitlements.mac.plist",
|
||||
"extendInfo": {
|
||||
"NSMicrophoneUsageDescription": "Please give us access to your microphone",
|
||||
"NSCameraUsageDescription": "Allow your conversational partners to see you in a Grape Call. You can turn off your video anytime during a call."
|
||||
},
|
||||
"icon": "./icon/im_electron_logo.png",
|
||||
"extraFiles": [
|
||||
{
|
||||
"from": "./node_modules/im_electron_sdk/lib/",
|
||||
"to": "./Resources",
|
||||
"filter": [
|
||||
"**/*"
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
"from": "./icon/",
|
||||
"to": "./Resources",
|
||||
"filter": [
|
||||
"**/*"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"win": {
|
||||
"icon": "./resources/logo.ico",
|
||||
"target": [
|
||||
{
|
||||
"target": "nsis",
|
||||
"arch": [
|
||||
"x64"
|
||||
]
|
||||
}
|
||||
],
|
||||
"extraFiles": [
|
||||
{
|
||||
"from": "./node_modules/im_electron_sdk/lib/",
|
||||
|
@ -117,25 +74,6 @@
|
|||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"linux": {
|
||||
"target": "deb",
|
||||
"extraFiles": [
|
||||
{
|
||||
"from": "./node_modules/im_electron_sdk/lib/",
|
||||
"to": "./resources",
|
||||
"filter": [
|
||||
"**/*"
|
||||
]
|
||||
},
|
||||
{
|
||||
"from": "node_modules/trtc-electron-sdk/build/Release/",
|
||||
"to": "./resources",
|
||||
"filter": [
|
||||
"**/*"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*/
|
||||
// import { ipcMain } from 'electron'
|
||||
// const TimMain = require('im_electron_sdk/dist/main')
|
||||
// import TimMain from 'im_electron_sdk/dist/main'
|
||||
import TimMain from 'im_electron_sdk/dist/main'
|
||||
// import {TIMErrCode} from 'im_electron_sdk/dist/enumbers'
|
||||
const sdkappidDef = 1600034736 // 可以去腾讯云即时通信IM控制台申请
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import { join } from 'path'
|
|||
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
|
||||
import icon from '../../resources/icon.png?asset'
|
||||
import File from './file'
|
||||
// import chat from './chat' // chat封装
|
||||
import chat from './chat' // chat封装
|
||||
// 代理 electron/remote
|
||||
// 第一步:引入remote
|
||||
import remote from '@electron/remote/main'
|
||||
|
@ -230,14 +230,14 @@ app.on('window-all-closed', () => {
|
|||
|
||||
// 监听全局事件
|
||||
function handleAll() {
|
||||
// const chatInstance = chat.initialize() // im-chat 实例
|
||||
const chatInstance = chat.initialize() // im-chat 实例
|
||||
// 新窗口创建-监听
|
||||
ipcMain.on('new-window', (e, data) => {
|
||||
const { id, type } = data
|
||||
const win = BrowserWindow.fromId(id)
|
||||
win.type = type // 绑定独立标识
|
||||
remote.enable(win.webContents) // 开启远程服务
|
||||
// chatInstance.enable(win.webContents) // 开启im-chat
|
||||
chatInstance.enable(win.webContents) // 开启im-chat
|
||||
})
|
||||
// 用于监听-状态管理变化-同步所有窗口
|
||||
ipcMain.handle('pinia-state-change', (e, storeName, jsonStr) => {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { contextBridge } from 'electron'
|
||||
import { electronAPI } from '@electron-toolkit/preload'
|
||||
// import TimRender from 'im_electron_sdk/dist/renderer' // im渲染部分实例
|
||||
import TimRender from 'im_electron_sdk/dist/renderer' // im渲染部分实例
|
||||
// Custom APIs for renderer
|
||||
const api = {
|
||||
preloadPath: __dirname, // 当前preload地址
|
||||
// getTimRender: () => new TimRender(), // im渲染部分实例
|
||||
getTimRender: () => new TimRender(), // im渲染部分实例
|
||||
}
|
||||
// Use `contextBridge` APIs to expose Electron APIs to
|
||||
// renderer only if context isolation is enabled, otherwise
|
||||
|
|
|
@ -0,0 +1,420 @@
|
|||
/**
|
||||
* @description im 事件监听
|
||||
* @author zdg
|
||||
* @date 2023-07-07
|
||||
*/
|
||||
// @ts-ignore
|
||||
const API = window?.api || {}
|
||||
const timRenderInstance = API.getTimRender()
|
||||
|
||||
// im 事件监听
|
||||
export class IMListeners {
|
||||
// 初始化监听
|
||||
static initListeners(callback) {
|
||||
/**
|
||||
* 注销消息监听事件
|
||||
*/
|
||||
timRenderInstance.TIMRemoveRecvNewMsgCallback()
|
||||
/**
|
||||
* @brief 增加接收新消息回调
|
||||
* @param cb 新消息回调函数,请参考[TIMRecvNewMsgCallback](TIMCloudCallback.h)
|
||||
* @param user_data 用户自定义数据,ImSDK只负责传回给回调函数cb,不做任何处理
|
||||
*
|
||||
* @note
|
||||
* 如果用户是登录状态,ImSDK收到新消息会通过此接口设置的回调抛出,另外需要注意,抛出的消息不一定是未读的消息,
|
||||
* 只是本地曾经没有过的消息(例如在另外一个终端已读,拉取最近联系人消息时可以获取会话最后一条消息,如果本地没有,会通过此方法抛出)。
|
||||
* 在用户登录之后,ImSDK会拉取离线消息,为了不漏掉消息通知,需要在登录之前注册新消息通知。
|
||||
*/
|
||||
timRenderInstance.TIMAddRecvNewMsgCallback({
|
||||
callback:(args)=>{
|
||||
callback({
|
||||
type: 'TIMAddRecvNewMsgCallback',
|
||||
data: JSON.parse(args[0])
|
||||
})
|
||||
},
|
||||
user_data: "test"
|
||||
})
|
||||
|
||||
|
||||
/**
|
||||
* @brief 1.3 设置消息已读回执回调
|
||||
* @param cb 消息已读回执回调,请参考[TIMMsgReadedReceiptCallback](TIMCloudCallback.h)
|
||||
* @param user_data 用户自定义数据,ImSDK只负责传回给回调函数cb,不做任何处理
|
||||
*
|
||||
* @note
|
||||
* 发送方发送消息,接收方调用接口[TIMMsgReportReaded]()上报该消息已读,发送方ImSDK会通过此接口设置的回调抛出。
|
||||
*/
|
||||
timRenderInstance.TIMSetMsgReadedReceiptCallback({
|
||||
callback:(args)=>{
|
||||
callback({
|
||||
type: 'TIMSetMsgReadedReceiptCallback',
|
||||
data: JSON.parse(args[0])
|
||||
})
|
||||
},
|
||||
user_data: "test"
|
||||
})
|
||||
|
||||
|
||||
/**
|
||||
* @brief 1.4 设置接收的消息被撤回回调
|
||||
* @param cb 消息撤回通知回调,请参考[TIMMsgRevokeCallback](TIMCloudCallback.h)
|
||||
* @param user_data 用户自定义数据,ImSDK只负责传回给回调函数cb,不做任何处理
|
||||
*
|
||||
* @note
|
||||
* 发送方发送消息,接收方收到消息。此时发送方调用接口[TIMMsgRevoke]()撤回该消息,接收方的ImSDK会通过此接口设置的回调抛出。
|
||||
*/
|
||||
timRenderInstance.TIMSetMsgRevokeCallback({
|
||||
callback:(args)=>{
|
||||
callback({
|
||||
type: 'TIMSetMsgRevokeCallback',
|
||||
data: JSON.parse(args[0])
|
||||
});
|
||||
},
|
||||
user_data: "test"
|
||||
})
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief 1.5 设置消息内元素相关文件上传进度回调
|
||||
* @param cb 文件上传进度回调,请参考[TIMMsgElemUploadProgressCallback](TIMCloudCallback.h)
|
||||
* @param user_data 用户自定义数据,ImSDK只负责传回给回调函数cb,不做任何处理
|
||||
*
|
||||
* @note
|
||||
* 设置消息元素上传进度回调。当消息内包含图片、声音、文件、视频元素时,ImSDK会上传这些文件,并触发此接口设置的回调,用户可以根据回调感知上传的进度
|
||||
*/
|
||||
timRenderInstance.TIMSetMsgElemUploadProgressCallback({
|
||||
callback:(args)=>{
|
||||
try{
|
||||
const [message, index, cur_size, total_size, user_data] = JSON.parse(args)
|
||||
callback({
|
||||
type: 'TIMSetMsgElemUploadProgressCallback',
|
||||
data: {
|
||||
message: JSON.parse(message),
|
||||
index,
|
||||
cur_size,
|
||||
total_size,
|
||||
user_data
|
||||
}
|
||||
})
|
||||
}catch(err){
|
||||
throw err;
|
||||
}
|
||||
},
|
||||
user_data: "test"
|
||||
})
|
||||
|
||||
/**
|
||||
* @brief 1.6 设置群组系统消息回调
|
||||
* @param cb 群消息回调,请参考[TIMGroupTipsEventCallback](TIMCloudCallback.h)
|
||||
* @param user_data 用户自定义数据,ImSDK只负责传回给回调函数cb,不做任何处理
|
||||
*
|
||||
* @note
|
||||
* 群组系统消息事件包括 加入群、退出群、踢出群、设置管理员、取消管理员、群资料变更、群成员资料变更。此消息是针对所有群组成员下发的
|
||||
*/
|
||||
timRenderInstance.TIMSetGroupTipsEventCallback({
|
||||
callback:(args)=>{
|
||||
callback({
|
||||
type: 'TIMSetGroupTipsEventCallback',
|
||||
data: JSON.parse(args[0])
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
/**
|
||||
* @brief 1.7 设置群组属性变更回调
|
||||
* @param cb 群组属性变更回调,请参考[TIMGroupAttributeChangedCallback](TIMCloudCallback.h)
|
||||
* @param user_data 用户自定义数据,ImSDK只负责传回给回调函数cb,不做任何处理
|
||||
*
|
||||
* @note
|
||||
* 某个已加入的群的属性被修改了,会返回所在群组的所有属性(该群所有的成员都能收到)
|
||||
*/
|
||||
timRenderInstance.TIMSetGroupAttributeChangedCallback({
|
||||
callback: (...args) => {callback({ type: 'TIMSetGroupAttributeChangedCallback', data: args })},
|
||||
userData: ""
|
||||
})
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief 1.8 设置会话事件回调
|
||||
* @param cb 会话事件回调,请参考[TIMConvEventCallback](TIMCloudCallback.h)
|
||||
* @param user_data 用户自定义数据,ImSDK只负责传回给回调函数cb,不做任何处理
|
||||
*
|
||||
* @note
|
||||
* > 会话事件包括:
|
||||
* >> 会话新增
|
||||
* >> 会话删除
|
||||
* >> 会话更新。
|
||||
* >> 会话开始
|
||||
* >> 会话结束
|
||||
* > 任何产生一个新会话的操作都会触发会话新增事件,例如调用接口[TIMConvCreate]()创建会话,接收到未知会话的第一条消息等。
|
||||
* 任何已有会话变化的操作都会触发会话更新事件,例如收到会话新消息,消息撤回,已读上报等。
|
||||
* 调用接口[TIMConvDelete]()删除会话成功时会触发会话删除事件。
|
||||
*/
|
||||
timRenderInstance.TIMSetConvEventCallback({
|
||||
callback:(args)=>{
|
||||
callback({
|
||||
type: 'TIMSetConvEventCallback',
|
||||
data: {
|
||||
type:args[0],
|
||||
data:args[1]!=="" ? JSON.parse(args[1]) : []
|
||||
}
|
||||
})
|
||||
},
|
||||
user_data:"TIMSetConvEventCallback"
|
||||
})
|
||||
|
||||
/**
|
||||
* @brief 1.9 设置会话未读消息总数变更的回调
|
||||
* @param cb 会话未读消息总数变更的回调,请参考[TIMConvTotalUnreadMessageCountChangedCallback](TIMCloudCallback.h)
|
||||
* @param user_data 用户自定义数据,ImSDK只负责传回给回调函数cb,不做任何处理
|
||||
*
|
||||
*/
|
||||
timRenderInstance.TIMSetConvTotalUnreadMessageCountChangedCallback({
|
||||
callback:(args)=>{
|
||||
callback({
|
||||
type: 'TIMSetConvTotalUnreadMessageCountChangedCallback',
|
||||
data: args[0]
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
/**
|
||||
* @brief 1.10 设置网络连接状态监听回调
|
||||
* @param cb 连接事件回调,请参考[TIMNetworkStatusListenerCallback](TIMCloudCallback.h)
|
||||
* @param user_data 用户自定义数据,ImSDK只负责传回给回调函数cb,不做任何处理
|
||||
*
|
||||
* @note
|
||||
* > 当调用接口 [TIMInit]() 时,ImSDK会去连接云后台。此接口设置的回调用于监听网络连接的状态。
|
||||
* > 网络连接状态包含四个:正在连接、连接失败、连接成功、已连接。这里的网络事件不表示用户本地网络状态,仅指明ImSDK是否与即时通信IM云Server连接状态。
|
||||
* > 可选设置,如果要用户感知是否已经连接服务器,需要设置此回调,用于通知调用者跟通讯后台链接的连接和断开事件,另外,如果断开网络,等网络恢复后会自动重连,自动拉取消息通知用户,用户无需关心网络状态,仅作通知之用
|
||||
* > 只要用户处于登录状态,ImSDK内部会进行断网重连,用户无需关心。
|
||||
*/
|
||||
timRenderInstance.TIMSetNetworkStatusListenerCallback({
|
||||
callback: (...args) => {callback({ type: 'TIMSetNetworkStatusListenerCallback', data: args })},
|
||||
userData: ""
|
||||
})
|
||||
|
||||
/**
|
||||
* @brief 1.11 设置被踢下线通知回调
|
||||
* @param cb 踢下线回调,请参考[TIMKickedOfflineCallback](TIMCloudCallback.h)
|
||||
* @param user_data 用户自定义数据,ImSDK只负责传回给回调函数cb,不做任何处理
|
||||
*
|
||||
* @note
|
||||
* > 用户如果在其他终端登录,会被踢下线,这时会收到用户被踢下线的通知,出现这种情况常规的做法是提示用户进行操作(退出,或者再次把对方踢下线)。
|
||||
* > 用户如果在离线状态下被踢,下次登录将会失败,可以给用户一个非常强的提醒(登录错误码ERR_IMSDK_KICKED_BY_OTHERS:6208),开发者也可以选择忽略这次错误,再次登录即可。
|
||||
* > 用户在线情况下的互踢情况:
|
||||
* + 用户在设备1登录,保持在线状态下,该用户又在设备2登录,这时用户会在设备1上强制下线,收到 TIMKickedOfflineCallback 回调。
|
||||
* 用户在设备1上收到回调后,提示用户,可继续调用login上线,强制设备2下线。这里是在线情况下互踢过程。
|
||||
* > 用户离线状态互踢:
|
||||
* + 用户在设备1登录,没有进行logout情况下进程退出。该用户在设备2登录,此时由于用户不在线,无法感知此事件,
|
||||
* 为了显式提醒用户,避免无感知的互踢,用户在设备1重新登录时,会返回(ERR_IMSDK_KICKED_BY_OTHERS:6208)错误码,表明之前被踢,是否需要把对方踢下线。
|
||||
* 如果需要,则再次调用login强制上线,设备2的登录的实例将会收到 TIMKickedOfflineCallback 回调。
|
||||
*/
|
||||
timRenderInstance.TIMSetKickedOfflineCallback({
|
||||
callback: (...args) => {
|
||||
callback({
|
||||
type: 'TIMSetKickedOfflineCallback',
|
||||
data: args
|
||||
});
|
||||
},
|
||||
userData: ""
|
||||
})
|
||||
|
||||
|
||||
/**
|
||||
* @brief 1.12 设置票据过期回调
|
||||
* @param cb 票据过期回调,请参考[TIMUserSigExpiredCallback](TIMCloudCallback.h)
|
||||
* @param user_data 用户自定义数据,ImSDK只负责传回给回调函数cb,不做任何处理
|
||||
*
|
||||
* @note
|
||||
* 用户票据,可能会存在过期的情况,如果用户票据过期,此接口设置的回调会调用。
|
||||
* [TIMLogin]()也将会返回70001错误码。开发者可根据错误码或者票据过期回调进行票据更换
|
||||
*/
|
||||
timRenderInstance.TIMSetUserSigExpiredCallback({
|
||||
callback: (...args) => {callback({ type: 'TIMSetUserSigExpiredCallback', data: args })},
|
||||
userData: ""
|
||||
})
|
||||
|
||||
|
||||
/**
|
||||
* @brief 1.13 设置添加好友的回调
|
||||
* @param cb 添加好友回调,请参考[TIMOnAddFriendCallback](TIMCloudCallback.h)
|
||||
* @param user_data 用户自定义数据,ImSDK只负责传回给回调函数cb,不做任何处理
|
||||
*
|
||||
* @note
|
||||
* 此回调为了多终端同步。例如A设备、B设备都登录了同一帐号的ImSDK,A设备添加了好友,B设备ImSDK会收到添加好友的推送,ImSDK通过此回调告知开发者。
|
||||
*/
|
||||
timRenderInstance.TIMSetOnAddFriendCallback({
|
||||
callback: (...args) => {
|
||||
console.log('=====添加好友=====', args)
|
||||
callback({ type: 'TIMSetOnAddFriendCallback', data: args })
|
||||
},
|
||||
userData: ""
|
||||
})
|
||||
|
||||
|
||||
/**
|
||||
* @brief 1.14 设置删除好友的回调
|
||||
* @param cb 删除好友回调,请参考[TIMOnDeleteFriendCallback](TIMCloudCallback.h)
|
||||
* @param user_data 用户自定义数据,ImSDK只负责传回给回调函数cb,不做任何处理
|
||||
*
|
||||
* @note
|
||||
* 此回调为了多终端同步。例如A设备、B设备都登录了同一帐号的ImSDK,A设备删除了好友,B设备ImSDK会收到删除好友的推送,ImSDK通过此回调告知开发者。
|
||||
*/
|
||||
timRenderInstance.TIMSetOnDeleteFriendCallback({
|
||||
callback: (...args) => {callback({ type: 'TIMSetOnDeleteFriendCallback', data: args })},
|
||||
userData: ""
|
||||
})
|
||||
|
||||
/**
|
||||
* @brief 1.15 设置更新好友资料的回调
|
||||
* @param cb 更新好友资料回调,请参考[TIMUpdateFriendProfileCallback](TIMCloudCallback.h)
|
||||
* @param user_data 用户自定义数据,ImSDK只负责传回给回调函数cb,不做任何处理
|
||||
*
|
||||
* @note
|
||||
* 此回调为了多终端同步。例如A设备、B设备都登录了同一帐号的ImSDK,A设备更新了好友资料,B设备ImSDK会收到更新好友资料的推送,ImSDK通过此回调告知开发者。
|
||||
*/
|
||||
timRenderInstance.TIMSetUpdateFriendProfileCallback({
|
||||
callback: (...args) => {callback({ type: 'TIMSetUpdateFriendProfileCallback', data: args })},
|
||||
userData: ""
|
||||
})
|
||||
|
||||
|
||||
/**
|
||||
* @brief 1.16 设置好友添加请求的回调
|
||||
* @param cb 好友添加请求回调,请参考[TIMFriendAddRequestCallback](TIMCloudCallback.h)
|
||||
* @param user_data 用户自定义数据,ImSDK只负责传回给回调函数cb,不做任何处理
|
||||
*
|
||||
* @note
|
||||
* 当前登入用户设置添加好友需要确认时,如果有用户请求加当前登入用户为好友,会收到好友添加请求的回调,ImSDK通过此回调告知开发者。如果多终端登入同一帐号,每个终端都会收到这个回调。
|
||||
*/
|
||||
timRenderInstance.TIMSetFriendAddRequestCallback({
|
||||
callback: (...args) => {
|
||||
console.log('=====添加好友请求=====', JSON.parse(args[0][0]));
|
||||
callback({
|
||||
type: 'TIMSetFriendAddRequestCallback',
|
||||
data: JSON.parse(args[0][0])
|
||||
})
|
||||
},
|
||||
userData: ""
|
||||
})
|
||||
|
||||
|
||||
/**
|
||||
* @brief 1.17 设置好友申请删除的回调
|
||||
* @param cb 好友申请删除回调,请参考[TIMFriendApplicationListDeletedCallback](TIMCloudCallback.h)
|
||||
* @param user_data 用户自定义数据,ImSDK只负责传回给回调函数cb,不做任何处理
|
||||
*
|
||||
* @note
|
||||
* 1. 主动删除好友申请
|
||||
* 2. 拒绝好友申请
|
||||
* 3. 同意好友申请
|
||||
* 4. 申请加别人好友被拒绝
|
||||
*/
|
||||
timRenderInstance.TIMSetFriendApplicationListDeletedCallback({
|
||||
callback: (...args) => {callback({ type: 'TIMSetFriendApplicationListDeletedCallback', data: args })},
|
||||
userData: ""
|
||||
})
|
||||
|
||||
/**
|
||||
* @brief 1.18 设置好友申请已读的回调
|
||||
* @param cb 好友申请已读回调,请参考[TIMFriendApplicationListReadCallback](TIMCloudCallback.h)
|
||||
* @param user_data 用户自定义数据,ImSDK只负责传回给回调函数cb,不做任何处理
|
||||
*
|
||||
* @note
|
||||
* 如果调用 setFriendApplicationRead 设置好友申请列表已读,会收到这个回调(主要用于多端同步)
|
||||
*/
|
||||
|
||||
timRenderInstance.TIMSetFriendApplicationListReadCallback({
|
||||
callback: (...args) => {callback({ type: 'TIMSetFriendApplicationListReadCallback', data: args })},
|
||||
userData: ""
|
||||
})
|
||||
|
||||
|
||||
/**
|
||||
* @brief 1.19 设置黑名单新增的回调
|
||||
* @param cb 黑名单新增的回调,请参考[TIMFriendBlackListAddedCallback](TIMCloudCallback.h)
|
||||
* @param user_data 用户自定义数据,ImSDK只负责传回给回调函数cb,不做任何处理
|
||||
*
|
||||
*/
|
||||
timRenderInstance.TIMSetFriendBlackListAddedCallback({
|
||||
callback: (...args) => {callback({ type: 'TIMSetFriendBlackListAddedCallback', data: args })},
|
||||
userData: ""
|
||||
})
|
||||
|
||||
/**
|
||||
* @brief 1.20 设置黑名单删除的回调
|
||||
* @param cb 黑名单删除的回调,请参考[TIMFriendBlackListDeletedCallback](TIMCloudCallback.h)
|
||||
* @param user_data 用户自定义数据,ImSDK只负责传回给回调函数cb,不做任何处理
|
||||
*
|
||||
*/
|
||||
timRenderInstance.TIMSetFriendBlackListDeletedCallback({
|
||||
callback: (...args) => {callback({ type: 'TIMSetFriendBlackListDeletedCallback', data: args })},
|
||||
userData: ""
|
||||
})
|
||||
|
||||
|
||||
/**
|
||||
* @brief 1.22 设置消息在云端被修改后回传回来的消息更新通知回调
|
||||
* @param cb 消息更新回调,请参考[TIMMsgUpdateCallback](TIMCloudCallback.h)
|
||||
* @param user_data 用户自定义数据,ImSDK只负责传回给回调函数cb,不做任何处理
|
||||
*
|
||||
* @note
|
||||
* > 当您发送的消息在服务端被修改后,ImSDK会通过该回调通知给您
|
||||
* > 您可以在您自己的服务器上拦截所有即时通信IM消息 [发单聊消息之前回调](https://cloud.tencent.com/document/product/269/1632)
|
||||
* > 设置成功之后,即时通信IM服务器会将您的用户发送的每条消息都同步地通知给您的业务服务器。
|
||||
* > 您的业务服务器可以对该条消息进行修改(例如过滤敏感词),如果您的服务器对消息进行了修改,ImSDK就会通过此回调通知您。
|
||||
*/
|
||||
timRenderInstance.TIMSetMsgUpdateCallback({
|
||||
callback: (...args) => {callback({ type: 'TIMSetMsgUpdateCallback', data: args })},
|
||||
userData: ""
|
||||
})
|
||||
timRenderInstance.TIMOnInvited({
|
||||
callback:(data)=>{
|
||||
callback({
|
||||
type: 'TIMOnInvited',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
})
|
||||
timRenderInstance.TIMOnRejected({
|
||||
callback:(data)=>{
|
||||
callback({
|
||||
type: 'TIMOnRejected',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
})
|
||||
timRenderInstance.TIMOnAccepted({
|
||||
callback:(data)=>{
|
||||
callback({
|
||||
type: 'TIMOnAccepted',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
})
|
||||
timRenderInstance.TIMOnCancelled({
|
||||
callback:(data)=>{
|
||||
callback({
|
||||
type: 'TIMOnCancelled',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
timRenderInstance.TIMOnTimeout({
|
||||
callback:(data)=>{
|
||||
callback({
|
||||
type: 'TIMOnTimeout',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export default { timRenderInstance, initListeners: IMListeners.initListeners }
|
|
@ -8,6 +8,7 @@
|
|||
// const TimRender = require('im_electron_sdk/dist/render')
|
||||
import * as TYPES from './enumbers' // sdk相关枚举
|
||||
import MsgEnum from './msgEnum' // 消息相关枚举(自定义)
|
||||
import IMListeners from './imLiseners' // im消息-监听器
|
||||
const API = window.api
|
||||
// TIM生成签名
|
||||
// import * as GenerateUserSig from './userSig' // 引入签名生成器
|
||||
|
@ -73,14 +74,18 @@ export class ImChat {
|
|||
return new Promise(async(resolve, reject) => {
|
||||
try {
|
||||
if(!API) reject('preload api获取失败, 初始化-未完成')
|
||||
this.timChat = await API.getTimRender()
|
||||
await this.timChat.TIMInit({
|
||||
// electron_log:true,
|
||||
})
|
||||
console.log('[im-chat]:初始化成功')
|
||||
// this.timChat = await API.getTimRender()
|
||||
this.timChat = IMListeners.timRenderInstance
|
||||
const code = await this.timChat.TIMInit()
|
||||
if (code == 0) { // 初始化成功
|
||||
this.setConsole('%cim-chat: init', '初始化成功')
|
||||
this.status.isConnect = true
|
||||
this.setConfig() // 设置日志级别
|
||||
resolve(this)
|
||||
} else { // 失败:具体请看code
|
||||
console.error('[im-chat]:初始化失败', code)
|
||||
reject(code)
|
||||
}
|
||||
} catch (error) {reject(error)}
|
||||
})
|
||||
}
|
||||
|
@ -96,21 +101,27 @@ export class ImChat {
|
|||
}
|
||||
// 监听
|
||||
watch(callback) {
|
||||
// 先移除监听
|
||||
this.timChat.TIMRemoveRecvNewMsgCallback()
|
||||
// 消息监听
|
||||
this.timChat.TIMAddRecvNewMsgCallback({
|
||||
callback, user_data: this.toStr('msg')
|
||||
})
|
||||
// 群消息监听
|
||||
// 群组系统消息事件包括 加入群、退出群、踢出群、设置管理员、取消管理员、群资料变更、群成员资料变更。此消息是针对所有群组成员下发的
|
||||
this.timChat.TIMSetGroupTipsEventCallback({
|
||||
// callback, user_data: this.toStr('msg-group')
|
||||
callback: (data) => {
|
||||
// console.log('群消息', group_tips_event)
|
||||
this.setConsole('%c群消息', data)
|
||||
},
|
||||
})
|
||||
// // 先移除监听
|
||||
// this.timChat.TIMRemoveRecvNewMsgCallback()
|
||||
// // 消息监听
|
||||
// this.timChat.TIMAddRecvNewMsgCallback({
|
||||
// callback, user_data: this.toStr('msg')
|
||||
// })
|
||||
// // 群消息监听
|
||||
// // 群组系统消息事件包括 加入群、退出群、踢出群、设置管理员、取消管理员、群资料变更、群成员资料变更。此消息是针对所有群组成员下发的
|
||||
// this.timChat.TIMSetGroupTipsEventCallback({
|
||||
// // callback, user_data: this.toStr('msg-group')
|
||||
// callback: (data) => {
|
||||
// // console.log('群消息', group_tips_event)
|
||||
// this.setConsole('%c群消息', data)
|
||||
// },
|
||||
// })
|
||||
if (this.timChat && this.status.isConnect) { // 连接成功允许监听
|
||||
this.setConsole('%cim-chat: watch', '监听成功')
|
||||
IMListeners.initListeners(callback)
|
||||
} else {
|
||||
this.setConsole('%cim-chat: watch', '监听失败, 未连接')
|
||||
}
|
||||
}
|
||||
// 登录
|
||||
login() {
|
||||
|
@ -127,18 +138,19 @@ export class ImChat {
|
|||
const res = await this.timChat.TIMLogin(option)
|
||||
if (res && res.code == 0) {
|
||||
// console.log('登录成功', res)
|
||||
this.setConsole('%cim-chat: login', '登录成功')
|
||||
this.status.isLogin = true
|
||||
resolve({status:0, msg:'登录成功', data:res})
|
||||
} else reject(res)
|
||||
} else {
|
||||
if (status == 1) { // 已登录
|
||||
console.log('已登录')
|
||||
this.setConsole('%cim-chat: login', '已登录')
|
||||
resolve({status, msg:'已登录'})
|
||||
} else if (status == 2) { // 登录中
|
||||
console.log('登录中')
|
||||
this.setConsole('%cim-chat: login', '登录中')
|
||||
resolve({status, msg:'登录中'})
|
||||
} else if (status == 4) { // 登出中
|
||||
console.log('登出中')
|
||||
this.setConsole('%cim-chat: login', '登出中')
|
||||
resolve({status, msg:'登出中'})
|
||||
}
|
||||
}
|
||||
|
@ -189,9 +201,10 @@ export class ImChat {
|
|||
// @TGS#3XVNI6ZOG
|
||||
return this.timChat.TIMGroupCreate(option).then(res => {
|
||||
if (res && res.code == 0) {
|
||||
this.setConsole('%c创建群组成功', res)
|
||||
const timGroupId = res?.json_param?.create_group_result_groupid
|
||||
if (!!timGroupId && timGroupId != 'undefined'){
|
||||
this.setConsole('%c创建群组成功', timGroupId)
|
||||
// this.setConsole('%c创建群组成功', timGroupId)
|
||||
this.timGroupId = timGroupId
|
||||
// this.setGroupMsgReceive()
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,44 +0,0 @@
|
|||
/**
|
||||
* @description: 生成签名|客户端计算 UserSig
|
||||
* @author: zdg
|
||||
* @date 2021-07-05 14:07:01
|
||||
*/
|
||||
|
||||
// TIM生成签名
|
||||
import LibGenerateTestUserSig from './lib-generate-test-usersig-es.min.js';
|
||||
/**
|
||||
* Signature expiration time, which should not be too short
|
||||
* Time unit: second
|
||||
* Default time: 7 * 24 * 60 * 60 = 604800 = 7days
|
||||
*/
|
||||
const EXPIRETIME = 604800;
|
||||
|
||||
/**
|
||||
* Module: GenerateTestUserSig
|
||||
*
|
||||
* Description: Generates UserSig for testing. UserSig is a security signature designed by Tencent Cloud for its cloud services.
|
||||
* It is calculated based on `SDKAppID`, `UserID`, and `EXPIRETIME` using the HMAC-SHA256 encryption algorithm.
|
||||
*
|
||||
* Attention: For the following reasons, do not use the code below in your commercial application.
|
||||
*
|
||||
* The code may be able to calculate UserSig correctly, but it is only for quick testing of the SDK’s basic features, not for commercial applications.
|
||||
* `SECRETKEY` in client code can be easily decompiled and reversed, especially on web.
|
||||
* Once your key is disclosed, attackers will be able to steal your Tencent Cloud traffic.
|
||||
*
|
||||
* The correct method is to deploy the `UserSig` calculation code and encryption key on your project server so that your application can request from your server a `UserSig` that is calculated whenever one is needed.
|
||||
* Given that it is more difficult to hack a server than a client application, server-end calculation can better protect your key.
|
||||
*
|
||||
* Reference: https://cloud.tencent.com/document/product/647/17275#Server
|
||||
*/
|
||||
|
||||
function genTestUserSig(options) {
|
||||
const { SDKAppID, secretKey, userID } = options;
|
||||
const generator = new LibGenerateTestUserSig(SDKAppID, secretKey, EXPIRETIME);
|
||||
const userSig = generator.genTestUserSig(userID);
|
||||
return {
|
||||
SDKAppID,
|
||||
userSig,
|
||||
};
|
||||
}
|
||||
|
||||
export { genTestUserSig, EXPIRETIME };
|
|
@ -36,13 +36,15 @@ export function shareStorePlugin({store}) {
|
|||
// 同步数据-发送给主线程-单独
|
||||
function stateSync(storeName, key, value) {
|
||||
// console.log('state-change', storeName, key, value)
|
||||
try {
|
||||
let jsonStr = ''
|
||||
let obj = {[key]:value}
|
||||
window.test = obj
|
||||
if (typeof key === 'string') jsonStr = JSON.stringify(obj)
|
||||
if (typeof key === 'string') jsonStr = JSON.stringify({[key]:value})
|
||||
else if (typeof value === 'object') jsonStr = JSON.stringify(key)
|
||||
// 通知主线程更新
|
||||
ipcRenderer?.invoke('pinia-state-change', storeName, jsonStr)
|
||||
} catch (error) {
|
||||
console.log('state-change-error', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 同步数据-发送给主线程-全量更新
|
||||
|
|
|
@ -110,7 +110,7 @@ export const createWindow = async (type, data) => {
|
|||
wins_tool.setIgnoreMouseEvents(true, {forward: true}) // 忽略鼠标事件但是事件继续传递给窗口
|
||||
wins_tool.setAlwaysOnTop(true,'screen-saver') // 将窗口设置为顶层窗口
|
||||
wins_tool.setVisibleOnAllWorkspaces(true) // 如果窗口在所有工作区都可见
|
||||
// win.webContents.openDevTools() // 打开调试工具
|
||||
// wins_tool.webContents.openDevTools() // 打开调试工具
|
||||
eventHandles(type, wins_tool) // 事件监听处理
|
||||
return wins_tool
|
||||
}
|
||||
|
@ -190,7 +190,11 @@ export function toolWindow({url, isConsole, isWeb=true, option={}}) {
|
|||
// 内部监听器-是否打印
|
||||
if (!!isConsole) {
|
||||
win.webContents.on('console-message', (e,leve,m,lin,s) => {
|
||||
console.log(`[${win.type}]`,m)
|
||||
console.log(m)
|
||||
if(m.startsWith('%c')){ // 特殊打印
|
||||
const arr = m.match(/(%c[^ ]+)(?:\s+(.*;))(.*)/)
|
||||
console.log(arr[1],arr[2],arr[3])
|
||||
} else console.log(`[${win.type}]`,m)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
@ -248,12 +252,12 @@ const eventHandles = (type, win) => {
|
|||
}
|
||||
}
|
||||
|
||||
const taskHandles = () => {
|
||||
// const taskHandles = () => {
|
||||
// // 设置任务栏上下文菜单
|
||||
// const contextMenu = new Remote.Menu()
|
||||
// contextMenu.append(new Remote.MenuItem({
|
||||
// label: '关闭',
|
||||
// click: () => {Remote.app.quit()}
|
||||
// }))
|
||||
}
|
||||
// }
|
||||
|
||||
|
|
|
@ -13,10 +13,10 @@ const props = defineProps({
|
|||
const imChatObj = reactive({imChat:null})
|
||||
onMounted(() => {
|
||||
// console.log(imChatObj)
|
||||
initImChat()
|
||||
// initImChat()
|
||||
})
|
||||
// 初始化 im-chat
|
||||
const initImChat = async () => {
|
||||
const initImChat = async (timGroupId) => {
|
||||
// console.log('im-chat', userStore.user.timuserid)
|
||||
try {
|
||||
const { timuserid, deptId, userId } = userStore.user
|
||||
|
@ -35,25 +35,55 @@ const initImChat = async () => {
|
|||
await imChatObj.imChat.login()
|
||||
// 监听 im-chat 消息
|
||||
imChatObj.imChat.watch((res) => {
|
||||
const [msg] = res[0]?JSON.parse(res[0]):[]
|
||||
imChatObj.imChat.setConsole('%cchat-msg', msg)
|
||||
// 系统消息
|
||||
if(msg.message_sender == '@TIM#SYSTEM'){
|
||||
emits('change', 'msg-system', null, msg)
|
||||
} else { // 普通消息-数据处理
|
||||
(msg?.message_elem_array||[]).forEach(o => {
|
||||
const msgData = !!o.text_elem_content ? JSON.parse(o.text_elem_content)||'' : ''
|
||||
emits('change', 'msg', msgData, msg)
|
||||
})
|
||||
}
|
||||
imChatObj.imChat.setConsole('%cchat-msg', res)
|
||||
msgHandle(res) // 消息处理
|
||||
})
|
||||
// 创建群
|
||||
if (props.isGroup) await createGroup(groupName)
|
||||
if (!timGroupId||props.isGroup) { // 创建群
|
||||
await createGroup(groupName)
|
||||
} else { // 已有群-设置群id
|
||||
imChatObj.imChat.timGroupId = timGroupId
|
||||
}
|
||||
return imChatObj.imChat
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('im-error: ', error)
|
||||
}
|
||||
}
|
||||
// 消息处理
|
||||
const msgHandle = (msg) => {
|
||||
const { type, data } = msg
|
||||
switch(type) {
|
||||
case 'TIMAddRecvNewMsgCallback': // 收到新消息 data=[]
|
||||
{
|
||||
(data||[]).forEach(o => {
|
||||
const msgArr = o?.message_elem_array||[]
|
||||
msgArr.forEach(info => {
|
||||
const msgType = info?.elem_type // 消息类型 TIMElemType
|
||||
const msgData = !!info.text_elem_content ? JSON.parse(info.text_elem_content)||'' : ''
|
||||
emits('change', 'msg', msgData, o, type, msgType)
|
||||
})
|
||||
})
|
||||
}
|
||||
break
|
||||
case 'TIMSetConvEventCallback': // 监听会话事件 data = {data,type}
|
||||
{
|
||||
const convArr = data.data || []
|
||||
convArr.forEach(o => {
|
||||
const msgArr = o?.conv_last_msg?.message_elem_array||[]
|
||||
msgArr.forEach(info => {
|
||||
const msgType = info?.elem_type // 消息类型 TIMElemType
|
||||
const msgData = !!info.text_elem_content ? JSON.parse(info.text_elem_content)||'' : ''
|
||||
emits('change', 'msg', msgData, o?.conv_last_msg, type, msgType)
|
||||
})
|
||||
})
|
||||
}
|
||||
emits('change', 'msg-conv', msg)
|
||||
break
|
||||
}
|
||||
// 未处理的消息
|
||||
emits('change', 'msgDef', msg)
|
||||
}
|
||||
// 创建群组
|
||||
const createGroup = async (groupName) => {
|
||||
if (!imChatObj.imChat) return
|
||||
|
@ -65,7 +95,7 @@ const logout = () => imChatObj.imChat?.logout()
|
|||
// 解散群
|
||||
const deleteGroup = () => imChatObj.imChat?.deleteGroup()
|
||||
|
||||
defineExpose({ logout, deleteGroup, imChatObj })
|
||||
defineExpose({ initImChat, logout, deleteGroup, imChatObj })
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<upvote-vue ref="upvoteRef"></upvote-vue>
|
||||
|
||||
<!-- im-chat 聊天组件 -->
|
||||
<!-- <im-chat ref="imChatRef" @change="chatChange" /> -->
|
||||
<im-chat ref="imChatRef" @change="chatChange" />
|
||||
|
||||
<!-- 底部工具栏 -->
|
||||
<div class="tool-bottom-all" @mouseenter="mouseChange(0)" @mouseleave="mouseChange(1)">
|
||||
|
@ -66,6 +66,7 @@ const classObj = reactive({ // 课程相关
|
|||
id: route.query.reservId, // 课程id
|
||||
data: {} // 课程信息
|
||||
})
|
||||
const msgIds = [] // 消息id
|
||||
const btnList = [ // 工具栏按钮列表
|
||||
{ label: '选择', value: 'select', icon: 'icon-mouse' },
|
||||
{ label: '画笔', value: 'brush', icon: 'icon-huabi' },
|
||||
|
@ -77,9 +78,9 @@ const btnList = [ // 工具栏按钮列表
|
|||
]
|
||||
// === 页面加载完毕 ===
|
||||
onMounted(async() => {
|
||||
getClassInfo() // 获取课堂详情 ex3
|
||||
setTimeout(() => {
|
||||
classManageApi.startClass(classObj.id) // 开始上课-临时
|
||||
// getClassInfo() // 获取课堂详情 ex3
|
||||
// classManageApi.startClass(classObj.id) // 开始上课-临时
|
||||
resetStatus() // 开启重置状态-监听
|
||||
}, 200);
|
||||
})
|
||||
|
@ -89,16 +90,12 @@ onMounted(async() => {
|
|||
const getClassInfo = async () => {
|
||||
const { data } = await classManageApi.getClassInfo(classObj.id)
|
||||
classObj.data = data
|
||||
// console.log('classObj:', classObj)
|
||||
if(!data.ex3 || data.ex3 == 'undefined') { // 无群直接创建
|
||||
await imChatRef.value.imChatObj.imChat.createGroup(data.className)
|
||||
const timGroupId = imChatRef.value.imChatObj.imChat.timGroupId
|
||||
// 群id
|
||||
let timGroupId = data?.ex3 && data?.ex3 != 'undefined' ? data.ex3: ''
|
||||
console.log('timGroupId:', timGroupId)
|
||||
const chat = await imChatRef.value?.initImChat(timGroupId) // 初始化im-chat
|
||||
if (!timGroupId) timGroupId = chat.timGroupId
|
||||
classManageApi.startClass(classObj.id, timGroupId) // 开始上课
|
||||
} else { // 已创建群
|
||||
console.log('已创建群: ', data.ex3)
|
||||
imChatRef.value.imChatObj.imChat.timGroupId = data.ex3
|
||||
// imChatRef.value.imChatObj.imChat.setGroupMsgReceive(data.ex3)
|
||||
}
|
||||
}
|
||||
// 切换tab-change
|
||||
const tabChange = (val) => {
|
||||
|
@ -121,17 +118,21 @@ const mouseChange = (bool) => {
|
|||
setIgnore(resBool)
|
||||
}
|
||||
// im-chat: 聊天事件 {type, data}
|
||||
const chatChange = (type, data) => {
|
||||
const chatChange = (type, data, ...args) => {
|
||||
if (type == 'createGroup') { // 创建群-监听
|
||||
console.log('创建群:', data)
|
||||
!!data && classManageApi.startClass(classObj.id, data)
|
||||
} else if (type == 'msg') { // im-chat 消息监听
|
||||
if (!data) return // 没有msg数据
|
||||
if (!data) return // 没有msg数据 message_msg_id
|
||||
const msgId = (args||[])[0].message_msg_id
|
||||
const { msgKey:head, msgcontent:msg, senduserid:sendId, msgType } = data
|
||||
switch(head) {
|
||||
case MsgEnum.HEADS.MSG_0001:
|
||||
// console.log('点赞:', data)
|
||||
if(msgIds.includes(msgId)) return
|
||||
upvoteRef.value.trigger()
|
||||
if (msgIds.length >= 100) msgIds.shift() // 删除第一个
|
||||
msgIds.push(msgId) // 添加到数组
|
||||
break
|
||||
default:
|
||||
console.log('未知消息:', data)
|
||||
|
@ -188,11 +189,11 @@ const sideChange = async o => {
|
|||
setTimeout(async() => {
|
||||
// elMsg.close()
|
||||
toolStore.isToolWin = false
|
||||
await classManageApi.endClass(route.query.reservId)
|
||||
await imChatRef.value?.deleteGroup() // 解散群
|
||||
await imChatRef.value?.logout() // 退出im
|
||||
await classManageApi.endClass(route.query.reservId)
|
||||
ipcMsgSend('tool-sphere:close') // 关闭窗口
|
||||
}, 200);
|
||||
}, 500);
|
||||
|
||||
// isOver.value = false
|
||||
// setIgnore(true) // 开启窗口鼠标-穿透
|
||||
|
|
Loading…
Reference in New Issue