|
@@ -129,7 +129,7 @@ export class MessageService {
|
|
|
*@'RESPONSEINVITOIN_' + uid: 接受邀请
|
|
|
*/
|
|
|
joinReady(channelName?: string) {
|
|
|
- this.rtmClient.addEventListener('message', async (event: any) => {
|
|
|
+ this.rtmClient?.addEventListener('message', async (event: any) => {
|
|
|
console.log('接收到一条消息:', event);
|
|
|
let states = [
|
|
|
'USERCALLINVITATION',
|
|
@@ -146,7 +146,7 @@ export class MessageService {
|
|
|
}
|
|
|
this.showMessage(event);
|
|
|
});
|
|
|
- this.rtmClient.addEventListener('presence', (event: any) => {
|
|
|
+ this.rtmClient?.addEventListener('presence', (event: any) => {
|
|
|
console.log('频道人员状态变化 ', event);
|
|
|
let is_self = event.publisher == this.userId;
|
|
|
//远端用户离开频道,主播在线状态
|
|
@@ -158,7 +158,7 @@ export class MessageService {
|
|
|
this.setConnectState(this.userId, 'ONLINE');
|
|
|
}
|
|
|
});
|
|
|
- this.rtmClient.addEventListener('linkState', (event: any) => {
|
|
|
+ this.rtmClient?.addEventListener('linkState', (event: any) => {
|
|
|
console.log('连接状态: ', event);
|
|
|
});
|
|
|
}
|
|
@@ -170,7 +170,7 @@ export class MessageService {
|
|
|
Mode: mode,
|
|
|
};
|
|
|
try {
|
|
|
- await this.rtmClient.presence.setState(channelName, channelType, states);
|
|
|
+ await this.rtmClient?.presence.setState(channelName, channelType, states);
|
|
|
} catch (err: any) {
|
|
|
console.log(err);
|
|
|
}
|
|
@@ -272,7 +272,7 @@ export class MessageService {
|
|
|
// }
|
|
|
async loginRTM(channelName?: string) {
|
|
|
try {
|
|
|
- await this.rtmClient.login({
|
|
|
+ await this.rtmClient?.login({
|
|
|
token: this.options.token,
|
|
|
});
|
|
|
this.options.connectState = true; // 登录成功
|
|
@@ -296,7 +296,7 @@ export class MessageService {
|
|
|
addTimeStamp: true,
|
|
|
addUserId: true,
|
|
|
};
|
|
|
- let result = await this.rtmClient.storage.setUserMetadata(
|
|
|
+ let result = await this.rtmClient?.storage.setUserMetadata(
|
|
|
metadata,
|
|
|
options
|
|
|
);
|
|
@@ -307,7 +307,7 @@ export class MessageService {
|
|
|
}
|
|
|
}
|
|
|
logOutRTM() {
|
|
|
- this.rtmClient.logout().then(() => {
|
|
|
+ this.rtmClient?.logout().then(() => {
|
|
|
console.log('logout success');
|
|
|
this.options.connectState = false;
|
|
|
});
|
|
@@ -375,7 +375,7 @@ export class MessageService {
|
|
|
}
|
|
|
async getUserMetadata(uid: string) {
|
|
|
try {
|
|
|
- const result = await this.rtmClient.storage.getUserMetadata({
|
|
|
+ const result = await this.rtmClient?.storage.getUserMetadata({
|
|
|
userId: uid,
|
|
|
});
|
|
|
return result.metadata;
|
|
@@ -393,7 +393,7 @@ export class MessageService {
|
|
|
const publishMessage = JSON.stringify(payload);
|
|
|
const publishOptions = { channelType: channelType ?? 'MESSAGE' };
|
|
|
try {
|
|
|
- const result = await this.rtmClient.publish(
|
|
|
+ const result = await this.rtmClient?.publish(
|
|
|
channelName,
|
|
|
publishMessage,
|
|
|
publishOptions
|