【m】消息接收发送
This commit is contained in:
@@ -336,6 +336,13 @@ class CallStateManager {
|
||||
this.state.session.status = 'ongoing';
|
||||
this.notify({ type: 'CALL_STATUS_CHANGE', status: 'ongoing' });
|
||||
|
||||
// 连接建立后发送本地用户信息
|
||||
this.sendMessage('user-info', {
|
||||
id: this.state.session.localUser.id,
|
||||
name: this.state.session.localUser.name,
|
||||
avatar: this.state.session.localUser.avatar
|
||||
});
|
||||
|
||||
if (this.state.localStream) {
|
||||
const tracks = this.state.localStream.getTracks(); // 获取本地媒体轨道
|
||||
for (const track of tracks) {
|
||||
@@ -383,6 +390,12 @@ class CallStateManager {
|
||||
this.updateRemoteUserStatus('online');
|
||||
// 更新远程用户网络质量为好
|
||||
this.updateRemoteUserNetworkQuality('good');
|
||||
|
||||
this.sendMessage('user-info', {
|
||||
id: this.state.session.localUser.id,
|
||||
name: this.state.session.localUser.name,
|
||||
avatar: this.state.session.localUser.avatar
|
||||
});
|
||||
// 启动通话时长计时器
|
||||
this.durationInterval = setInterval(() => {
|
||||
this.state.session.duration++;
|
||||
@@ -406,17 +419,39 @@ class CallStateManager {
|
||||
if (data.type === 'chat-message') {
|
||||
// 处理聊天
|
||||
// 添加到列表并更新UI
|
||||
|
||||
chatMessage.handleChatMessage(data.message);
|
||||
// 从消息中提取用户信息并更新remoteUser
|
||||
if (data.message && data.message.senderId !== this.state.session.localUser.id) {
|
||||
this.state.session.remoteUser = {
|
||||
...this.state.session.remoteUser,
|
||||
id: data.message.senderId,
|
||||
name: data.message.senderName,
|
||||
avatar: data.message.senderAvatar
|
||||
};
|
||||
this.notify({ type: 'REMOTE_MEDIA_CHANGE', mediaState: this.state.session.remoteUser.mediaState });
|
||||
}
|
||||
} else if (data.type === 'media-state-changed') {
|
||||
// 处理媒体状态变化
|
||||
console.log('收到媒体状态变化:', data.data);
|
||||
// 更新远程用户的媒体状态
|
||||
this.updateRemoteMedia(data.data);
|
||||
} else if (data.type === 'on-message') {
|
||||
} else if (data.type === 'user-info') {
|
||||
// 处理用户信息更新
|
||||
console.log('收到用户信息:', data.data);
|
||||
if (data.data) {
|
||||
this.state.session.remoteUser = {
|
||||
...this.state.session.remoteUser,
|
||||
id: data.data.id || this.state.session.remoteUser.id,
|
||||
name: data.data.name || this.state.session.remoteUser.name,
|
||||
avatar: data.data.avatar || this.state.session.remoteUser.avatar
|
||||
};
|
||||
this.notify({ type: 'REMOTE_MEDIA_CHANGE', mediaState: this.state.session.remoteUser.mediaState });
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
// 启动WebRTC连接
|
||||
await this.renderstreaming.start();
|
||||
await this.renderstreaming.createConnection(connectionId);
|
||||
@@ -466,6 +501,21 @@ class CallStateManager {
|
||||
this.state.session.status = 'ended';
|
||||
this.notify({ type: 'CALL_ENDED' });
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
* @param {string} type - 消息类型
|
||||
* @param {Object} data - 消息数据
|
||||
*/
|
||||
sendMessage(type, data) {
|
||||
if (this.renderstreaming) {
|
||||
this.renderstreaming.sendMessage({
|
||||
type: type,
|
||||
data: data
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置编解码器偏好
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user