Notify users when there are no gaming slots

This commit is contained in:
Sergey Stepanov 2023-05-21 13:54:21 +03:00
parent 624eecd4e8
commit 5b4f74e2b7
No known key found for this signature in database
GPG key ID: A56B4929BAA8556B
6 changed files with 13 additions and 10 deletions

View file

@ -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

View file

@ -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
}

View file

@ -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) => {

View file

@ -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()

View file

@ -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';

View file

@ -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