mirror of
https://github.com/Shik3i/KoalaSync.git
synced 2026-08-08 02:13:17 +00:00
Fix WEB_JOIN_REQUEST and joinBtn: custom server invite + password generation
- WEB_JOIN_REQUEST handler: forceDisconnect+connect instead of reusing old socket (same bug as CONNECT: JOIN_ROOM was sent to official server instead of custom) - joinBtn handler: generate random password when roomId is empty and password empty (previously created rooms without passwords when using the advanced join button) - Auto-copy invite link when creating room via joinBtn (consistent with Create Room button)
This commit is contained in:
+7
-15
@@ -1300,23 +1300,15 @@ async function handleAsyncMessage(message, sender, sendResponse) {
|
||||
useCustomServer: !!useCustomServer,
|
||||
serverUrl: serverUrl || ''
|
||||
}, async () => {
|
||||
reconnectFailed = false;
|
||||
reconnectStartTime = null;
|
||||
reconnectAttempts = 0;
|
||||
chrome.storage.session.set({ reconnectFailed: false, reconnectAttempts: 0, reconnectStartTime: null });
|
||||
broadcastConnectionStatus('connecting');
|
||||
leaveOldRoomIfSwitching(roomId);
|
||||
if (socket && socket.readyState === WebSocket.OPEN && isNamespaceJoined) {
|
||||
// FORCE TRANSITION: Emit Join Room directly if already connected
|
||||
const settings = await getSettings();
|
||||
emit(EVENTS.JOIN_ROOM, {
|
||||
roomId,
|
||||
password,
|
||||
peerId,
|
||||
username: settings.username,
|
||||
tabTitle: currentTabTitle,
|
||||
protocolVersion: PROTOCOL_VERSION
|
||||
});
|
||||
addLog(`Joining room via link: ${roomId}`, 'info');
|
||||
} else {
|
||||
connect();
|
||||
}
|
||||
forceDisconnect();
|
||||
connect();
|
||||
addLog(`Joining room via link: ${roomId}`, 'info');
|
||||
sendResponse({ status: 'ok' });
|
||||
});
|
||||
} else if (message.type === 'REGENERATE_ID') {
|
||||
|
||||
+9
-1
@@ -1019,7 +1019,15 @@ elements.joinBtn.addEventListener('click', async () => {
|
||||
}
|
||||
|
||||
const roomId = roomIdInput || Math.random().toString(36).substring(2, 8).toUpperCase();
|
||||
const password = elements.password.value;
|
||||
let password = elements.password.value;
|
||||
if (isCreating && !password) {
|
||||
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
||||
const array = new Uint8Array(6);
|
||||
self.crypto.getRandomValues(array);
|
||||
password = Array.from(array, byte => chars[byte % chars.length]).join('');
|
||||
elements.password.value = password;
|
||||
window.justCreatedRoom = true;
|
||||
}
|
||||
|
||||
await chrome.storage.sync.set({ serverUrl, roomId, password, useCustomServer: useCustom });
|
||||
elements.roomId.value = roomId;
|
||||
|
||||
Reference in New Issue
Block a user