Commit bfddd649 by Sixong.Zhu

cs

parent fdd3ea77
Showing with 21 additions and 5 deletions
...@@ -44,13 +44,25 @@ export const enum ServiceType { ...@@ -44,13 +44,25 @@ export const enum ServiceType {
Backend, Backend,
} }
export const enum ImEnvironment {
Dev = 1,
Stage,
Pro
}
export const socketMapping = new Map<ImEnvironment, string>([
[ImEnvironment.Dev, 'ws://hro.channel.jinsehuaqin.com:8080/ws'],
[ImEnvironment.Stage, ''],
[ImEnvironment.Pro, 'wss://channel.qinqinxiaobao.com/ws'],
]);
export type TokenStringGetter = () => Promise<string>; export type TokenStringGetter = () => Promise<string>;
export interface ChatOption { export interface ChatOption {
/** /**
* 长链接chat sdk地址 * IM 链接,如果使用系统配置,只需要传入环境标识即可,如果默认配置不满足,可以传入指定地址
*/ */
webSocketUri: string; connection: ImEnvironment | string;
sdk: () => UniplatSdk; sdk: () => UniplatSdk;
......
...@@ -8,6 +8,8 @@ import { ...@@ -8,6 +8,8 @@ import {
ServiceType, ServiceType,
CustomerServiceProduct, CustomerServiceProduct,
ChatMessageController, ChatMessageController,
socketMapping,
ImEnvironment,
} from "./../model"; } from "./../model";
import { ChatLoggerService } from "./logger"; import { ChatLoggerService } from "./logger";
import tokenManager from "./token"; import tokenManager from "./token";
...@@ -41,7 +43,7 @@ class Chat implements ChatMessageController { ...@@ -41,7 +43,7 @@ class Chat implements ChatMessageController {
throw new Error(`You must specify a chat option for chat service`); throw new Error(`You must specify a chat option for chat service`);
} }
if (!option.webSocketUri) { if (!option.connection) {
throw new Error( throw new Error(
`You must specify a web socket address for chat service` `You must specify a web socket address for chat service`
); );
...@@ -71,7 +73,9 @@ class Chat implements ChatMessageController { ...@@ -71,7 +73,9 @@ class Chat implements ChatMessageController {
// this.keywords = ["社保"]; // this.keywords = ["社保"];
return this.initChatSdk((this.ws = option.webSocketUri)).finally(() => { const path = socketMapping.get(option.connection as ImEnvironment) as string || option.connection as string;
return this.initChatSdk((this.ws = path)).finally(() => {
this.connected = true; this.connected = true;
for (const item of this.connectedActions) { for (const item of this.connectedActions) {
item(); item();
...@@ -193,7 +197,7 @@ class Chat implements ChatMessageController { ...@@ -193,7 +197,7 @@ class Chat implements ChatMessageController {
this.messageController && this.messageController.info(msg); this.messageController && this.messageController.info(msg);
} }
public getAvatar(){ public getAvatar() {
return this.defaultAvatar; return this.defaultAvatar;
} }
} }
......
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