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) {
|
||||
this._messagingService.getPermission();
|
||||
this._messagingService.receiveMessage();
|
||||
const chatterChannel = `${p.uid}_chatter`;
|
||||
const chatterChannel = `${p.id}`;
|
||||
this._signalrService
|
||||
.init('chatter')
|
||||
.init('userupdates')
|
||||
.then((r) => {
|
||||
this._signalrService.connection.on(
|
||||
chatterChannel,
|
||||
@@ -69,7 +69,7 @@ export class AppComponent implements OnInit {
|
||||
.catch((err) => {
|
||||
console.error(
|
||||
'app.component',
|
||||
'Unable to initialise chatter hub',
|
||||
'Unable to initialise site update hub',
|
||||
err
|
||||
);
|
||||
});
|
||||
|
||||
@@ -29,7 +29,6 @@ import { ModalModule } from 'ngx-bootstrap/modal';
|
||||
import { AuthGuard } from './services/auth.guard';
|
||||
import { ImageService } from './services/image.service';
|
||||
import { DebugService } from './services/debug.service';
|
||||
import { ChatterService } from './services/chatter.service';
|
||||
import { DebugComponent } from './components/debug/debug.component';
|
||||
import { InlineEditorModule } from '@qontu/ngx-inline-editor';
|
||||
import { SidebarComponent } from './components/sidebar/sidebar.component';
|
||||
@@ -208,7 +207,6 @@ export function provideConfig() {
|
||||
PushRegistrationService,
|
||||
DebugService,
|
||||
MessagingService,
|
||||
ChatterService,
|
||||
AppInsightsService,
|
||||
JobsService,
|
||||
AudioService,
|
||||
|
||||
@@ -4,7 +4,6 @@ import { Component, OnInit } from '@angular/core';
|
||||
import { DebugService } from 'app/services/debug.service';
|
||||
import { environment } from 'environments/environment';
|
||||
import { JobsService } from 'app/services/jobs.service';
|
||||
import { ChatterService } from 'app/services/chatter.service';
|
||||
import { MessagingService } from 'app/services/messaging.service';
|
||||
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
|
||||
|
||||
@@ -23,7 +22,6 @@ export class DebugComponent implements OnInit {
|
||||
|
||||
constructor(
|
||||
private _debugService: DebugService,
|
||||
private _chatterService: ChatterService,
|
||||
private _jobsService: JobsService,
|
||||
private _pushNotifications: MessagingService,
|
||||
private _signalrService: SignalRService
|
||||
|
||||
@@ -4,7 +4,6 @@ export class ProfileModel {
|
||||
email: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
uid?: string;
|
||||
profileImage?: string;
|
||||
apiKey: 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 Description { get; set; }
|
||||
public string ProfileImage { get; set; }
|
||||
public string Uid { get; set; }
|
||||
public string ApiKey { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace PodNoms.Api.Services.Hubs {
|
||||
[Authorize]
|
||||
public class ChatterHub : Hub {
|
||||
public async Task SendMessage(string user, string message) {
|
||||
public class UserUpdatesHub : Hub {
|
||||
public async Task SendMessage(string userId, string message) {
|
||||
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;
|
||||
|
||||
public ApplicationsSettings _applicationsSettings { get; }
|
||||
private readonly HubLifetimeManager<ChatterHub> _chatterHub;
|
||||
private readonly HubLifetimeManager<UserUpdatesHub> _userUpdateHub;
|
||||
|
||||
public UrlProcessService(IEntryRepository repository, IUnitOfWork unitOfWork,
|
||||
IFileUploader fileUploader, IOptions<ApplicationsSettings> applicationsSettings,
|
||||
HubLifetimeManager<ChatterHub> chatterHub,
|
||||
HubLifetimeManager<UserUpdatesHub> userUpdateHub,
|
||||
ILoggerFactory logger, IMapper mapper, IRealTimeUpdater pusher) : base(logger, mapper, pusher) {
|
||||
this._applicationsSettings = applicationsSettings.Value;
|
||||
this._repository = repository;
|
||||
this._unitOfWork = unitOfWork;
|
||||
this._chatterHub = chatterHub;
|
||||
this._userUpdateHub = userUpdateHub;
|
||||
}
|
||||
|
||||
private async Task __downloader_progress(string userId, string uid, ProcessProgressEvent e) {
|
||||
@@ -97,8 +97,8 @@ namespace PodNoms.Api.Services.Processor {
|
||||
|
||||
await _sendProcessCompleteMessage(entry);
|
||||
await _unitOfWork.CompleteAsync();
|
||||
await _chatterHub.SendAllAsync(
|
||||
$"{entry.Podcast.AppUser.Id}_chatter",
|
||||
await _userUpdateHub.SendAllAsync(
|
||||
entry.Podcast.AppUser.Id,
|
||||
new object[] { $"{entry.Title} has succesfully been processed" });
|
||||
|
||||
}
|
||||
@@ -108,8 +108,8 @@ namespace PodNoms.Api.Services.Processor {
|
||||
entry.ProcessingPayload = ex.Message;
|
||||
await _unitOfWork.CompleteAsync();
|
||||
await _sendProcessCompleteMessage(entry);
|
||||
await _chatterHub.SendAllAsync(
|
||||
$"{entry.Podcast.AppUser.Id}_chatter",
|
||||
await _userUpdateHub.SendAllAsync(
|
||||
entry.Podcast.AppUser.Id,
|
||||
new object[] { $"Error processing {entry.Title}" });
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -275,7 +275,7 @@ namespace PodNoms.Api {
|
||||
|
||||
app.UseSignalR(routes => {
|
||||
routes.MapHub<AudioProcessingHub>("/hubs/audioprocessing");
|
||||
routes.MapHub<ChatterHub>("/hubs/chatter");
|
||||
routes.MapHub<UserUpdatesHub>("/hubs/userupdates");
|
||||
routes.MapHub<DebugHub>("/hubs/debug");
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user