From 8f09bdce5b9b5df4620821fac6cae12116a71c0e Mon Sep 17 00:00:00 2001 From: Nuwan Chathuranga Date: Sun, 23 May 2021 18:26:21 +0530 Subject: [PATCH] musician latency badge wip --- web/app/assets/javascripts/jam_rest.js | 14 ++++++++ .../actions/LatencyActions.js.coffee | 6 ++++ .../stores/LatencyStore.js.coffee | 35 +++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 web/app/assets/javascripts/react-components/actions/LatencyActions.js.coffee create mode 100644 web/app/assets/javascripts/react-components/stores/LatencyStore.js.coffee diff --git a/web/app/assets/javascripts/jam_rest.js b/web/app/assets/javascripts/jam_rest.js index 99c357923..a1094a440 100644 --- a/web/app/assets/javascripts/jam_rest.js +++ b/web/app/assets/javascripts/jam_rest.js @@ -1773,6 +1773,19 @@ }); } + function getLatencyToUsers(options) { + var id = getId(options); + var user_ids = options['user_ids']; + var data = { user_ids: user_ids }; + return $.ajax({ + type: "GET", + url: '/api/users/' + id + '/latencies', + dataType: "json", + contentType: 'application/json', + data: JSON.stringify(options) + }); + } + function updateAudioLatency(options) { var id = getId(options); return $.ajax({ @@ -3204,6 +3217,7 @@ this.cancelSubscription= cancelSubscription; this.listInvoices = listInvoices; this.getVideoConferencingRoomUrl = getVideoConferencingRoomUrl; + this.getLatencyToUsers = getLatencyToUsers; return this; }; })(window, jQuery); diff --git a/web/app/assets/javascripts/react-components/actions/LatencyActions.js.coffee b/web/app/assets/javascripts/react-components/actions/LatencyActions.js.coffee new file mode 100644 index 000000000..960e236bc --- /dev/null +++ b/web/app/assets/javascripts/react-components/actions/LatencyActions.js.coffee @@ -0,0 +1,6 @@ +context = window + +@LatencyActions = Reflux.createActions({ + resolve: {} +}) + diff --git a/web/app/assets/javascripts/react-components/stores/LatencyStore.js.coffee b/web/app/assets/javascripts/react-components/stores/LatencyStore.js.coffee new file mode 100644 index 000000000..e019261a3 --- /dev/null +++ b/web/app/assets/javascripts/react-components/stores/LatencyStore.js.coffee @@ -0,0 +1,35 @@ +$ = jQuery +context = window +logger = context.JK.logger +rest = new context.JK.Rest() + +@LatencyStore = Reflux.createStore( + { + latencies: [] + + listenables: @LatencyActions + + init: -> + this.listenTo(context.AppStore, this.onAppInit) + + onAppInit: (@app) -> + logger.debug("LatencyStore.onAppInit") + + changed: () -> + @trigger(@latencies) + + onResolve: (user_ids) -> + rest.getLatencyToUsers(user_ids).done((response) => @onLoaded(response)).fail((jqXHR) => @onUserFail(jqXHR)) + + onLoaded: (response) -> + logger.debug("LatencyStore.onLoaded", response); + @latencies.push([{ user_id: '12345', score: 5 }]) + + onUserFail:(jqXHR) -> + logger.debug("LatencyStore.onFail", jqXHR); + #@app.layout.notify({title: 'Unable to Update User Info', text: "We recommend you refresh the page."}) + + getState:() -> + { latencies: @latencies } + } +)