Skip to content

Commit

Permalink
Merge pull request #583 from Real-Dev-Squad/feature/sidebar
Browse files Browse the repository at this point in the history
[Live-Site] - Sidebar peers map according to roles
  • Loading branch information
satyam73 authored Aug 31, 2023
2 parents 31efbe8 + 9bddcdc commit d90578a
Show file tree
Hide file tree
Showing 8 changed files with 286 additions and 52 deletions.
44 changes: 44 additions & 0 deletions app/components/live-participants.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<div data-test-sidebar-body-role class='body__role-user'>
<p
data-test-sidebar-body-role-guest
class='role-user__type guestUsers'
>{{@user}}</p>
<ul>

{{#if (not-eq @minimumParticipants @role)}}
<li data-test-sidebar-user={{'peer.id'}} class='user'>
<p>No {{@user}} in the stream</p>
</li>
{{else}}

{{#each @peers as |peer|}}
{{#if (eq peer.roleName @role)}}
<li data-test-sidebar-user={{peer.id}} class='user'>
<p>{{peer.name}}</p>
{{#if
(or
(eq this.liveService.localPeer.roleName this.ROLES.host)
(eq this.liveService.localPeer.roleName this.ROLES.moderator)
)
}}
<button
type='button'
class='user__btn'
{{on 'click' (fn @openKickoutModal peer)}}
>
<IconifyIcon
data-test-icon='remove'
@icon='material-symbols:person-remove'
width='36'
height='36'
color='red'
/>
</button>
{{/if}}
</li>
{{/if}}
{{/each}}
{{/if}}

</ul>
</div>
11 changes: 11 additions & 0 deletions app/components/live-participants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Component from '@glimmer/component';
import { ROLES } from '../constants/live';
import { getOwner } from '@ember/application';

export default class LiveParticipantsComponent extends Component {
ROLES = ROLES;

get liveService() {
return getOwner(this).lookup('service:live');
}
}
57 changes: 21 additions & 36 deletions app/components/live-sidebar.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -40,41 +40,26 @@
{{/each}}
is presenting</span>
</div>
<div data-test-sidebar-body-role class='body__role-user'>
<p
data-test-sidebar-body-role-guest
class='role-user__type guestUsers'
>Guest Users</p>
<ul>

{{#each @peers as |peer|}}
{{#if (eq peer.roleName this.ROLES.guest)}}
<li data-test-sidebar-user={{peer.id}} class='user'>
<p>{{peer.name}}</p>
{{#if
(or
(eq this.liveService.localPeer.roleName this.ROLES.host)
(eq this.liveService.localPeer.roleName this.ROLES.moderator)
)
}}
<button
type='button'
class='user__btn'
{{on 'click' (fn @openKickoutModal peer)}}
>
<IconifyIcon
data-test-icon='remove'
@icon='material-symbols:person-remove'
width='36'
height='36'
color='red'
/>
</button>
{{/if}}
</li>
{{/if}}
{{/each}}
</ul>
</div>
<LiveParticipants
@user='Mavens'
@role='maven'
@peers={{@peers}}
@minimumParticipants={{this.liveService.mavenRole}}
@openKickoutModal={{@openKickoutModal}}
/>
<LiveParticipants
@user='Moderators'
@role='moderator'
@peers={{@peers}}
@minimumParticipants={{this.liveService.moderatorRole}}
@openKickoutModal={{@openKickoutModal}}
/>
<LiveParticipants
@user='Guests'
@role='guest'
@peers={{@peers}}
@minimumParticipants={{this.liveService.guestRole}}
@openKickoutModal={{@openKickoutModal}}
/>
</div>
</div>
8 changes: 5 additions & 3 deletions app/components/live-sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import { getOwner } from '@ember/application';
export default class LiveHeaderComponent extends Component {
@tracked isSideBarOpen = false;
ROLES = ROLES;
get liveService() {
return getOwner(this).lookup('service:live');
}

@action toggleMobileSidebar() {
this.isSideBarOpen = !this.isSideBarOpen;
}

get liveService() {
return getOwner(this).lookup('service:live');
}
}
10 changes: 10 additions & 0 deletions app/services/live.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export default class LiveService extends Service {
@globalRef('videoEl') videoEl;
@tracked peers;
@tracked isScreenShareOn;
@tracked mavenRole = '';
@tracked moderatorRole = '';
@tracked guestRole = '';
@tracked roomCodesForMaven = [];
@tracked roomCodeLoading = false;
@tracked userData = this.login?.userData;
Expand Down Expand Up @@ -360,6 +363,13 @@ export default class LiveService extends Service {

async renderScreenVideoToPeers(peers) {
this.peers = peers;
const maven = peers.find((peer) => peer.roleName === ROLES.maven);
const moderator = peers.find((peer) => peer.roleName === ROLES.moderator);
const guest = peers.find((peer) => peer.roleName === ROLES.guest);
this.mavenRole = maven?.roleName;
this.moderatorRole = moderator?.roleName;
this.guestRole = guest?.roleName;

const presenterTrackId = peers?.find((p) => p.roleName === ROLES.host)
?.auxiliaryTracks[0];
if (presenterTrackId) {
Expand Down
61 changes: 61 additions & 0 deletions tests/constants/participants-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
export const hostPeer = [
{
id: 1,
name: 'Ankush',
roleName: 'host',
},
];

export const mavenPeerData = [
{
id: 1,
name: 'Ankush',
roleName: 'host',
},
{
id: 2,
name: 'Maven1',
roleName: 'maven',
},
{
id: 3,
name: 'Maven2',
roleName: 'maven',
},
];

export const moderatorData = [
{
id: 1,
name: 'Ankush',
roleName: 'host',
},
{
id: 2,
name: 'Mod1',
roleName: 'moderator',
},
{
id: 3,
name: 'Mod3',
roleName: 'moderator',
},
];

export const guestData = [
{
id: 1,
name: 'Ankush',
roleName: 'host',
},
{
id: 2,
name: 'Guest1',
roleName: 'guest',
},
{
id: 3,
name: 'Guest2',
roleName: 'guest',
},
];
133 changes: 133 additions & 0 deletions tests/integration/components/live-participants-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'website-www/tests/helpers';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import {
hostPeer,
mavenPeerData,
moderatorData,
guestData,
} from '../../constants/participants-data';

module('Integration | Component | live-participants', function (hooks) {
setupRenderingTest(hooks);
test('renders No Maven In the stream Text', async function (assert) {
this.setProperties({
peers: hostPeer,
profilePic: 'profilepicurl',
isKickoutModalOpen: true,
});
this.set('openKickoutModal', () => {
this.isKickoutModalOpen = true;
});
await render(hbs`<LiveParticipants
@user='Mavens'
@role='maven'
@peers={{this.peers}}
@minimumParticipants=""
@openKickoutModal={{this.openKickoutModal}}
/>`);
assert
.dom('[data-test-sidebar-body-role] .user')
.hasText('No Mavens in the stream');
});

test('renders No Moderators In the stream Text', async function (assert) {
this.setProperties({
peers: hostPeer,
profilePic: 'profilepicurl',
isKickoutModalOpen: true,
});
this.set('openKickoutModal', () => {
this.isKickoutModalOpen = true;
});
await render(hbs` <LiveParticipants
@user='Moderators'
@role='moderator'
@peers={{this.peers}}
@minimumParticipants=""
@openKickoutModal={{this.openKickoutModal}}
/>`);
assert
.dom('[data-test-sidebar-body-role] .user')
.hasText('No Moderators in the stream');
});

test('renders No Guests In the stream Text', async function (assert) {
this.setProperties({
peers: hostPeer,
profilePic: 'profilepicurl',
isKickoutModalOpen: true,
});
this.set('openKickoutModal', () => {
this.isKickoutModalOpen = true;
});
await render(hbs` <LiveParticipants
@user='Guests'
@role='guest'
@peers={{@peers}}
@minimumParticipants=""
@openKickoutModal={{this.openKickoutModal}}
/>`);
assert
.dom('[data-test-sidebar-body-role] .user')
.hasText('No Guests in the stream');
});

test('renders Mavens Lists who joined Stream', async function (assert) {
this.setProperties({
peers: mavenPeerData,
profilePic: 'profilepicurl',
isKickoutModalOpen: true,
});
this.set('openKickoutModal', () => {
this.isKickoutModalOpen = true;
});
await render(hbs`<LiveParticipants
@user='Mavens'
@role='maven'
@peers={{this.peers}}
@minimumParticipants="maven"
@openKickoutModal={{this.openKickoutModal}}
/>`);
assert.dom('[data-test-sidebar-user="2"]').hasText('Maven1');
});

test('renders Moderators Lists who joined Stream', async function (assert) {
this.setProperties({
peers: moderatorData,
profilePic: 'profilepicurl',
isKickoutModalOpen: true,
});
this.set('openKickoutModal', () => {
this.isKickoutModalOpen = true;
});
await render(hbs`<LiveParticipants
@user='Moderator'
@role='moderator'
@peers={{this.peers}}
@minimumParticipants="moderator"
@openKickoutModal={{this.openKickoutModal}}
/>`);
assert.dom('[data-test-sidebar-user="3"]').hasText('Mod3');
});

test('renders Guests Lists who joined Stream', async function (assert) {
this.setProperties({
peers: guestData,
profilePic: 'profilepicurl',
isKickoutModalOpen: true,
});
this.set('openKickoutModal', () => {
this.isKickoutModalOpen = true;
});
await render(hbs`<LiveParticipants
@user='Guest'
@role='guest'
@peers={{this.peers}}
@minimumParticipants="guest"
@openKickoutModal={{this.openKickoutModal}}
/>`);
assert.dom('[data-test-sidebar-user="3"]').hasText('Guest2');
});
});
14 changes: 1 addition & 13 deletions tests/integration/components/live-sidebar-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module('Integration | Component | live-sidebar', function (hooks) {
setupRenderingTest(hooks);

test('live-sidebar renders', async function (assert) {
assert.expect(17);
assert.expect(12);
this.setProperties({
peers: [
{
Expand Down Expand Up @@ -48,17 +48,5 @@ module('Integration | Component | live-sidebar', function (hooks) {

assert.dom('[data-test-sidebar-host-name]').exists();
assert.dom('[data-test-sidebar-host-name]').hasText('Ankush is presenting');

assert.dom('[data-test-sidebar-body-role]').exists();

assert.dom('[data-test-sidebar-body-role-guest]').exists();
assert.dom('[data-test-sidebar-body-role-guest]').hasText('Guest Users');

assert.dom('[data-test-sidebar-user="2"]').exists();
assert.strictEqual(
document.querySelector(`[data-test-sidebar-user="2"]`).innerText,
this.peers[1].name,
'guest name is same!'
);
});
});

0 comments on commit d90578a

Please sign in to comment.