fix Room bugs
This commit is contained in:
parent
5e8ccff93e
commit
d7bbdbf505
@ -5,6 +5,12 @@ namespace EnotaryoPH.Data.Entities
|
||||
[Table("LawyerVideoConferenceSchedule")]
|
||||
public class LawyerVideoConferenceSchedule
|
||||
{
|
||||
[Column("ServerCallID")]
|
||||
public string? ServerCallID { get; set; }
|
||||
|
||||
[Column("RecordingID")]
|
||||
public string? RecordingID { get; set; }
|
||||
|
||||
[Column("CreatedOn")]
|
||||
public DateTime? CreatedOn { get; set; }
|
||||
|
||||
|
@ -19,6 +19,7 @@ class VideoCall {
|
||||
this.onCreateLocalVideoStream = null;
|
||||
this.remoteParticipantStateChanged = null;
|
||||
this.remoteVideoIsAvailableChanged = null;
|
||||
this.onGetServerCallID = null;
|
||||
}
|
||||
|
||||
async init(userAccessToken, options) {
|
||||
@ -42,13 +43,6 @@ class VideoCall {
|
||||
this.localVideoStream = new LocalVideoStream(cameras[0]);
|
||||
}
|
||||
|
||||
async startLocalVideo() {
|
||||
if (this.localVideoStream) {
|
||||
//const localVideoOptions = new VideoStreamOptions();
|
||||
await this.callAgent.startCall([this.callAgent.identity], { video: [this.localVideoStream] });
|
||||
}
|
||||
}
|
||||
|
||||
stopLocalVideo() {
|
||||
if (this.call) {
|
||||
this.call.stopVideo(this.localVideoStream);
|
||||
@ -67,6 +61,21 @@ class VideoCall {
|
||||
const roomCallLocator = { roomId: roomId };
|
||||
let call = this.callAgent.join(roomCallLocator, { videoOptions });
|
||||
this.subscribeToCall(call);
|
||||
|
||||
this.callAgent.on('callsUpdated', e => {
|
||||
e.added.forEach((addedCall) => {
|
||||
addedCall.on('stateChanged', () => {
|
||||
if (addedCall.state === 'Connected') {
|
||||
debugger;
|
||||
addedCall.info.getServerCallId().then(result => {
|
||||
this.onGetServerCallID?.(result);
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Azure.Communication.CallAutomation" Version="1.3.0" />
|
||||
<PackageReference Include="Azure.Communication.Identity" Version="1.3.1" />
|
||||
<PackageReference Include="Azure.Communication.Rooms" Version="1.1.1" />
|
||||
<PackageReference Include="CompreFace.NET.Sdk" Version="1.0.2" />
|
||||
|
@ -77,7 +77,7 @@
|
||||
<input type="hidden" value="@JsonSerializer.Serialize(Model.Participants)" />
|
||||
|
||||
@section Scripts {
|
||||
<script type="text/javascript" src="~/dist/jfa.js"></script>
|
||||
<script type="text/javascript" src="/dist/_jfa.js"></script>
|
||||
<script>
|
||||
|
||||
let participants = JSON.parse('@Html.Raw(JsonSerializer.Serialize(Model.Participants))');
|
||||
@ -138,8 +138,21 @@
|
||||
e.el.querySelector('video').style['object-fit'] = 'cover';
|
||||
document.getElementById(participant.Id).appendChild(e.el);
|
||||
}
|
||||
},
|
||||
onGetServerCallID: function(e) {
|
||||
debugger;
|
||||
let url = jfa.utilities.routing.getCurrentURLWithHandler("StartRecording");
|
||||
debugger;
|
||||
url.searchParams.append("ServerCallID", e.serverCallId || "");
|
||||
jfa.utilities.request.post(url, {})
|
||||
.then(resp => {
|
||||
if (resp.ok === true) {
|
||||
jfa.page.reload();
|
||||
}
|
||||
})
|
||||
.catch(err => console.error(err));
|
||||
}
|
||||
}
|
||||
};
|
||||
await videoCall.init(userAccessToken, options);
|
||||
videoCall.joinRoom('@Model.CommunicationRoomId');
|
||||
}
|
||||
|
@ -1,7 +1,3 @@
|
||||
using Azure;
|
||||
using Azure.Communication;
|
||||
using Azure.Communication.Identity;
|
||||
using Azure.Communication.Rooms;
|
||||
using EnotaryoPH.Data;
|
||||
using EnotaryoPH.Data.Entities;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@ -11,83 +7,54 @@ namespace EnotaryoPH.Web.Pages.Participant.VideoCall
|
||||
{
|
||||
public class RoomModel : PageModel
|
||||
{
|
||||
private const string CONNECTION_STRING = "endpoint=https://comm-enotario.asiapacific.communication.azure.com/;accesskey=yqxq5mRByG8aPwZBiT/KFfx6Rr16RR280dC3GVkGaFVNXGk91sIDy04j5jrZfjDZAvdn0fjtyF0kGJPXMGgfKg==";
|
||||
private readonly IConferenceSheduleService _conferenceSheduleService;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly NotaryoDBContext _dbContext;
|
||||
private readonly ISession _session;
|
||||
private readonly CommunicationUserIdentifier? _user1;
|
||||
private readonly CommunicationUserIdentifier? _user2;
|
||||
private CommunicationIdentityClient? _communicationIdentityClient;
|
||||
private LawyerVideoConferenceSchedule _LawyerVideoConferenceSchedule;
|
||||
private Transaction _Transaction;
|
||||
|
||||
public RoomModel(IHttpContextAccessor httpContextAccessor, ICurrentUserService currentUserService, NotaryoDBContext dbContext)
|
||||
public RoomModel(ICurrentUserService currentUserService, NotaryoDBContext dbContext, IConferenceSheduleService conferenceSheduleService)
|
||||
{
|
||||
_session = httpContextAccessor.HttpContext.Session;
|
||||
_currentUserService = currentUserService;
|
||||
_dbContext = dbContext;
|
||||
_conferenceSheduleService = conferenceSheduleService;
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnGetAsync()
|
||||
{
|
||||
_Transaction = _dbContext.Transactions
|
||||
.Include(t => t.TransactionSignatories)
|
||||
.Include(t => t.Principal)
|
||||
.FirstOrDefault(t => t.Transaction_UID == Transaction_UID);
|
||||
if (_Transaction == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
_LawyerVideoConferenceSchedule = _dbContext.LawyerVideoConferenceSchedules
|
||||
.Include(meeting => meeting.LawyerVideoConferenceParticipants)
|
||||
.ThenInclude(p => p.Participant)
|
||||
.Include(meeting => meeting.Lawyer)
|
||||
.ThenInclude(l => l.User)
|
||||
.FirstOrDefault(meeting => meeting.TransactionID == _Transaction.TransactionID);
|
||||
|
||||
if (ShouldCreateRoom())
|
||||
var currentUser = _dbContext.Users.Single(u => u.User_UID == _currentUserService.GetUser_UID());
|
||||
var schedule_UID = await _conferenceSheduleService.GetOrCreateScheduleIDAsync(Transaction_UID);
|
||||
if (schedule_UID == Guid.Empty)
|
||||
{
|
||||
_LawyerVideoConferenceSchedule ??= new LawyerVideoConferenceSchedule
|
||||
if (_Transaction.PrincipalID == currentUser.UserID)
|
||||
{
|
||||
LawyerVideoConferenceSchedule_UID = Guid.CreateVersion7(),
|
||||
CreatedOn = DateTime.UtcNow,
|
||||
LawyerID = _Transaction.LawyerID.GetValueOrDefault(),
|
||||
TransactionID = _Transaction.TransactionID,
|
||||
};
|
||||
_LawyerVideoConferenceSchedule.MeetingDate = DateTime.UtcNow;
|
||||
_LawyerVideoConferenceSchedule.Status = nameof(VideoConferenceStatus.New);
|
||||
|
||||
var roomParticipants = new List<RoomParticipant>();
|
||||
foreach (var participant in _LawyerVideoConferenceSchedule.LawyerVideoConferenceParticipants)
|
||||
{
|
||||
var attendee = await CommunicationIdentityClient.CreateUserAsync();
|
||||
roomParticipants.Add(new RoomParticipant(attendee) { Role = ParticipantRole.Attendee });
|
||||
participant.MeetingRoomTokenID = await GetTokenResponse(attendee);
|
||||
participant.MeetingRoomUserID = attendee.Value.Id;
|
||||
return Redirect($"/Principal/TransactionStatus/{Transaction_UID}");
|
||||
}
|
||||
|
||||
var presenter = await CommunicationIdentityClient.CreateUserAsync();
|
||||
roomParticipants.Add(new RoomParticipant(presenter) { Role = ParticipantRole.Presenter });
|
||||
_LawyerVideoConferenceSchedule.MeetingRoomTokenID = await GetTokenResponse(presenter);
|
||||
_LawyerVideoConferenceSchedule.MeetingRoomUserID = presenter.Value.Id;
|
||||
|
||||
var roomsClient = new RoomsClient(CONNECTION_STRING);
|
||||
CommunicationRoom room = await roomsClient.CreateRoomAsync(DateTime.Now, DateTime.Now.AddHours(2), roomParticipants);
|
||||
|
||||
_LawyerVideoConferenceSchedule.MeetingRoomID = room.Id;
|
||||
|
||||
if (_LawyerVideoConferenceSchedule.LawyerVideoConferenceScheduleID == 0)
|
||||
if (currentUser.Role.IsInList(UserType.Principal, UserType.Witness))
|
||||
{
|
||||
_dbContext.Add(_LawyerVideoConferenceSchedule);
|
||||
return Redirect($"/Participant/VideoCall/Waiting/{Transaction_UID}");
|
||||
}
|
||||
else
|
||||
{
|
||||
_dbContext.Update(_LawyerVideoConferenceSchedule);
|
||||
}
|
||||
_dbContext.SaveChanges();
|
||||
|
||||
return Redirect("/");
|
||||
}
|
||||
|
||||
var currentUser = _dbContext.Users.FirstOrDefault(u => u.User_UID == _currentUserService.GetUser_UID());
|
||||
_LawyerVideoConferenceSchedule = _dbContext.LawyerVideoConferenceSchedules
|
||||
.Include(sched => sched.LawyerVideoConferenceParticipants)
|
||||
.ThenInclude(p => p.Participant)
|
||||
.Include(sched => sched.Lawyer)
|
||||
.ThenInclude(l => l.User)
|
||||
.FirstOrDefault(sched => sched.LawyerVideoConferenceSchedule_UID == schedule_UID);
|
||||
|
||||
CommunicationUserToken = currentUser.Role == nameof(UserType.Notary)
|
||||
? _LawyerVideoConferenceSchedule.MeetingRoomTokenID
|
||||
: _LawyerVideoConferenceSchedule.LawyerVideoConferenceParticipants.First(u => u.ParticipantID == currentUser.UserID).MeetingRoomTokenID;
|
||||
@ -96,53 +63,47 @@ namespace EnotaryoPH.Web.Pages.Participant.VideoCall
|
||||
? _LawyerVideoConferenceSchedule.MeetingRoomUserID
|
||||
: _LawyerVideoConferenceSchedule.LawyerVideoConferenceParticipants.First(u => u.ParticipantID == currentUser.UserID).MeetingRoomUserID;
|
||||
|
||||
|
||||
return Page();
|
||||
}
|
||||
|
||||
private static string GetHashCode(string stringValue) => stringValue.GetHashCode().ToString("X8");
|
||||
|
||||
private async Task<string> GetTokenResponse(Response<CommunicationUserIdentifier> user)
|
||||
{
|
||||
var tokenResponse = await CommunicationIdentityClient.GetTokenAsync(user, new[] { CommunicationTokenScope.VoIP });
|
||||
return tokenResponse.Value.Token;
|
||||
}
|
||||
|
||||
private bool ShouldCreateRoom() => _LawyerVideoConferenceSchedule == null || DateTime.UtcNow.Subtract(_LawyerVideoConferenceSchedule.MeetingDate).TotalHours > 1 || _LawyerVideoConferenceSchedule.LawyerVideoConferenceParticipants.Any(p => string.IsNullOrEmpty(p.MeetingRoomTokenID));
|
||||
public async Task OnPostStartRecordingAsync() => await _conferenceSheduleService.StartRecordingAsync(Transaction_UID);
|
||||
|
||||
public string CommunicationRoomId { get; private set; }
|
||||
public string CommunicationUserToken { get; private set; }
|
||||
|
||||
public string CommunicationUserId { get; set; }
|
||||
|
||||
public string CommunicationUserToken { get; private set; }
|
||||
|
||||
public List<RoomParticipantViewModel> Participants
|
||||
{
|
||||
get
|
||||
{
|
||||
var signatoryTypes = _Transaction.TransactionSignatories.Where(t => t.UserID > 0).ToDictionary(k => k.UserID, v => v.Type);
|
||||
var dic = _LawyerVideoConferenceSchedule.LawyerVideoConferenceParticipants.ConvertAll(p => new RoomParticipantViewModel
|
||||
var participants = _LawyerVideoConferenceSchedule.LawyerVideoConferenceParticipants.ConvertAll(p => new RoomParticipantViewModel
|
||||
{
|
||||
Id = p.LawyerVideoConferenceParticipant_UID.ToString(),
|
||||
DisplayName = $"{p.Participant.Firstname} {p.Participant.Lastname}",
|
||||
DisplayName = $"{p.Participant.Firstname} {p.Participant.Lastname}".Trim().DefaultIfEmpty(p.Participant.Email),
|
||||
RoomUserID = p.MeetingRoomUserID,
|
||||
Type = signatoryTypes.GetValueOrDefault(p.ParticipantID, nameof(UserType.Principal))
|
||||
});
|
||||
|
||||
var host = _LawyerVideoConferenceSchedule.Lawyer.User;
|
||||
dic.Add(new RoomParticipantViewModel
|
||||
participants.Add(new RoomParticipantViewModel
|
||||
{
|
||||
DisplayName = $"{host.Firstname} {host.Lastname}",
|
||||
DisplayName = $"{host.Firstname} {host.Lastname}".Trim().DefaultIfEmpty(host.Email),
|
||||
Id = Guid.Empty.ToString(),
|
||||
RoomUserID = _LawyerVideoConferenceSchedule.MeetingRoomUserID,
|
||||
Type = nameof(UserType.Notary)
|
||||
});
|
||||
|
||||
return dic;
|
||||
return participants;
|
||||
}
|
||||
}
|
||||
|
||||
[BindProperty(SupportsGet = true)]
|
||||
public Guid Transaction_UID { get; set; }
|
||||
public string ServerCallingID { get; set; }
|
||||
|
||||
private CommunicationIdentityClient CommunicationIdentityClient => _communicationIdentityClient ??= new CommunicationIdentityClient(CONNECTION_STRING);
|
||||
[BindProperty(SupportsGet = true)]
|
||||
public Guid Transaction_UID { get; set; }
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user