Commit 284f5a4a by panjiangyi

以来注入

parent 020bfda3
Showing with 27 additions and 47 deletions
import type { UniplatSdk } from "uniplat-sdk"
export interface Chat { export interface Chat {
chat_id: number chat_id: number
title: string title: string
...@@ -40,32 +42,17 @@ export interface ChatOption { ...@@ -40,32 +42,17 @@ export interface ChatOption {
* 长链接chat sdk地址 * 长链接chat sdk地址
*/ */
webSocketUri: string webSocketUri: string
/**
* 基础服务Api地址,开发环境可传空值 sdk:UniplatSdk
*/
serviceBaseUri: string
/**
* 通信服务Api地址,开发环境可传空值
*/
chatServiceBaseUri: string
/**
* 小站id
*/
stationId: number
orgId?: number | string
orgId: () => string | number
logger?: ChatServiceLogger logger?: ChatServiceLogger
/**
* 用户映射, key 是 eid,value 是用户名+头像地址
*/
userMapping?: { [key: string]: { name: string; avatar: string } }
/**
* 是否来源于桌面用户端
*/
webHost?: boolean
} }
export interface ChatServiceLogger { export interface ChatServiceLogger {
......
import { Module } from "vuex" import { Module } from "vuex"
import { RootStoreState } from "../../store/model" import { RootStoreState } from "@/store/model"
import { ChatMember } from "../model" import { ChatMember } from "../model"
import { ChatStore, ChatStoreState, ChatStatus, ChatMemberType } from "./model" import { ChatStore, ChatStoreState, ChatStatus, ChatMemberType } from "./model"
import xim, { ChatNotifyListener } from "../xim/xim" import xim, { ChatNotifyListener } from "../xim/xim"
import { unique } from "../utils" import { unique } from "../utils"
import Chat from "../xim" import Chat from "../xim"
import { decode } from "../utils/jwt" import { decode } from "../utils/jwt"
import Vue from "vue"
import type { UniplatSdk } from "uniplat-sdk"
import { Global } from "@/common/global"
import chatType from "../xim/chat-type" import chatType from "../xim/chat-type"
import { isAccessibleUrl } from "../service/tools" import { isAccessibleUrl } from "../service/tools"
import chat from "../xim/"
export const ns = ChatStore.ns export const ns = ChatStore.ns
const sdk = () => Vue.prototype.sdk as UniplatSdk const sdk = chat.getSdk
const global = () => Vue.prototype.global as Global
const UniplatChatModelName = "UniplatChat" const UniplatChatModelName = "UniplatChat"
const model = () => sdk().model(UniplatChatModelName) const model = () => sdk().model(UniplatChatModelName)
const orgId = () => global().org?.id ?? "0" const orgId = chat.getOrgId
const getMyinfo = (function () { const getMyinfo = (function () {
let data let data
return async () => { return async () => {
......
...@@ -3,8 +3,12 @@ import { ChatOption, TokenStringGetter } from "./../model" ...@@ -3,8 +3,12 @@ import { ChatOption, TokenStringGetter } from "./../model"
import { ChatLoggerService } from "./logger" import { ChatLoggerService } from "./logger"
import { EmojiService } from "../service/emoji" import { EmojiService } from "../service/emoji"
import tokenManager from "./token" import tokenManager from "./token"
import type { UniplatSdk } from "uniplat-sdk"
class Chat { class Chat {
private _sdk: UniplatSdk
private _orgId: () => string | number = () => "0"
private token!: TokenStringGetter private token!: TokenStringGetter
private userMapping: { [key: string]: { name: string; avatar: string } } = private userMapping: { [key: string]: { name: string; avatar: string } } =
{} {}
private webHost = false private webHost = false
...@@ -21,6 +25,8 @@ class Chat { ...@@ -21,6 +25,8 @@ class Chat {
`You must specify a web socket address for chat service` `You must specify a web socket address for chat service`
) )
} }
this._sdk = option.sdk
this._orgId = option.orgId
// if (option.enterpriseTokenString) { // if (option.enterpriseTokenString) {
// this.token = option.enterpriseTokenString // this.token = option.enterpriseTokenString
...@@ -29,15 +35,18 @@ class Chat { ...@@ -29,15 +35,18 @@ class Chat {
tokenManager.save(this.token) tokenManager.save(this.token)
// } // }
this.userMapping = option.userMapping || {}
// if (option.webHost) {
// this.webHost = option.webHost
// }
// XimService.buildInstance(new XimService(option));
EmojiService.raiseOnReady(this.token) EmojiService.raiseOnReady(this.token)
return this.initChatSdk(option.webSocketUri) return this.initChatSdk(option.webSocketUri)
} }
public getSdk = () => {
return this._sdk
}
public getOrgId = () => {
return this._orgId()
}
public isWebHost() { public isWebHost() {
return this.webHost return this.webHost
} }
...@@ -76,20 +85,7 @@ class Chat { ...@@ -76,20 +85,7 @@ class Chat {
} }
public getUserMapping() { public getUserMapping() {
return this.userMapping return {}
}
public appendUserMappingItem(eid: string, name: string, avatar: string) {
if (this.userMapping[eid]) {
if (name) {
this.userMapping[eid].name = name
}
if (avatar) {
this.userMapping[eid].avatar = avatar
}
} else {
this.userMapping[eid] = { name, avatar }
}
} }
private debug(message: string) { private debug(message: string) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment