diff --git a/web/app/assets/javascripts/react-components/FindSessionOpen.js.jsx.coffee b/web/app/assets/javascripts/react-components/FindSessionOpen.js.jsx.coffee index e0f1bd47a..8ffdfd366 100644 --- a/web/app/assets/javascripts/react-components/FindSessionOpen.js.jsx.coffee +++ b/web/app/assets/javascripts/react-components/FindSessionOpen.js.jsx.coffee @@ -1,6 +1,7 @@ context = window SessionsActions = @SessionsActions +LatencyActions = @LatencyActions @FindSessionOpen = React.createClass({ @@ -11,7 +12,7 @@ SessionsActions = @SessionsActions registeredInfiniteScroll: false getInitialState: () -> - {active: false, sessions: [], searching: false, count: 0, currentPage: 0, end: false} + {active: false, sessions: [], searching: false, count: 0, currentPage: 0, end: false, participant_ids: []} sessionResults: () -> results = [] @@ -188,6 +189,15 @@ SessionsActions = @SessionsActions onSessionsChanged: (sessionsChanged) -> if sessionsChanged.type == @props.mode + + for session in sessionsChanged.sessions + for participant in session.active_music_session.participants + @state.participant_ids.push(participant.user.id) + + # for rsvp in session.approved_rsvps + # @state.participant_ids.push(rsvp.id) + #logger.debug("<<<<<<>>>>>>>>", _.unique(@state.participant_ids)) + LatencyActions.resolve(_.unique(@state.participant_ids)) @setState(sessionsChanged) }) \ No newline at end of file diff --git a/web/app/assets/javascripts/react-components/FindSessionRow.js.jsx.coffee b/web/app/assets/javascripts/react-components/FindSessionRow.js.jsx.coffee index 312ffb2ac..13d4c4942 100644 --- a/web/app/assets/javascripts/react-components/FindSessionRow.js.jsx.coffee +++ b/web/app/assets/javascripts/react-components/FindSessionRow.js.jsx.coffee @@ -5,13 +5,16 @@ EVENTS = context.JK.EVENTS SessionsActions = context.SessionsActions AppStore = context.AppStore MAX_MINUTES_SHOW_START = 15 +SessionUtils = context.JK.SessionUtils @FindSessionRow = React.createClass({ + mixins: [Reflux.listenTo(@LatencyStore, "onLatencyUpdate")] + ui: null getInitialState: () -> - {rsvpToggle: false, openSlotToggle: false} + { rsvpToggle: false, openSlotToggle: false, userLatencies: [] } createInstrument: (participant) -> @@ -26,12 +29,26 @@ MAX_MINUTES_SHOW_START = 15 instruments + createLatencyBadge: (participant) -> + logger.debug(">>>userLatencies", @state.userLatencies) + latency = @state.userLatencies.find((latency) -> + latency.user_id == participant.id; + ) + # latencyData = SessionUtils.changeLatencyDataStructure(latency) + # data = $.extend(latencyData, SessionUtils.createLatency(latencyData)) + # latency_text = data.latency_text + # latency_style = data.latency_text + + `{latency_text}` + createInSessionUser: (participant) -> - instruments = @createInstrument(participant) + instruments = @createInstrument(participant) - `` + latencyBadge = @createLatencyBadge(participant) + + `` createOpenSlot:(slot, isLast) -> @@ -73,7 +90,6 @@ MAX_MINUTES_SHOW_START = 15 {more_link}  ` - createRsvpUser: (user, session, isLast) -> instruments = [] @@ -99,10 +115,9 @@ MAX_MINUTES_SHOW_START = 15 moreLinkHtml = `{text}` + latencyBadge = @createLatencyBadge(user) - `` - - + `` inSessionUsersHtml: (session) -> inSessionUsers = [] @@ -121,7 +136,6 @@ MAX_MINUTES_SHOW_START = 15 ` return [result, inSessionUsers] - createRsvpUsers:(session) -> firstResults = [] @@ -144,8 +158,6 @@ MAX_MINUTES_SHOW_START = 15 [firstResults, lastResults] - - createOpenSlots: (session) -> firstResults = [] @@ -195,7 +207,6 @@ MAX_MINUTES_SHOW_START = 15
{joinText}
` - rsvpLink: (session) -> pendingRsvpId = null @@ -385,7 +396,6 @@ MAX_MINUTES_SHOW_START = 15 ) return false - inSessionMusicians: (in_session_musicians) -> if @props.mode == 'upcoming' return null @@ -399,6 +409,10 @@ MAX_MINUTES_SHOW_START = 15 createListenLink: () -> null + + onLatencyUpdate: (userLatencies) -> + @setState(userLatencies: userLatencies) + render: () -> session = @props.session diff --git a/web/app/assets/javascripts/react-components/HoverUser.js.jsx.coffee b/web/app/assets/javascripts/react-components/HoverUser.js.jsx.coffee index 358e0c3ee..04a858e70 100644 --- a/web/app/assets/javascripts/react-components/HoverUser.js.jsx.coffee +++ b/web/app/assets/javascripts/react-components/HoverUser.js.jsx.coffee @@ -30,6 +30,9 @@ MAX_MINUTES_SHOW_START = 15
{this.props.instruments}
+ +
GOOD
+ {this.props.more} ` diff --git a/web/spec/features/find_sessions_latency_badge.rb b/web/spec/features/find_sessions_latency_badge.rb deleted file mode 100644 index 380f4c391..000000000 --- a/web/spec/features/find_sessions_latency_badge.rb +++ /dev/null @@ -1,114 +0,0 @@ -require 'spec_helper' - -describe "Find session latency badge", js: true, type: :feature, capybara_feature: true do - let(:creator_user){ FactoryGirl.create(:user) } - let(:joiner_user){ FactoryGirl.create(:user) } - let(:finder_user){ FactoryGirl.create(:user) } - let(:latency_data_uri) { /\S+\/user_latencies/ } - - - def create_and_join_session(creator_user, joiner_user) - in_client(creator_user) do - fast_signin(creator_user, "/client#/createSession") - wait_until_curtain_gone - find("h1", text: "session") - find(".quick-start-open").click - end - - in_client(joiner_user) do - fast_signin(joiner_user, "/client#/findSession") - wait_until_curtain_gone - find("h1", text: "find a session") - find("a", text: "Open Jams").click - expect(page).to have_selector("#sessions-active .found-session", count: 1) - find("#sessions-active .found-session .join-link").click - find("#session-terms-conditions") - within("#session-terms-conditions") do - find("#btn-accept-terms").click - end - find("h1", text: "session") - end - end - - def mock_latency_response(collection) - resp = [] - if collection && collection.any? - resp = collection.map do |latency_item| - user = latency_item[:user] - latency = latency_item[:latency] - audio_latency = latency_item[:audio_latency] - audio_latency_unknown = latency_item[:audio_latency_unknown] - ars_internet_latency = latency_item[:ars_internet_latency] - ars_total_latency = latency_item[:ars_total_latency] - p2p_internet_latency = latency_item[:p2p_internet_latency] - p2p_total_latency = latency_item[:p2p_total_latency] - wifi = latency_item[:wifi] - - { - "user_id": user.id, - "first_name": user.first_name, - "last_name": user.last_name, - "audio_latency": audio_latency, - "audio_latency_unknown": audio_latency_unknown, - "ars": { - "internet_latency": ars_internet_latency, - "total_latency": ars_total_latency - }, - "p2p": { - "internet_latency": p2p_internet_latency, - "total_latency": p2p_total_latency - }, - "wifi": wifi - } - end - end - - output = if resp.any? - { - "users": resp, - "my_audio_latency": 4.0, - "my_audio_latency_unknown": false - } - else - { - "users": [] - } - end - output.to_json - end - - before(:all) do - Capybara.default_max_wait_time = 10 - end - - describe "public session" do - - before(:each) do - emulate_client - ActiveMusicSession.delete_all - create_and_join_session(creator_user, joiner_user) - end - - - it "finds session" do - in_client(finder_user) do - response_body = mock_latency_response([{ user: creator_user, ars_total_latency: 1.0, ars_internet_latency: 0.5, audio_latency: 0.5 }]) #sessionUtils.LATENCY.GOOD : {description: "GOOD", style: "latency-good", min: 0.0, max: 40.0}, - - stub_request(:post, latency_data_uri) - .with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}) - .to_return( body: response_body, status: 200) - - fast_signin(finder_user, "/client#/findSession") - wait_until_curtain_gone - find("h1", text: "find a session") - find("a", text: "Open Jams").click - expect(page).to have_selector("#sessions-active .found-session table.musicians-category tr", count: 2) - - find("#sessions-active a[data-user-id=\"#{creator_user.id}\"][data-hoveraction=\"musician\"]", text: creator_user.name).hover_intent - find('h3', text: creator_user.name) - find("#musician-latency-badge .latency", text: 'GOOD') - end - end - - end -end \ No newline at end of file diff --git a/web/spec/features/find_sessions_latency_badge_spec.rb b/web/spec/features/find_sessions_latency_badge_spec.rb new file mode 100644 index 000000000..8b9b9c40f --- /dev/null +++ b/web/spec/features/find_sessions_latency_badge_spec.rb @@ -0,0 +1,96 @@ +require 'spec_helper' +require 'webmock/rspec' + +describe "Find session latency badge", js: true, type: :feature, capybara_feature: true do + let(:creator_user){ FactoryGirl.create(:user) } + let(:joiner_user){ FactoryGirl.create(:user) } + let(:finder_user){ FactoryGirl.create(:user) } + let(:latency_data_uri) { /\S+\/user_latencies/ } + + def create_and_join_session(creator_user, joiner_user) + in_client(creator_user) do + fast_signin(creator_user, "/client#/createSession") + wait_until_curtain_gone + find("h1", text: "session") + find(".quick-start-open").click + end + in_client(joiner_user) do + joiner_response_body = mock_latency_response([{ user: joiner_user, ars_total_latency: 1.0, ars_internet_latency: 0.5, audio_latency: 0.5 }]) + + stub_request(:post, latency_data_uri) + .with( + :headers => { + 'Accept'=>'*/*', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'} + ) + .to_return( body: joiner_response_body, status: 200) + + fast_signin(joiner_user, "/client#/findSession") + wait_until_curtain_gone + find("h1", text: "find a session") + find("a", text: "Open Jams").click + expect(page).to have_selector("#sessions-active .found-session", count: 1) + find("#sessions-active .found-session .join-link").click + find("#session-terms-conditions") + within("#session-terms-conditions") do + find("#btn-accept-terms").click + end + find("h1", text: "session") + end + end + + + before(:all) do + Capybara.default_max_wait_time = 10 + end + + describe "In public session" do + + before(:each) do + emulate_client + ActiveMusicSession.delete_all + create_and_join_session(creator_user, joiner_user) + end + + + it "show GOOD" do + in_client(finder_user) do + creator_response_body = mock_latency_response([{ user: creator_user, ars_total_latency: 1.0, ars_internet_latency: 0.5, audio_latency: 0.5 }]) #sessionUtils.LATENCY.GOOD : {description: "GOOD", style: "latency-good", min: 0.0, max: 40.0}, + + + stub_request(:post, latency_data_uri) + .with( + :headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'} + ) + .to_return( body: creator_response_body, status: 200) + + + + + fast_signin(finder_user, "/client#/findSession") + wait_until_curtain_gone + find("h1", text: "find a session") + find("a", text: "Open Jams").click + expect(page).to have_selector("#sessions-active .found-session table.musicians-category tr", count: 2) + + expect(page).to have_selector("div.latency-badge[data-user-id=\"#{creator_user.id}\"]", text: "GOOD") + #expect(page).to have_selector("div.latency-badge[data-user-id=\"#{joiner_user.id}\"]", text: "GOOD") + + # selector = "#sessions-active a[data-user-id=\"#{creator_user.id}\"][data-hoveraction=\"musician\"]" + # find(selector, text: creator_user.name).hover_intent + # find('h3', text: creator_user.name) + # find("#musician-latency-badge .latency", text: 'GOOD') + # page.execute_script("$('#{selector}').mouseleave();") + # sleep(1) + + # selector = "#sessions-active a[data-user-id=\"#{joiner_user.id}\"][data-hoveraction=\"musician\"]" + # find(selector, text: joiner_user.name).hover_intent + # find('h3', text: joiner_user.name) + # find("#musician-latency-badge .latency", text: 'GOOD') + # page.execute_script("$('#{selector}').mouseleave();") + # sleep(1) + end + end + + end + +end \ No newline at end of file