collab_client: Defer sending messages until connected

This avoids filling the server logs with "Dropping pre-CLIENT_READY
message" error messages.
rhansen-collab_client
Richard Hansen 2021-03-30 18:32:37 -04:00
parent 1ff228391d
commit a18f5de0fc
1 changed files with 5 additions and 4 deletions

View File

@ -167,7 +167,8 @@ const getCollabClient = (ace2editor, serverVars, initialUserInfo, options, _pad)
handleUserChanges(); handleUserChanges();
}; };
const sendMessage = (msg) => { const sendMessage = async (msg) => {
await connectedGate;
getSocket().json.send( getSocket().json.send(
{ {
type: 'COLLABROOM', type: 'COLLABROOM',
@ -326,7 +327,7 @@ const getCollabClient = (ace2editor, serverVars, initialUserInfo, options, _pad)
userSet[userId] = userInfo; userSet[userId] = userInfo;
tellAceActiveAuthorInfo(userInfo); tellAceActiveAuthorInfo(userInfo);
if (!getSocket()) return; if (!getSocket()) return;
sendMessage( await sendMessage(
{ {
type: 'USERINFO_UPDATE', type: 'USERINFO_UPDATE',
userInfo, userInfo,
@ -398,8 +399,8 @@ const getCollabClient = (ace2editor, serverVars, initialUserInfo, options, _pad)
return array; return array;
}; };
const sendClientMessage = (msg) => { const sendClientMessage = async (msg) => {
sendMessage( await sendMessage(
{ {
type: 'CLIENT_MESSAGE', type: 'CLIENT_MESSAGE',
payload: msg, payload: msg,