showing latency badge wip
This commit is contained in:
parent
8f09bdce5b
commit
bcbd36a221
|
|
@ -7,6 +7,7 @@
|
|||
var logger = context.JK.logger;
|
||||
var rest = context.JK.Rest();
|
||||
var hoverSelector = "#musician-hover";
|
||||
var latencyBadgeSelector = '#musician-latency-badge';
|
||||
var $templateLatency = null;
|
||||
var sessionUtils = context.JK.SessionUtils;
|
||||
|
||||
|
|
@ -130,6 +131,9 @@
|
|||
|
||||
$(hoverSelector).css(css);
|
||||
$(hoverSelector).fadeIn(500);
|
||||
|
||||
bindUserLatencyUpdate(userId);
|
||||
LatencyActions.resolve([userId])
|
||||
})
|
||||
.fail(function(xhr) {
|
||||
if(xhr.status >= 500) {
|
||||
|
|
@ -180,8 +184,36 @@
|
|||
|
||||
}
|
||||
|
||||
function bindUserLatencyUpdate(userId){
|
||||
var latency;
|
||||
$(document).one('user_latency_update', function(e, latencyData){
|
||||
logger.debug("bindUserLatencyUpdate", latencyData)
|
||||
//latency = latencyData[0]
|
||||
latency = latencyData
|
||||
if(latency['id'] === userId){
|
||||
showLatencyBadge(latency)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function showLatencyBadge(latency){
|
||||
$templateLatency = $("#template-account-session-latency");
|
||||
var latencyBadge = context._.template(
|
||||
$templateLatency.html(),
|
||||
$.extend(latency, sessionUtils.createLatency(latency)),
|
||||
{ variable: 'data' }
|
||||
);
|
||||
//logger.debug('BADGE', latencyBadge)
|
||||
$(latencyBadgeSelector).html(latencyBadge)
|
||||
}
|
||||
|
||||
function unbindUserLatencyUpdate(){
|
||||
$(document).off('user_latency_update');
|
||||
}
|
||||
|
||||
this.hideBubble = function() {
|
||||
$(hoverSelector).hide();
|
||||
unbindUserLatencyUpdate();
|
||||
$(hoverSelector).hide();
|
||||
};
|
||||
|
||||
this.id = function() {
|
||||
|
|
|
|||
|
|
@ -1775,14 +1775,13 @@
|
|||
|
||||
function getLatencyToUsers(options) {
|
||||
var id = getId(options);
|
||||
var user_ids = options['user_ids'];
|
||||
var data = { user_ids: user_ids };
|
||||
logger.debug(">>> getLatencyToUsers", options)
|
||||
return $.ajax({
|
||||
type: "GET",
|
||||
url: '/api/users/' + id + '/latencies',
|
||||
dataType: "json",
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify(options)
|
||||
data: options
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,22 +13,23 @@ rest = new context.JK.Rest()
|
|||
this.listenTo(context.AppStore, this.onAppInit)
|
||||
|
||||
onAppInit: (@app) ->
|
||||
logger.debug("LatencyStore.onAppInit")
|
||||
|
||||
changed: () ->
|
||||
$(document).trigger("user_latency_update", @latencies)
|
||||
@trigger(@latencies)
|
||||
|
||||
onResolve: (user_ids) ->
|
||||
rest.getLatencyToUsers(user_ids).done((response) => @onLoaded(response)).fail((jqXHR) => @onUserFail(jqXHR))
|
||||
|
||||
# rest.getLatencyToUsers({user_ids: user_ids}).done((response) => @onLoaded(response)).fail((jqXHR) => @onUserFail(jqXHR))
|
||||
@latencies.push({ id: '6337dc99-5023-477f-8781-3a810bb35b61', audio_latency: 3, full_score: 5, internet_score:2 })
|
||||
@changed()
|
||||
|
||||
onLoaded: (response) ->
|
||||
logger.debug("LatencyStore.onLoaded", response);
|
||||
@latencies.push([{ user_id: '12345', score: 5 }])
|
||||
@latencies.push(response)
|
||||
|
||||
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 }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -937,15 +937,32 @@ class ApiUsersController < ApiController
|
|||
|
||||
#fetch latency information from latency-graph serverless
|
||||
def get_latencies
|
||||
query_str = params[:user_ids].split(',').inject(""){|q, id| q.concat("id=#{id}&")}
|
||||
latency_url = "#{Rails.application.config.latency_data_host}/dev/user_latencies/#{current_user.id}?#{query_str}"
|
||||
url = URI(latency_url)
|
||||
|
||||
user_ids = params[:user_ids]
|
||||
#query_str = user_ids.inject(""){|q, id| q.concat("id=#{id}&")}
|
||||
#latency_url = "#{Rails.application.config.latency_data_host}/dev/user_latencies/#{current_user.id}?#{query_str}"
|
||||
latency_url = "#{Rails.application.config.latency_data_host}/dev/user_latencies"
|
||||
uri = URI(latency_url)
|
||||
begin
|
||||
http = Net::HTTP.new(url.host, url.port)
|
||||
header = {
|
||||
'Content-Type': 'text/json',
|
||||
'Authorization': "Basic #{Rails.application.config.latency_data_host_auth_code}"
|
||||
}
|
||||
http = Net::HTTP.new(uri.host, uri.port, read_timeout: 5, open_timeout: 5)
|
||||
http.use_ssl = true if Rails.application.config.latency_data_host.start_with?("https://")
|
||||
request = Net::HTTP::Get.new(url)
|
||||
request["Authorization"] = "Basic #{Rails.application.config.latency_data_host_auth_code}"
|
||||
response = http.request(request)
|
||||
req = Net::HTTP::Post.new(uri.path, header)
|
||||
req["Authorization"] = "Basic #{Rails.application.config.latency_data_host_auth_code}"
|
||||
data = {
|
||||
my_user_id: current_user.id,
|
||||
my_public_ip: request.remote_ip,
|
||||
my_device_id: "unknown",
|
||||
my_client_id: "unknown",
|
||||
users: user_ids
|
||||
}
|
||||
req.body = data.to_json
|
||||
|
||||
response = http.request(req)
|
||||
|
||||
if response.is_a?(Net::HTTPOK) || response.is_a?(Net::HTTPSuccess)
|
||||
render json: response.body, status: 200
|
||||
else
|
||||
|
|
@ -962,7 +979,7 @@ class ApiUsersController < ApiController
|
|||
render json: {}, status: 422
|
||||
end
|
||||
rescue
|
||||
Bugsnag.notify("Latency server returned code: #{response.code}")
|
||||
Bugsnag.notify("Latency server returned code: #{response.code}") if response
|
||||
render json: {}, status: 500
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -117,7 +117,8 @@
|
|||
<br />
|
||||
<div class="f11">{biography}</div><br />
|
||||
<div class="left f11 musician-latency">
|
||||
Your latency to {first_name} is: {latency_badge}
|
||||
Your latency to {first_name} is:
|
||||
<span id="musician-latency-badge">{latency_badge}</span>
|
||||
</div>
|
||||
<br clear="both"/>
|
||||
<br clear="both"/>
|
||||
|
|
|
|||
Loading…
Reference in New Issue