-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathVideoCallServiceImpl.java
More file actions
135 lines (106 loc) · 4.78 KB
/
VideoCallServiceImpl.java
File metadata and controls
135 lines (106 loc) · 4.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package com.iemr.common.service.videocall;
import org.apache.commons.lang.RandomStringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.sql.Timestamp;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.io.IOException;
import com.iemr.common.data.videocall.VideoCallParameters;
import com.iemr.common.mapper.videocall.VideoCallMapper;
import com.iemr.common.model.videocall.UpdateCallRequest;
import com.iemr.common.model.videocall.VideoCallRequest;
import com.iemr.common.repository.videocall.VideoCallParameterRepository;
import com.iemr.common.utils.config.ConfigProperties;
import com.iemr.common.utils.mapper.OutputMapper;
import com.iemr.common.utils.response.OutputResponse;
import org.springframework.beans.factory.annotation.Value;
@Service
public class VideoCallServiceImpl implements VideoCallService {
final Logger logger = LoggerFactory.getLogger(this.getClass().getName());
@Autowired
private VideoCallParameterRepository videoCallRepository;
@Autowired
private VideoCallMapper videoCallMapper;
private String meetingLink;
private boolean isLinkSent = false;
private String consultationStatus = "Not Initiated";
@Value("${video-call-url}")
private String jitsiLink;
public VideoCallServiceImpl() {
// this.jitsiLink = ConfigProperties.getPropertyByName("video-call-url");
// logger.info("Jitsi Link fetched: " + this.jitsiLink);
}
@Override
public String generateMeetingLink() {
logger.info("Jitsi Link: " + jitsiLink);
meetingLink=jitsiLink+"m="+RandomStringUtils.randomAlphanumeric(8);
logger.info("Meeting link: " + meetingLink);
return meetingLink;
}
@Override
public String sendMeetingLink(VideoCallRequest request) throws Exception {
OutputResponse response = new OutputResponse();
if (meetingLink == null || meetingLink.isEmpty()) {
throw new Exception("Meeting link not generated yet.");
}
isLinkSent = true;
VideoCallParameters videoCallEntity = videoCallMapper.videoCallToEntity(request);
videoCallEntity.setMeetingLink(meetingLink);
videoCallEntity.setLinkGeneratedAt(Timestamp.valueOf(LocalDateTime.now()));
videoCallEntity.setLinkUsed(false);
videoCallRepository.save(videoCallEntity);
VideoCallRequest responseData = videoCallMapper.videoCallToRequest(videoCallEntity);
response.setResponse(responseData.toJson());
return OutputMapper.gsonWithoutExposeRestriction()
.toJson(response);
}
@Override
public String updateCallStatus(UpdateCallRequest callRequest) throws Exception {
VideoCallParameters videoCall = null;
VideoCallParameters requestEntity = videoCallMapper.updateRequestToVideoCall(callRequest);
videoCall = videoCallRepository.findByMeetingLink(requestEntity.getMeetingLink());
int updateCount = videoCallRepository.updateCallStatusByMeetingLink(
requestEntity.getMeetingLink(),
requestEntity.getCallStatus(),
requestEntity.getCallDuration(),
requestEntity.getModifiedBy()
);
if (updateCount > 0) {
videoCall.setLinkUsed(true);
videoCallRepository.save(videoCall);
// if ("Completed".equalsIgnoreCase(requestEntity.getCallStatus())) {
// saveRecordingFile(videoCall.getMeetingLink());
// }
} else {
throw new Exception("Failed to update the call status");
}
return OutputMapper.gsonWithoutExposeRestriction()
.toJson(videoCallMapper.videoCallToResponse(videoCall));
}
private void saveRecordingFile(String meetingLink) {
try {
// Configurable Jibri recording location
String jibriOutputDir = ConfigProperties.getPropertyByName("jibri.output.path"); // e.g., /srv/jibri/recordings
String saveDir = ConfigProperties.getPropertyByName("video.recording.path"); // e.g., /srv/recordings
File jibriDir = new File(jibriOutputDir);
File[] matchingFiles = jibriDir.listFiles((dir, name) -> name.contains(meetingLink) && name.endsWith(".mp4"));
if (matchingFiles != null && matchingFiles.length > 0) {
File recording = matchingFiles[0];
Path targetPath = Paths.get(saveDir, meetingLink + ".mp4");
Files.copy(recording.toPath(), targetPath, StandardCopyOption.REPLACE_EXISTING);
logger.info("Recording file saved: " + targetPath);
} else {
logger.warn("No matching recording file found for meeting: " + meetingLink);
}
} catch (IOException e) {
logger.error("Error saving recording file: ", e);
}
}
}