This commit is contained in:
2023-12-02 18:44:35 +08:00
parent 460ede57d2
commit 3688c421dc
16 changed files with 251 additions and 128 deletions

View File

@@ -102,32 +102,46 @@ export class ImClient {
this.userSign = userSign
this.imeiLength = self.imeiLength;
if (Beans.isEmpty(this.url)) {
log.info("获取im地址")
let api = new HttpApi(this.httpUrl);
let resp = await api.call("/user/login", {}, { clientType: this.clientType, appId: this.appId, userId: this.userId })
// console.log(resp)
if (resp.isFailed()) {
log.info("登录失败获取im地址失败")
return;
}
let ip = resp.data.ip;
let port = resp.data.port;
console.log("获取im地址")
try {
let api = new HttpApi(this.httpUrl);
let resp = await api.call("/user/login", {}, { clientType: this.clientType, appId: this.appId, userId: this.userId })
// console.log(resp)
if (resp.isFailed()) {
console.error("登录失败获取im地址失败")
console.log("登录失败获取im地址失败")
if (typeof imClient.listeners.onSocketErrorEvent === 'function') {
imClient.listeners.onSocketErrorEvent("登录失败获取im地址失败");
}
return;
}
let ip = resp.data.ip;
let port = resp.data.port;
var protocolStr = document.location.protocol;
if(protocolStr == "http:")
{
this.url = "ws://" + ip + ":" + port + "/ws";
var protocolStr = document.location.protocol;
if(protocolStr == "http:")
{
this.url = "ws://" + ip + ":" + port + "/ws";
}
else if(protocolStr == "https:")
{
this.url = "wss://" + ip + "/hs_ws";
}
} catch (e) {
console.error("获取im地址 捕获到异常")
console.error(e)
if (typeof imClient.listeners.onSocketErrorEvent === 'function') {
imClient.listeners.onSocketErrorEvent("登录失败获取im地址失败");
}
}
else if(protocolStr == "https:")
{
this.url = "wss://" + ip + "/hs_ws";
}
}
var req = new LoginPack(self.appId, self.userId, 1);
let { success, err, conn } = await limLogin(self.url, req, self);
console.warn(success)
console.warn(err)
if (success) {
if (!firstMonitorSocket) {
firstMonitorSocket = true;
@@ -193,6 +207,10 @@ export class ImClient {
} else {
log.error(err?.message)
// 加入socket 连接事件
if (typeof imClient.listeners.onSocketErrorEvent === 'function') {
imClient.listeners.onSocketErrorEvent(err?.message);
}
}
}