|
@@ -6,6 +6,7 @@ import LibGenerateTestUserSig from "./lib-generate-test-usersig-es.min";
|
|
|
|
|
|
const EXPIRETIME = 604800;
|
|
const EXPIRETIME = 604800;
|
|
const LOGTAG = '--JHIM--:';
|
|
const LOGTAG = '--JHIM--:';
|
|
|
|
+const LOGTAGGROUP = '--JHIM-GROUP--:';
|
|
|
|
|
|
class JhImGroup {
|
|
class JhImGroup {
|
|
constructor(jhim, groupId, groupType, name ,avatar) {
|
|
constructor(jhim, groupId, groupType, name ,avatar) {
|
|
@@ -21,15 +22,15 @@ class JhImGroup {
|
|
return this.jhim.ready && this.groupReady;
|
|
return this.jhim.ready && this.groupReady;
|
|
}
|
|
}
|
|
join(isOwner) {
|
|
join(isOwner) {
|
|
- console.log(LOGTAG + 'join', this.groupId, isOwner);
|
|
|
|
|
|
+ console.log(LOGTAGGROUP + 'join', this.groupId, isOwner);
|
|
|
|
|
|
let join = () => {
|
|
let join = () => {
|
|
- console.log(LOGTAG + 'dojoin', this.groupId);
|
|
|
|
|
|
+ console.log(LOGTAGGROUP + 'dojoin', this.groupId);
|
|
return this.jhim.tim.joinGroup({
|
|
return this.jhim.tim.joinGroup({
|
|
groupID: this.groupId,
|
|
groupID: this.groupId,
|
|
type: TIM.TYPES.GRP_AVCHATROOM
|
|
type: TIM.TYPES.GRP_AVCHATROOM
|
|
}).then(res => {
|
|
}).then(res => {
|
|
- console.log(LOGTAG + 'joinGrouped', res.data.status);
|
|
|
|
|
|
+ console.log(LOGTAGGROUP + 'joinGrouped', res.data.status);
|
|
switch (res.data.status) {
|
|
switch (res.data.status) {
|
|
case TIM.TYPES.JOIN_STATUS_WAIT_APPROVAL: // 等待管理员同意
|
|
case TIM.TYPES.JOIN_STATUS_WAIT_APPROVAL: // 等待管理员同意
|
|
break;
|
|
break;
|
|
@@ -44,7 +45,7 @@ class JhImGroup {
|
|
return this.jhim.tim.searchGroupByID(this.groupId).then(() => {
|
|
return this.jhim.tim.searchGroupByID(this.groupId).then(() => {
|
|
return join();
|
|
return join();
|
|
}, () => {
|
|
}, () => {
|
|
- console.log(LOGTAG + 'createGroup');
|
|
|
|
|
|
+ console.log(LOGTAGGROUP + 'createGroup');
|
|
return this.jhim.tim.createGroup({
|
|
return this.jhim.tim.createGroup({
|
|
groupID: this.groupId,
|
|
groupID: this.groupId,
|
|
name: this.groupId,
|
|
name: this.groupId,
|
|
@@ -55,16 +56,20 @@ class JhImGroup {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
exit(dismiss) {
|
|
exit(dismiss) {
|
|
- console.log(LOGTAG + 'exit', this.groupId, dismiss);
|
|
|
|
- return this.jhim.tim.quitGroup(this.groupId).then(() => {
|
|
|
|
- this.groupReady = false;
|
|
|
|
- }).then(()=>{
|
|
|
|
- if(dismiss) {
|
|
|
|
- return this.jhim.tim.dismissGroup(this.groupId);;
|
|
|
|
- }else {
|
|
|
|
- return Promise.resolve();
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
|
|
+ console.log(LOGTAGGROUP + 'exit', this.groupId, dismiss);
|
|
|
|
+ if(dismiss) {
|
|
|
|
+ return this.jhim.tim.dismissGroup(this.groupId).then(res=>{
|
|
|
|
+ this.groupReady = false;
|
|
|
|
+ console.log(LOGTAGGROUP+'dismissGroup', res);
|
|
|
|
+ return res;
|
|
|
|
+ });
|
|
|
|
+ }else {
|
|
|
|
+ return this.jhim.tim.quitGroup(this.groupId).then(res=>{
|
|
|
|
+ this.groupReady = false;
|
|
|
|
+ console.log(LOGTAGGROUP+'quitGroup', res);
|
|
|
|
+ return res;
|
|
|
|
+ });
|
|
|
|
+ }
|
|
}
|
|
}
|
|
getProfile() {
|
|
getProfile() {
|
|
return this.jhim.tim.getGroupProfile({
|
|
return this.jhim.tim.getGroupProfile({
|
|
@@ -136,7 +141,7 @@ class JhImGroup {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-let instance = null;
|
|
|
|
|
|
+
|
|
export default class JhIm {
|
|
export default class JhIm {
|
|
static getInstance(userId, sdkAppID, secretKey, userSig) {
|
|
static getInstance(userId, sdkAppID, secretKey, userSig) {
|
|
if (JhIm.instance) return JhIm.instance;
|
|
if (JhIm.instance) return JhIm.instance;
|
|
@@ -166,39 +171,20 @@ export default class JhIm {
|
|
this.TYPES = TIM.TYPES;
|
|
this.TYPES = TIM.TYPES;
|
|
this.EVENT = TIM.EVENT;
|
|
this.EVENT = TIM.EVENT;
|
|
|
|
|
|
- this.tim.on(TIM.EVENT.MESSAGE_RECEIVED, event => {
|
|
|
|
- console.log(LOGTAG + 'recv', event);
|
|
|
|
- let msgs = [];
|
|
|
|
- event.data.forEach(v => {
|
|
|
|
- // https://imsdk-1252463788.file.myqcloud.com/IM_DOC/Web/Message.html
|
|
|
|
- if (v.type == TIM.TYPES.MSG_TEXT) {
|
|
|
|
- msgs.push(v);
|
|
|
|
- msgs.push({
|
|
|
|
- type: v.type,
|
|
|
|
- name: v.nick,
|
|
|
|
- avatar: v.avatar,
|
|
|
|
- text: v.payload.text,
|
|
|
|
- conversationType: v.conversationType,
|
|
|
|
- time: v.time,
|
|
|
|
- })
|
|
|
|
- } else if (v.type == "TIMGroupTipElem") {
|
|
|
|
- this.onIMGroupTipElem && this.onIMGroupTipElem(v.payload);
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
-
|
|
|
|
- this.onIMMessageReceived && this.onIMMessageReceived(msgs);
|
|
|
|
- }, this);
|
|
|
|
-
|
|
|
|
- this.tim.on(TIM.EVENT.SDK_READY, event => {
|
|
|
|
|
|
+ this._readyCb = event => {
|
|
this.ready = true;
|
|
this.ready = true;
|
|
- }, this);
|
|
|
|
- this.tim.on(TIM.EVENT.SDK_NOT_READY, event => {
|
|
|
|
|
|
+ };
|
|
|
|
+ this.tim.on(TIM.EVENT.SDK_READY, this._readyCb);
|
|
|
|
+ this._notReadyCb = event => {
|
|
this.ready = false;
|
|
this.ready = false;
|
|
- }, this);
|
|
|
|
|
|
+ };
|
|
|
|
+ this.tim.on(TIM.EVENT.SDK_NOT_READY, this._notReadyCb);
|
|
|
|
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
destory() {
|
|
destory() {
|
|
|
|
+ this.tim.off(this._readyCb);
|
|
|
|
+ this.tim.off(this._notReadyCb);
|
|
this.tim = null;
|
|
this.tim = null;
|
|
}
|
|
}
|
|
on(name, cb) {
|
|
on(name, cb) {
|