Skip to content

Commit 729c61a

Browse files
committed
Button that allows moderators to lower someone else's hand
1 parent 4ce9a23 commit 729c61a

File tree

8 files changed

+61
-11
lines changed

8 files changed

+61
-11
lines changed

backend/src/main/java/urjc/ovteaching/OpenViduComponent.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,15 @@
3333
import org.apache.http.ssl.SSLContextBuilder;
3434
import org.apache.http.ssl.TrustStrategy;
3535
import org.apache.http.util.EntityUtils;
36+
import org.json.simple.JSONArray;
37+
import org.json.simple.JSONObject;
3638
import org.springframework.beans.factory.annotation.Autowired;
3739
import org.springframework.beans.factory.annotation.Value;
3840
import org.springframework.stereotype.Component;
3941

4042
import com.google.gson.Gson;
43+
import com.google.gson.JsonArray;
44+
import com.google.gson.JsonElement;
4145
import com.google.gson.JsonObject;
4246

4347
import io.openvidu.java.client.OpenVidu;
@@ -215,20 +219,21 @@ public String stopRecording(Room room) {
215219
return null;
216220
}
217221

218-
public void sendSignalToEveryone(Room room, String type, String data) throws UnsupportedEncodingException, IOException {
222+
public void sendSignal(Room room, JsonArray to, String type, JsonObject data) throws UnsupportedEncodingException, IOException {
219223
Session session = this.roomIdSession.get(room.getId());
220224

221225
HttpPost request = new HttpPost(this.OPENVIDU_URL + "/api/signal");
222226

223227
JsonObject json = new JsonObject();
224228
json.addProperty("session", session.getSessionId());
229+
json.add("to", to);
225230
json.addProperty("type", "signal:" + type);
226-
json.addProperty("data", data);
231+
json.addProperty("data", data.toString());
227232

228233
StringEntity params = new StringEntity(json.toString());
229234
request.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
230235
request.setEntity(params);
231-
236+
232237
HttpResponse response = this.httpClient.execute(request);
233238
try {
234239
int statusCode = response.getStatusLine().getStatusCode();

backend/src/main/java/urjc/ovteaching/rooms/controllers/OpenViduController.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package urjc.ovteaching.rooms.controllers;
22

33
import java.io.IOException;
4+
import java.util.HashSet;
45

56
import javax.servlet.http.HttpServletRequest;
67

8+
import org.json.simple.JSONArray;
79
import org.json.simple.JSONObject;
10+
import org.json.simple.parser.JSONParser;
811
import org.springframework.beans.factory.annotation.Autowired;
912
import org.springframework.http.HttpStatus;
1013
import org.springframework.http.ResponseEntity;
@@ -17,6 +20,9 @@
1720
import org.springframework.web.bind.annotation.RequestMapping;
1821
import org.springframework.web.bind.annotation.RestController;
1922

23+
import com.google.gson.Gson;
24+
import com.google.gson.JsonObject;
25+
2026
import io.openvidu.java.client.OpenViduHttpException;
2127
import io.openvidu.java.client.OpenViduJavaClientException;
2228
import urjc.ovteaching.OpenViduComponent;
@@ -237,7 +243,7 @@ public ResponseEntity<String> stopRecording(@PathVariable String roomName, HttpS
237243
* @return HttpStatus of the operation
238244
*/
239245
@PostMapping("/room/{roomName}/signal/{type}")
240-
public ResponseEntity<?> sendSignal(@PathVariable String roomName, @PathVariable String type, @RequestBody JSONObject data, HttpServletRequest request) {
246+
public ResponseEntity<?> sendSignal(@PathVariable String roomName, @PathVariable String type, @RequestBody JSONObject body, HttpServletRequest request) {
241247
if (!request.isUserInRole("USER")) { // User not logged
242248
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
243249
}
@@ -257,7 +263,8 @@ public ResponseEntity<?> sendSignal(@PathVariable String roomName, @PathVariable
257263
}
258264

259265
try {
260-
this.openViduComponent.sendSignalToEveryone(room, type, data.toString());
266+
JsonObject gsonBody = new Gson().fromJson(body.toString(), JsonObject.class);
267+
this.openViduComponent.sendSignal(room, gsonBody.getAsJsonArray("to"), type, gsonBody.getAsJsonObject("data"));
261268
} catch (IOException e) {
262269
System.err.println(e.toString());
263270
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);

backend/src/main/java/urjc/ovteaching/rooms/controllers/RoomController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public ResponseEntity<Integer> raiseHand(@PathVariable String roomName, @Request
248248
* @return the httpStatus of the operation
249249
*/
250250
@DeleteMapping("/room/{roomName}/raiseHand")
251-
public ResponseEntity<?> lowerHand(@PathVariable String roomName, @RequestBody JSONObject connectionId, HttpServletRequest request) {
251+
public ResponseEntity<?> lowerHand(@PathVariable String roomName, @RequestBody JSONObject body, HttpServletRequest request) {
252252
if (!request.isUserInRole("USER")) {
253253
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
254254
}
@@ -259,7 +259,7 @@ public ResponseEntity<?> lowerHand(@PathVariable String roomName, @RequestBody J
259259
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
260260
}
261261
if (room.isInRoom(user)) {
262-
boolean wasRemoved = room.removeHandRaisedUser(connectionId);
262+
boolean wasRemoved = room.removeHandRaisedUser(body);
263263
this.roomServ.save(room);
264264
if(wasRemoved) {
265265
return new ResponseEntity<>(HttpStatus.OK);

frontend/src/app/shared/components/popup/popup.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
<mat-card-content *ngIf="this.content">
99
{{this.content}}
1010
</mat-card-content>
11+
<button mat-flat-button *ngIf="isRaiseHand && userSrv.isModOfRoom(roomName)" (click)="sendSignalLowerHand()" color="primary">Lower their hand</button>
1112
</mat-card>

frontend/src/app/shared/components/popup/popup.component.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { OpenViduService } from './../../services/open-vidu.service';
2+
import { UserService } from './../../services/user.service';
13
import { Component, OnInit, Input } from '@angular/core';
24

35
@Component({
@@ -12,11 +14,17 @@ export class PopupComponent implements OnInit {
1214
@Input() userAvatar: string;
1315
@Input() content: string;
1416
@Input() color: string;
17+
@Input() isRaiseHand: boolean;
18+
@Input() roomName: string;
19+
@Input() connectionId: string;
1520

1621
backgroundColor: string;
1722
letterColor: string;
1823

19-
constructor() { }
24+
constructor(
25+
private userSrv: UserService,
26+
private openviduSrv: OpenViduService
27+
) { }
2028

2129
ngOnInit() {
2230
if(this.color==='dark') {
@@ -30,4 +38,11 @@ export class PopupComponent implements OnInit {
3038
this.letterColor = 'rgb(0, 0, 0)';
3139
}
3240
}
41+
42+
sendSignalLowerHand() {
43+
this.openviduSrv.sendSignal(this.roomName, 'lowerYourHand', [this.connectionId],{}).subscribe(
44+
(_) => {},
45+
error => console.error(error)
46+
);
47+
}
3348
}

frontend/src/app/shared/services/open-vidu.service.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,17 @@ export class OpenViduService {
8888
});
8989
}
9090

91+
sendSignal(roomName: string, type: string, to: string[], data: any) {
92+
const body = {
93+
to: to,
94+
data: data
95+
}
96+
return this.http.post(this.baseURL + '/room/' + roomName + '/signal/' + type, body)
97+
.pipe(
98+
catchError(error => this.handleError(error))
99+
);
100+
}
101+
91102
private handleError(error: any) {
92103
console.error(error);
93104
return Observable.throw("Server error (" + error.status + "): " + error.message)

frontend/src/app/video-room/video-room.component.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@
116116
[userName]="notification.nickname"
117117
[userAvatar]="notification.userAvatar"
118118
[content]="notification.content"
119-
[color]="notification.color">
119+
[color]="notification.color"
120+
[isRaiseHand]="false"
121+
[roomName]="this.mySessionId"
122+
[connectionId]="undefined">
120123
</popup-component>
121124

122125
<popup-component
@@ -129,7 +132,10 @@
129132
[userName]="handsRaised[0].nickname"
130133
[userAvatar]="handsRaised[0].avatar"
131134
[content]="handsRaisedMessage"
132-
[color]="'accent'">
135+
[color]="'accent'"
136+
[isRaiseHand]="true"
137+
[roomName]="this.mySessionId"
138+
[connectionId]="handsRaised[0].connectionId">
133139
</popup-component>
134140

135141
<div id="layout" class="bounds" [class.boundsLight]="lightTheme">

frontend/src/app/video-room/video-room.component.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,12 @@ export class VideoRoomComponent implements OnInit, OnDestroy {
777777
this.session.on('signal:lowerYourHand', (event:any) => {
778778
if(event.from===undefined) {
779779
//Only do something if "from" is undefined, which means the signal was called by the backend
780-
this.raiseHand();
780+
this.roomService.lowerHand(this.mySessionId, this.localUsers[0].getConnectionId()).subscribe(
781+
(_) => {
782+
this.raiseHand();
783+
},
784+
error => console.error(error)
785+
);
781786
}
782787
});
783788
}

0 commit comments

Comments
 (0)