This commit is contained in:
2023-10-26 21:03:04 +08:00
3 changed files with 43 additions and 3 deletions

View File

@@ -33,7 +33,8 @@ export default class HttpApi {
'Content-Type':'application/json',
};
const request: any = {method: requestMethod,headers:headers, mode: 'cors', body: Beans.json(body)};
// const request: any = {method: requestMethod,headers:headers, mode: 'cors', body: Beans.json(body)};
const request: any = {method: requestMethod,headers:headers, body: Beans.json(body)};
return this.httpFetch(reqUrl, request);
}

View File

@@ -112,7 +112,18 @@ export class ImClient {
}
let ip = resp.data.ip;
let port = resp.data.port;
this.url = "wss://" + ip + ":" + port + "/hs_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";
}
}
var req = new LoginPack(self.appId, self.userId, 1);
@@ -254,6 +265,7 @@ export class ImClient {
}
}
public getSingleUserInfo(uid: string): Promise<any> {
return new Promise((resolve, _) => {
let api = new HttpApi(this.httpUrl);
@@ -262,6 +274,7 @@ export class ImClient {
})
}
public async syncGetUserInfo(userId: string[]) {
let api = new HttpApi(this.httpUrl);
let resp = api.call("/user/data/getUserInfo", this.getRequestParams(), { userIds: userId })
@@ -301,6 +314,30 @@ export class ImClient {
})
}
public createRoom(room:any): Promise<any> {
return new Promise((resolve,_)=>{
let api = new HttpApi(this.httpUrl);
let resp = api.call("/room/createRoom", this.getRequestParams(), room)
return resp;
})
}
public joinRoom(room:any): Promise<any> {
return new Promise((resolve,_)=>{
let api = new HttpApi(this.httpUrl);
let resp = api.call("/room/joinRoom", this.getRequestParams(), room)
return resp;
})
}
public getRoomInfo(roomId:any): Promise<any> {
return new Promise((resolve,_)=>{
let api = new HttpApi(this.httpUrl);
let resp = api.call("/room/getRoomInfo", this.getRequestParams(), { roomId: roomId })
return resp;
})
}
// 2、心跳
private heartbeatLoop(conn) {
let start = Date.now()

View File

@@ -26,7 +26,9 @@ export class MessagePack {
buildTextMessagePack(fromId: string, toId: string, text: string) {
this.fromId = fromId;
this.toId = toId;
let body = { type: 1, content: text }
console.warn(typeof text)
console.log(text)
let body = text
this.messageBody = Beans.json(body);
}