Skip to content

Commit a8c2a5c

Browse files
authored
feature-8987 - Implement dedicated Rocket Chat rooms for each video r… (#8998)
* feature-8987 - Implement dedicated Rocket Chat rooms for each video room and make them ready for mobile view * feature-8987 + feature-9004 * feature-8987 + feature-9004 * feature-8987: Implement dedicated Rocket Chat rooms for each video room * feature-8987 close chat pannel when switch room * feature-8987 close chat pannel when switch room * fix conflict
1 parent fb98fd2 commit a8c2a5c

File tree

15 files changed

+176
-46
lines changed

15 files changed

+176
-46
lines changed

app/components/public/stream/chat-panel.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<h3>Unable to login to chat. Please contact the administrator</h3>
1212
{{/if}}
1313
{{#if this.token}}
14-
<Public::Stream::Chat @token={{this.token}} @embedded={{true}} @event={{@event}} />
14+
<Public::Stream::Chat @token={{this.token}} @embedded={{true}} @event={{@event}} @currentRoom={{@currentRoom}} />
1515
{{/if}}
1616
{{/if}}
1717
</div>

app/components/public/stream/chat-panel.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { action } from '@ember/object';
88
interface Args {
99
event: Event
1010
shown: boolean
11+
currentRoom: any
1112
}
1213
export default class PublicStreamChatPanel extends Component<Args> {
1314
@service declare loader: Loader;
@@ -18,9 +19,16 @@ export default class PublicStreamChatPanel extends Component<Args> {
1819

1920
@action
2021
async setup(): Promise<void> {
21-
const { success, token } = await this.loader.load(`/events/${this.args.event.id}/chat-token`);
22-
this.token = token;
23-
this.success = success;
24-
this.loading = false;
22+
if (this.args.currentRoom && this.args.currentRoom.isChatEnabled) {
23+
const { success, token } = await this.loader.load(`/events/${this.args.event.id}/room/${this.args.currentRoom.microlocationId}/chat-token`);
24+
this.token = token;
25+
this.success = success;
26+
this.loading = false;
27+
} else {
28+
const { success, token } = await this.loader.load(`/events/${this.args.event.id}/chat-token`);
29+
this.token = token;
30+
this.success = success;
31+
this.loading = false;
32+
}
2533
}
2634
}

app/components/public/stream/chat.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import Event from 'open-event-frontend/models/event';
77
interface Args {
88
token: string,
99
embedded: boolean,
10-
event: Event
10+
event: Event,
11+
currentRoom: any,
1112
}
1213

1314
export default class PublicStreamChat extends Component<Args> {
@@ -16,6 +17,10 @@ export default class PublicStreamChat extends Component<Args> {
1617

1718
@action
1819
init(): void {
19-
this.iframeUrl = this.settings.rocketChatUrl + `/group/${this.args.event.chatRoomName}?resumeToken=${this.args.token}` + (this.args.embedded ? '&layout=embedded' : '');
20+
let room_name = this.args.event.chatRoomName;
21+
if (this.args.currentRoom && this.args.currentRoom.isChatEnabled) {
22+
room_name = this.args.currentRoom.chatRoomName
23+
}
24+
this.iframeUrl = this.settings.rocketChatUrl + `/group/${room_name}?resumeToken=${this.args.token}` + (this.args.embedded ? '&layout=embedded' : '');
2025
}
2126
}

app/components/public/stream/side-panel.hbs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<button {{did-insert this.setup}} class="ui icon button stream-side-panel-button" {{action (mut this.shown) true}}>
22
<i class="angle right icon"></i>
33
</button>
4-
{{#if this.showChat}}
4+
{{#if this.isChatShowing}}
55
<div class="ui chat-stream-side-panel-button right">
66
<i class="rocketchat large icon p-4 chat-panel-icon" {{on "click" @showChatPanel}} role="button"></i>
77
</div>
@@ -42,14 +42,12 @@
4242
{{t 'Exhibition'}}</span>
4343
</a>
4444
{{/if}}
45-
46-
{{#if this.showChat}}
45+
{{#if (and @event.isChatEnabled this.settings.rocketChatUrl (or @currentRoom.isChatEnabled @currentRoom.isGlobalEventRoom))}}
4746
<a href="#" class="ui labeled icon item" role="button" {{on "click" @showChatPanel}}>
4847
<span><i class="comment icon"></i>
4948
{{t 'Chat'}}</span>
5049
</a>
5150
{{/if}}
52-
5351
{{#if this.showVideoRoom}}
5452
<div class="item">
5553
<span><i class="video icon"></i>
@@ -60,7 +58,7 @@
6058
{{#if this.showVideoRoom}}
6159
<div class="ui inverted vertical fluid menu borderless stream-side-menu" style="margin-top: -20px;">
6260
{{#each this.streams as |stream index|}}
63-
<a href={{href-to 'public.stream.view' @event stream.slugName stream.id}} class="{{if (eq @videoStream.id stream.id) 'video-active'}} item stream-item d-flex items-center">
61+
<a href={{href-to 'public.stream.view' @event stream.slugName stream.id }} class="{{if (eq @currentRoom.microlocationId stream.microlocationId) 'video-active'}} item stream-item d-flex items-center" {{on "click" (fn @setupRoomChat stream) }}>
6462

6563
<span class="stream-preview-letter" style={{css background-color=(object-at (abs (mod stream.hash this.colors.length)) this.colors)}}>{{truncate (uppercase stream.name) 1 false}}</span>
6664
<span class="ml-2">{{stream.name}}</span>

app/components/public/stream/side-panel.ts

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Component from '@glimmer/component';
22
import VideoStream from 'open-event-frontend/models/video-stream';
33
import { tracked } from '@glimmer/tracking';
4-
import { action } from '@ember/object';
4+
import { action, computed } from '@ember/object';
55
import Event from 'open-event-frontend/models/event';
66
import { inject as service } from '@ember/service';
77
import { slugify, stringHashCode } from 'open-event-frontend/utils/text';
@@ -14,6 +14,9 @@ interface Args {
1414
event: Event,
1515
shown: boolean,
1616
showChatPanel: any,
17+
currentRoom: any,
18+
streamId: number,
19+
setupRoomChat: ((stream: any) => void),
1720
}
1821

1922
interface ChannelData {
@@ -41,6 +44,7 @@ export default class PublicStreamSidePanel extends Component<Args> {
4144
@tracked showSpeakers: number | null = null;
4245
@tracked showExhibitors: number | null = null;
4346
@tracked showChat = false;
47+
@tracked showRoomChat = false;
4448
@tracked showVideoRoom = false;
4549

4650
@tracked translationChannels = [{
@@ -87,6 +91,14 @@ export default class PublicStreamSidePanel extends Component<Args> {
8791
this.showExhibitors = this.showExhibitors ?? await hasExhibitors(this.loader, this.args.event);
8892
}
8993

94+
@computed('args.currentRoom')
95+
get isChatShowing(): boolean {
96+
if (this.args.currentRoom) {
97+
return this.args.event.isChatEnabled && this.settings.rocketChatUrl && (this.args.currentRoom.isChatEnabled || this.args.currentRoom.isGlobalEventRoom);
98+
}
99+
return false
100+
}
101+
90102
addStream(stream: VideoStream | null): void {
91103
if (!stream) {return;}
92104
if (this.streams.map(stream => stream.id).any(id => id === stream.id)) {return;}
@@ -100,7 +112,9 @@ export default class PublicStreamSidePanel extends Component<Args> {
100112

101113
@action
102114
async setup(): Promise<void> {
103-
this.fetchTranslationChannels(this.args.videoStream.id);
115+
if (this.args.videoStream) {
116+
this.fetchTranslationChannels(this.args.videoStream.id);
117+
}
104118
this.shown = this.args.shown || Boolean(new URLSearchParams(location.search).get('side_panel'));
105119
this.addStream(this.args.event.belongsTo('videoStream').value());
106120

@@ -112,23 +126,31 @@ export default class PublicStreamSidePanel extends Component<Args> {
112126

113127
if (this.args.event.isSchedulePublished) {
114128
try {
115-
const rooms = await this.loader.load(`/events/${this.args.event.identifier}/microlocations?include=video-stream&fields[microlocation]=id,video_stream,position&fields[video-stream]=id,name&sort=position`);
129+
const rooms = await this.loader.load(`/events/${this.args.event.identifier}/microlocations?include=video-stream&fields[microlocation]=id,name,video_stream,position,is_chat_enabled,chat_room_name,is_global_event_room&fields[video-stream]=id,name&sort=position`);
116130
rooms.included?.map((stream: any) => ({
117-
id : stream.id,
118-
name : stream.attributes.name,
119-
slugName : slugify(stream.attributes.name),
120-
hash : stringHashCode(stream.attributes.name + stream.id)
131+
id : stream.id,
132+
name : stream.attributes.name,
133+
roomName : rooms.data.filter((room: any) => room.relationships['video-stream'].data ? room.relationships['video-stream'].data.id === stream.id : null).map((room: any) => room.attributes.name)[0],
134+
slugName : slugify(rooms.data.filter((room: any) => room.relationships['video-stream'].data ? room.relationships['video-stream'].data.id === stream.id : null).map((room: any) => room.attributes['chat-room-name'])[0]),
135+
isChatEnabled : rooms.data.filter((room: any) => room.relationships['video-stream'].data ? room.relationships['video-stream'].data.id === stream.id : null).map((room: any) => room.attributes['is-chat-enabled'])[0],
136+
isGlobalEventRoom : rooms.data.filter((room: any) => room.relationships['video-stream'].data ? room.relationships['video-stream'].data.id === stream.id : null).map((room: any) => room.attributes['is-global-event-room'])[0],
137+
chatRoomName : rooms.data.filter((room: any) => room.relationships['video-stream'].data ? room.relationships['video-stream'].data.id === stream.id : null).map((room: any) => room.attributes['chat-room-name'])[0],
138+
microlocationId : rooms.data.filter((room: any) => room.relationships['video-stream'].data ? room.relationships['video-stream'].data.id === stream.id : null).map((room: any) => room.id)[0],
139+
hash : stringHashCode(stream.attributes.name + stream.id)
121140
})).forEach((stream: any) => {
122141
this.addStream(stream)
123142
});
124143
} catch (e) {
125144
console.error('Error while loading rooms in video stream', e);
126145
}
127-
128146
if (this.args.event.isChatEnabled) {
129147
const { success, token } = await this.loader.load(`/events/${this.args.event.id}/chat-token`);
130148
this.token = token;
131149
this.success = success;
150+
if (this.args.streamId) {
151+
const microlocation = this.streams.find(stream => stream.id === this.args.streamId)
152+
this.args.setupRoomChat(microlocation)
153+
}
132154
}
133155

134156
this.loading = false;

app/components/public/stream/video-stream.hbs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@
2828
{{/if}}
2929
{{/if}}
3030
</div>
31-
<Public::Stream::SidePanel @event={{@event}} @videoStream={{@videoStream}} @selectingLanguage={{this.selectingLanguage}} @shown={{true}} @showChatPanel={{this.showChatPanel}} />
31+
<Public::Stream::SidePanel @event={{@event}} @videoStream={{@videoStream}} @selectingLanguage={{this.selectingLanguage}} @shown={{true}} @showChatPanel={{this.showChatPanel}} @setupRoomChat={{action 'setupRoomChat'}} @currentRoom={{this.currentRoom}} @streamId={{@streamId}}/>
32+
3233
{{#if this.isRocketChatEnabled}}
3334
{{#if this.shown}}
34-
<Public::Stream::ChatPanel @event={{@event}} @shown={{true}} @showChatPanel={{this.showChatPanel}} />
35+
<Public::Stream::ChatPanel @event={{@event}} @shown={{true}} @showChatPanel={{this.showChatPanel}} @currentRoom={{this.currentRoom}}/>
3536
{{else}}
36-
<Public::Stream::ChatPanel @event={{@event}} @shown={{false}} @showChatPanel={{this.showChatPanel}} />
37+
<Public::Stream::ChatPanel @event={{@event}} @shown={{false}} @showChatPanel={{this.showChatPanel}} @currentRoom={{this.currentRoom}}/>
3738
{{/if}}
3839
{{/if}}

app/components/public/stream/video-stream.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ declare global {
1414
interface Args {
1515
videoStream: VideoStream,
1616
event: Event,
17+
streamId: number,
1718
}
1819

1920
export default class PublicStreamVideoStream extends Component<Args> {
@@ -53,6 +54,9 @@ export default class PublicStreamVideoStream extends Component<Args> {
5354
@tracked
5455
shown = false;
5556

57+
@tracked
58+
currentRoom = null;
59+
5660
@tracked
5761
provider = '';
5862

@@ -174,6 +178,12 @@ export default class PublicStreamVideoStream extends Component<Args> {
174178
}
175179
}
176180

181+
@action
182+
async setupRoomChat(stream:any) {
183+
this.currentRoom = stream;
184+
this.shown = false;
185+
}
186+
177187
@action
178188
hideStreamYard() {
179189
this.selectingLanguage.setStreamYardVisibility(false);

app/controllers/events/view/chat.js

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,37 @@
11
import Controller from '@ember/controller';
2-
import { action } from '@ember/object';
2+
import { action, computed } from '@ember/object';
33

44
export default class extends Controller {
5+
6+
@computed('model.rooms.data')
7+
get rooms() {
8+
return this.model.rooms?.data;
9+
}
10+
11+
@action
12+
async changeRoomChatStatus(room) {
13+
room.isChatEnabled = !room.isChatEnabled;
14+
if (room.isGlobalEventRoom) {
15+
room.isGlobalEventRoom = !room.isGlobalEventRoom;
16+
}
17+
await room.save();
18+
}
19+
20+
@action
21+
async setGlobalEventRoom(room) {
22+
room.isGlobalEventRoom = !room.isGlobalEventRoom;
23+
if (room.isChatEnabled) {
24+
room.isChatEnabled = !room.isChatEnabled;
25+
}
26+
await room.save();
27+
}
28+
529
@action
630
async toggleChat() {
7-
this.set('model.isChatEnabled', !this.model.isChatEnabled);
31+
const { event } = this.model;
32+
this.set('model.event.isChatEnabled', !event.isChatEnabled);
833
try {
9-
await this.model.save();
34+
await event.save();
1035
} catch (error) {
1136
console.error('Error while enabling chat', error);
1237
}

app/controllers/public.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default class PublicController extends Controller {
1919
@tracked canAccess = null;
2020

2121
@tracked shown = false;
22+
@tracked currentRoom = null;
2223

2324
@computed('model.socialLinks')
2425
get twitterLink() {
@@ -203,4 +204,10 @@ export default class PublicController extends Controller {
203204
this.hasStreams = exists;
204205
this.canAccess = can_access;
205206
}
207+
208+
@action
209+
async setupRoomChat(stream) {
210+
this.currentRoom = stream;
211+
this.shown = false;
212+
}
206213
}

app/models/microlocation.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ export default class Microlocation extends ModelBase.extend({
99
hiddenInScheduler : attr('boolean', { defaultValue: false }),
1010
longitude : attr('number'),
1111
position : attr('number', { defaultValue: 0 }),
12-
13-
sessions : hasMany('session'),
14-
event : belongsTo('event'),
15-
videoStream : belongsTo('video-stream')
12+
isChatEnabled : attr('boolean', { defaultValue: false }),
13+
isGlobalEventRoom : attr('boolean', { defaultValue: false }),
14+
// chatRoomId : attr('string'),
15+
sessions : hasMany('session'),
16+
event : belongsTo('event'),
17+
videoStream : belongsTo('video-stream')
1618
}) {
1719

1820
get hasVideoStream(): boolean {

0 commit comments

Comments
 (0)