Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions resources/js/Workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ export default class Workspace {
this.containerWatcher = null;
this.statusBarComponent = null;
this.subscribeTimeout = null;

this.eventsQueue = [];

}

start() {
if (this.started) return;

this.initializeHooks();
this.initializeContainerWatcher();
this.startChannel();
this.initializeHooks();
this.started = true;
}

Expand Down Expand Up @@ -121,6 +124,10 @@ export default class Workspace {

this.channel
.subscribed(() => {
for (const event of this.eventsQueue) {
this.whisper( event.event, event.payload, true );
}

clearSubscribeTimeout();
debug(`✅ Subscribed to channel "${channelName}"`);
})
Expand Down Expand Up @@ -440,12 +447,19 @@ export default class Workspace {
return this.store.users.length === 1;
}

whisper(event, payload) {
whisper(event, payload, force = false) {
if (this.isAlone()) return;

const chunkSize = 2500;
const str = JSON.stringify(payload);
const msgId = Math.random() + '';
const isChannelSubscribed = this.subscribeTimeout === null;

if(!isChannelSubscribed && !force) {
debug(`⏳ Broadcast adding to queue "${event}"`, payload);
this.eventsQueue.push({ event, payload });
return;
}

if (str.length < chunkSize) {
debug(`📣 Broadcasting "${event}"`, payload);
Expand Down