diff --git a/pkg/api/api.go b/pkg/api/api.go index cfdafe0a..6f53154d 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -79,6 +79,7 @@ const ( ToggleMultitap PT = 109 RecordGame PT = 110 GetWorkerList PT = 111 + ErrNoFreeSlots PT = 112 RegisterRoom PT = 201 CloseRoom PT = 202 IceCandidate = WebrtcIce diff --git a/pkg/coordinator/hub.go b/pkg/coordinator/hub.go index 6331aef4..bc815d9d 100644 --- a/pkg/coordinator/hub.go +++ b/pkg/coordinator/hub.go @@ -66,6 +66,7 @@ func (h *Hub) handleUserConnection() http.HandlerFunc { params := r.URL.Query() worker := h.findWorkerFor(user, params, h.log.Extend(h.log.With().Str("cid", user.Id().Short()))) if worker == nil { + user.Notify(api.ErrNoFreeSlots, "") h.log.Info().Msg("no free workers") return } diff --git a/web/js/api/api.js b/web/js/api/api.js index 7fafe225..bbb21318 100644 --- a/web/js/api/api.js +++ b/web/js/api/api.js @@ -20,6 +20,7 @@ const api = (() => { GAME_TOGGLE_MULTITAP: 109, GAME_RECORDING: 110, GET_WORKER_LIST: 111, + GAME_ERROR_NO_FREE_SLOTS: 112, }); const packet = (type, payload, id) => { diff --git a/web/js/controller.js b/web/js/controller.js index ab0ad129..eb7cd05a 100644 --- a/web/js/controller.js +++ b/web/js/controller.js @@ -214,6 +214,9 @@ case api.endpoint.GAME_RECORDING: event.pub(RECORDING_STATUS_CHANGED, payload); break; + case api.endpoint.GAME_ERROR_NO_FREE_SLOTS: + event.pub(GAME_ERROR_NO_FREE_SLOTS); + break; } } @@ -482,10 +485,8 @@ event.sub(GAME_PLAYER_IDX_SET, idx => { if (!isNaN(+idx)) message.show(+idx + 1); }); + event.sub(GAME_ERROR_NO_FREE_SLOTS, () => message.show("No free slots :(", 2500)); event.sub(WEBRTC_NEW_CONNECTION, (data) => { - // if (pingPong) { - // webrtc.setMessageHandler(onWebrtcMessage); - // } workerManager.whoami(data.wid); webrtc.start(data.ice); api.server.initWebrtc() diff --git a/web/js/event/event.js b/web/js/event/event.js index 922d468f..9ad45a4b 100644 --- a/web/js/event/event.js +++ b/web/js/event/event.js @@ -65,6 +65,7 @@ const GAME_SAVED = 'gameSaved'; const GAME_LOADED = 'gameLoaded'; const GAME_PLAYER_IDX = 'gamePlayerIndex'; const GAME_PLAYER_IDX_SET = 'gamePlayerIndexSet' +const GAME_ERROR_NO_FREE_SLOTS = 'gameNoFreeSlots' const WEBRTC_CONNECTION_CLOSED = 'webrtcConnectionClosed'; const WEBRTC_CONNECTION_READY = 'webrtcConnectionReady'; diff --git a/web/js/gui/message.js b/web/js/gui/message.js index d4bf668c..598d69e9 100644 --- a/web/js/gui/message.js +++ b/web/js/gui/message.js @@ -12,7 +12,7 @@ const message = (() => { let isScreenFree = true; - const _popup = () => { + const _popup = (time = 1000) => { // recursion edge case: // no messages in the queue or one on the screen if (!(queue.length > 0 && isScreenFree)) { @@ -21,7 +21,7 @@ const message = (() => { isScreenFree = false; popupBox.innerText = queue.shift(); - gui.anim.fadeInOut(popupBox, 1000, .05).finally(() => { + gui.anim.fadeInOut(popupBox, time, .05).finally(() => { isScreenFree = true; _popup(); }) @@ -33,14 +33,12 @@ const message = (() => { } } - const _proceed = (text) => { + const _proceed = (text, time) => { _storeMessage(text); - _popup(); + _popup(time); } - const show = (text) => { - _proceed(text) - } + const show = (text, time = 1000) => _proceed(text, time) return Object.freeze({ show: show