mirror of
https://github.com/fergalmoran/podnoms.git
synced 2025-12-22 09:18:08 +00:00
Refactor of the messy signalr hubs
This commit is contained in:
@@ -55,9 +55,9 @@ export class AppComponent implements OnInit {
|
|||||||
if (p) {
|
if (p) {
|
||||||
this._messagingService.getPermission();
|
this._messagingService.getPermission();
|
||||||
this._messagingService.receiveMessage();
|
this._messagingService.receiveMessage();
|
||||||
const chatterChannel = `${p.uid}_chatter`;
|
const chatterChannel = `${p.id}`;
|
||||||
this._signalrService
|
this._signalrService
|
||||||
.init('chatter')
|
.init('userupdates')
|
||||||
.then((r) => {
|
.then((r) => {
|
||||||
this._signalrService.connection.on(
|
this._signalrService.connection.on(
|
||||||
chatterChannel,
|
chatterChannel,
|
||||||
@@ -69,7 +69,7 @@ export class AppComponent implements OnInit {
|
|||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(
|
console.error(
|
||||||
'app.component',
|
'app.component',
|
||||||
'Unable to initialise chatter hub',
|
'Unable to initialise site update hub',
|
||||||
err
|
err
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ import { ModalModule } from 'ngx-bootstrap/modal';
|
|||||||
import { AuthGuard } from './services/auth.guard';
|
import { AuthGuard } from './services/auth.guard';
|
||||||
import { ImageService } from './services/image.service';
|
import { ImageService } from './services/image.service';
|
||||||
import { DebugService } from './services/debug.service';
|
import { DebugService } from './services/debug.service';
|
||||||
import { ChatterService } from './services/chatter.service';
|
|
||||||
import { DebugComponent } from './components/debug/debug.component';
|
import { DebugComponent } from './components/debug/debug.component';
|
||||||
import { InlineEditorModule } from '@qontu/ngx-inline-editor';
|
import { InlineEditorModule } from '@qontu/ngx-inline-editor';
|
||||||
import { SidebarComponent } from './components/sidebar/sidebar.component';
|
import { SidebarComponent } from './components/sidebar/sidebar.component';
|
||||||
@@ -208,7 +207,6 @@ export function provideConfig() {
|
|||||||
PushRegistrationService,
|
PushRegistrationService,
|
||||||
DebugService,
|
DebugService,
|
||||||
MessagingService,
|
MessagingService,
|
||||||
ChatterService,
|
|
||||||
AppInsightsService,
|
AppInsightsService,
|
||||||
JobsService,
|
JobsService,
|
||||||
AudioService,
|
AudioService,
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import { Component, OnInit } from '@angular/core';
|
|||||||
import { DebugService } from 'app/services/debug.service';
|
import { DebugService } from 'app/services/debug.service';
|
||||||
import { environment } from 'environments/environment';
|
import { environment } from 'environments/environment';
|
||||||
import { JobsService } from 'app/services/jobs.service';
|
import { JobsService } from 'app/services/jobs.service';
|
||||||
import { ChatterService } from 'app/services/chatter.service';
|
|
||||||
import { MessagingService } from 'app/services/messaging.service';
|
import { MessagingService } from 'app/services/messaging.service';
|
||||||
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
|
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
|
||||||
|
|
||||||
@@ -23,7 +22,6 @@ export class DebugComponent implements OnInit {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private _debugService: DebugService,
|
private _debugService: DebugService,
|
||||||
private _chatterService: ChatterService,
|
|
||||||
private _jobsService: JobsService,
|
private _jobsService: JobsService,
|
||||||
private _pushNotifications: MessagingService,
|
private _pushNotifications: MessagingService,
|
||||||
private _signalrService: SignalRService
|
private _signalrService: SignalRService
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ export class ProfileModel {
|
|||||||
email: string;
|
email: string;
|
||||||
name: string;
|
name: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
uid?: string;
|
|
||||||
profileImage?: string;
|
profileImage?: string;
|
||||||
apiKey: string;
|
apiKey: string;
|
||||||
firstName: string;
|
firstName: string;
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
import { Injectable } from '@angular/core';
|
|
||||||
import { environment } from 'environments/environment';
|
|
||||||
import { HttpClient } from '@angular/common/http';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class ChatterService {
|
|
||||||
constructor(private _http: HttpClient) {}
|
|
||||||
|
|
||||||
ping(message: string): any {
|
|
||||||
return this._http.post(
|
|
||||||
environment.API_HOST + '/chatter/ping',
|
|
||||||
JSON.stringify({ message: message })
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
using System.Linq;
|
|
||||||
using System.Security.Claims;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Microsoft.AspNetCore.Identity;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.SignalR;
|
|
||||||
using PodNoms.Api.Persistence;
|
|
||||||
using PodNoms.Api.Services.Auth;
|
|
||||||
using PodNoms.Api.Services.Hubs;
|
|
||||||
|
|
||||||
namespace PodNoms.Api.Controllers {
|
|
||||||
[Authorize]
|
|
||||||
[Route("[controller]")]
|
|
||||||
public class ChatterController : BaseAuthController {
|
|
||||||
private readonly HubLifetimeManager<ChatterHub> _chatterHub;
|
|
||||||
public ChatterController(HubLifetimeManager<ChatterHub> chatterHub, UserManager<ApplicationUser> userManager, IHttpContextAccessor contextAccessor)
|
|
||||||
: base(contextAccessor, userManager) {
|
|
||||||
this._chatterHub = chatterHub;
|
|
||||||
}
|
|
||||||
[HttpPost("ping")]
|
|
||||||
public async Task<ActionResult<string>> Ping([FromBody] string message) {
|
|
||||||
await _chatterHub.SendAllAsync(
|
|
||||||
$"{_applicationUser.Id}_chatter",
|
|
||||||
new object[] { message });
|
|
||||||
return Ok(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -8,7 +8,6 @@
|
|||||||
public string LastName { get; set; }
|
public string LastName { get; set; }
|
||||||
public string Description { get; set; }
|
public string Description { get; set; }
|
||||||
public string ProfileImage { get; set; }
|
public string ProfileImage { get; set; }
|
||||||
public string Uid { get; set; }
|
|
||||||
public string ApiKey { get; set; }
|
public string ApiKey { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
|
|
||||||
namespace PodNoms.Api.Services.Hubs {
|
namespace PodNoms.Api.Services.Hubs {
|
||||||
[Authorize]
|
[Authorize]
|
||||||
public class ChatterHub : Hub {
|
public class UserUpdatesHub : Hub {
|
||||||
public async Task SendMessage(string user, string message) {
|
public async Task SendMessage(string userId, string message) {
|
||||||
string timestamp = DateTime.Now.ToShortTimeString();
|
string timestamp = DateTime.Now.ToShortTimeString();
|
||||||
await Clients.All.SendAsync($"{user}_chatter", timestamp, user, message);
|
await Clients.All.SendAsync(userId, timestamp, userId, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -24,16 +24,16 @@ namespace PodNoms.Api.Services.Processor {
|
|||||||
private readonly IEntryRepository _repository;
|
private readonly IEntryRepository _repository;
|
||||||
|
|
||||||
public ApplicationsSettings _applicationsSettings { get; }
|
public ApplicationsSettings _applicationsSettings { get; }
|
||||||
private readonly HubLifetimeManager<ChatterHub> _chatterHub;
|
private readonly HubLifetimeManager<UserUpdatesHub> _userUpdateHub;
|
||||||
|
|
||||||
public UrlProcessService(IEntryRepository repository, IUnitOfWork unitOfWork,
|
public UrlProcessService(IEntryRepository repository, IUnitOfWork unitOfWork,
|
||||||
IFileUploader fileUploader, IOptions<ApplicationsSettings> applicationsSettings,
|
IFileUploader fileUploader, IOptions<ApplicationsSettings> applicationsSettings,
|
||||||
HubLifetimeManager<ChatterHub> chatterHub,
|
HubLifetimeManager<UserUpdatesHub> userUpdateHub,
|
||||||
ILoggerFactory logger, IMapper mapper, IRealTimeUpdater pusher) : base(logger, mapper, pusher) {
|
ILoggerFactory logger, IMapper mapper, IRealTimeUpdater pusher) : base(logger, mapper, pusher) {
|
||||||
this._applicationsSettings = applicationsSettings.Value;
|
this._applicationsSettings = applicationsSettings.Value;
|
||||||
this._repository = repository;
|
this._repository = repository;
|
||||||
this._unitOfWork = unitOfWork;
|
this._unitOfWork = unitOfWork;
|
||||||
this._chatterHub = chatterHub;
|
this._userUpdateHub = userUpdateHub;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task __downloader_progress(string userId, string uid, ProcessProgressEvent e) {
|
private async Task __downloader_progress(string userId, string uid, ProcessProgressEvent e) {
|
||||||
@@ -97,8 +97,8 @@ namespace PodNoms.Api.Services.Processor {
|
|||||||
|
|
||||||
await _sendProcessCompleteMessage(entry);
|
await _sendProcessCompleteMessage(entry);
|
||||||
await _unitOfWork.CompleteAsync();
|
await _unitOfWork.CompleteAsync();
|
||||||
await _chatterHub.SendAllAsync(
|
await _userUpdateHub.SendAllAsync(
|
||||||
$"{entry.Podcast.AppUser.Id}_chatter",
|
entry.Podcast.AppUser.Id,
|
||||||
new object[] { $"{entry.Title} has succesfully been processed" });
|
new object[] { $"{entry.Title} has succesfully been processed" });
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -108,8 +108,8 @@ namespace PodNoms.Api.Services.Processor {
|
|||||||
entry.ProcessingPayload = ex.Message;
|
entry.ProcessingPayload = ex.Message;
|
||||||
await _unitOfWork.CompleteAsync();
|
await _unitOfWork.CompleteAsync();
|
||||||
await _sendProcessCompleteMessage(entry);
|
await _sendProcessCompleteMessage(entry);
|
||||||
await _chatterHub.SendAllAsync(
|
await _userUpdateHub.SendAllAsync(
|
||||||
$"{entry.Podcast.AppUser.Id}_chatter",
|
entry.Podcast.AppUser.Id,
|
||||||
new object[] { $"Error processing {entry.Title}" });
|
new object[] { $"Error processing {entry.Title}" });
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -275,7 +275,7 @@ namespace PodNoms.Api {
|
|||||||
|
|
||||||
app.UseSignalR(routes => {
|
app.UseSignalR(routes => {
|
||||||
routes.MapHub<AudioProcessingHub>("/hubs/audioprocessing");
|
routes.MapHub<AudioProcessingHub>("/hubs/audioprocessing");
|
||||||
routes.MapHub<ChatterHub>("/hubs/chatter");
|
routes.MapHub<UserUpdatesHub>("/hubs/userupdates");
|
||||||
routes.MapHub<DebugHub>("/hubs/debug");
|
routes.MapHub<DebugHub>("/hubs/debug");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user