我想在一个页面上创建多个聊天室,用户可以在其中进行不同房间的视频/音频/文本聊天。我已经做了一个单一的,但我不太了解在一个页面上的连接。
我正在使用RTCMultiConnection V3.0用于单个聊天室。
我希望在下图中提到。
任何人都可以帮我实现这个目标吗?
答案 0 :(得分:2)
使用多个RTCMultiConnection实例:
var room1 = new RTCMultiConnection();
var room2 = new RTCMultiConnection();
var room3 = new RTCMultiConnection();
room1.join('room1-unique-ID');
room2.join('room2-unique-ID');
room3.join('room3-unique-ID');
connection.session.broadcast = true;
connection.open('each-user-unique-id'); // each user should call this
现在每个用户都可以加入任何会议室:
connection.join('first-room');
connection.join('second-room');
connection.join('third-room');
请记住,我们在上面设置{broadcast:true}
;这意味着join
方法只允许您加入房间所有者/主持人/发起人。
您需要请房间主持人为您提供所有参与者的列表。
var alreadyGivedParticipants = {};
connection.onPeerStateChanged = function(state) {
if (state.iceConnectionState !== 'connected') return; // ignore
if (alreadyGivedParticipants[state.userid]) return;
alreadyGivedParticipants[state.userid] = true; // to make sure we don't duplicate
connection.socket.emit(connection.socketCustonEvent, {
participants: connection.getAllParticipants(),
onlyForThisUser: state.userid
});
};
connection.connectSocket(function() {
connection.socket.on(connection.socketCustonEvent, function(message) {
if (message.onlyForThisUser !== connection.userid) return; // ignore
message.participants.forEach(function(pid) {
connection.join(pid); // join all room participants
});
});
});
您甚至可以向现有参与者提供每个新用户的信息。
var alreadyGivedParticipants = {};
connection.onPeerStateChanged = function(state) {
if (state.iceConnectionState !== 'connected') return; // ignore
if (alreadyGivedParticipants[state.userid]) return;
alreadyGivedParticipants[state.userid] = true; // to make sure we don't duplicate
connection.socket.emit(connection.socketCustonEvent, {
participants: connection.getAllParticipants(),
onlyForThisUser: state.userid
});
// below block shares new user with existing participants
connection.getAllParticipants().forEach(function(existingUser) {
connection.socket.emit(connection.socketCustonEvent, {
participants: [state.userid],
onlyForThisUser: existingUser
});
});
};
connection.connectSocket(function() {
connection.socket.on(connection.socketCustonEvent, function(message) {
if (message.onlyForThisUser !== connection.userid) return; // ignore
message.participants.forEach(function(pid) {
connection.join(pid); // join all room participants
});
});
});
您可以使用getPublicModerators方法获取所有公共房间的列表。一个live demo。
答案 1 :(得分:0)
对于多房间/类别,你需要一个变量“类型”然后使用精确的mysql与搜索机制!