mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
fix login to socket
This commit is contained in:
@@ -26,11 +26,13 @@ export class DexieRepository<T> {
|
||||
const id = await this.table.add(dataValidation.data);
|
||||
return ok(id);
|
||||
} catch (error) {
|
||||
return err(new Error('Failed to insert document: ' + error.message));
|
||||
console.log(error)
|
||||
return err(new Error('Failed to insert document: ' + error));
|
||||
}
|
||||
} else {
|
||||
Logger.error(`dexie.js failed to insert into ${this.table.name}, invalid data`, {
|
||||
data: document
|
||||
data: document,
|
||||
zodError: dataValidation.error.issues
|
||||
});
|
||||
return err((dataValidation as unknown as ZodError<T>))
|
||||
}
|
||||
@@ -42,6 +44,10 @@ export class DexieRepository<T> {
|
||||
|
||||
const validationResult = schema.safeParse(documents)
|
||||
if(!validationResult.success) {
|
||||
Logger.error(`dexie.js failed to insert many into ${this.table.name}, invalid data`, {
|
||||
data: document,
|
||||
zodError: validationResult.error.issues
|
||||
});
|
||||
return err((validationResult as unknown as ZodError<T>))
|
||||
}
|
||||
|
||||
@@ -49,9 +55,7 @@ export class DexieRepository<T> {
|
||||
const ids = await this.table.bulkAdd(documents as any);
|
||||
return ok(ids);
|
||||
} catch (error) {
|
||||
Logger.error(`dexie.js failed to insert many into ${this.table.name}, invalid data`, {
|
||||
data: document
|
||||
});
|
||||
|
||||
return err(new Error('Failed to insert multiple documents: ' + error.message));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ export class ChatModule {
|
||||
).subscribe((value)=> {
|
||||
if(value) {
|
||||
// on reconnect
|
||||
this.ChatServiceService.start();
|
||||
this.ChatServiceService.chatSync();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { RoomListItemOutPutDTO, RoomListOutPutDTO } from '../dto/room/roomListOutputDTO';
|
||||
import { Dexie, EntityTable, liveQuery, Observable } from 'Dexie';
|
||||
import { z } from 'zod';
|
||||
import { DexieRepository } from 'src/app/infra/repository/dexie/dexie-repository.service';
|
||||
import { RoomTable, RoomTableSchema } from '../../infra/database/dexie/schema/room';
|
||||
import { chatDatabase } from '../../infra/database/dexie/service';
|
||||
import { ok } from 'neverthrow';
|
||||
import { err, Result } from 'neverthrow';
|
||||
@@ -37,6 +35,13 @@ export class MemberListLocalRepository extends DexieRepository<MemberTable> {
|
||||
async addMember(data: MemberTable) {
|
||||
data.$roomIdUserId = data.roomId + data.wxUserId
|
||||
return this.insert(data)
|
||||
// try {
|
||||
// data.$roomIdUserId = data.roomId + data.wxUserId
|
||||
// const result = await chatDatabase.members.add(data)
|
||||
// return ok(result)
|
||||
// } catch (e) {
|
||||
// return err(false)
|
||||
// }
|
||||
}
|
||||
|
||||
async updateMemberRole(data: MemberTable) {
|
||||
|
||||
+4
@@ -44,6 +44,10 @@ export class MessageSocketRepositoryService {
|
||||
private socket: SignalRService
|
||||
) {}
|
||||
|
||||
connect() {
|
||||
return this.socket.establishConnection();
|
||||
}
|
||||
|
||||
async sendMessage(data: msgObj) {
|
||||
|
||||
try {
|
||||
|
||||
@@ -25,6 +25,7 @@ import { SendLocalMessagesUseCaseService } from './use-case/messages-send-offlin
|
||||
import { RemoveMemberUseCaseService } from './use-case/member/-use-case.service'
|
||||
import { AddMemberUseCaseService } from './use-case/member-add-use-case.service'
|
||||
import { UpdateRoomByIdUseCaseService } from './use-case/room-update-by-id-use-case.service'
|
||||
import { SocketConnectUseCaseService } from './use-case/socket-connect-use-case.service'
|
||||
import { MessageMarkAsReadUseCaseService } from './use-case/message/message-mark-as-read-use-case.service'
|
||||
import { GetMessageAttachmentLocallyUseCaseService } from 'src/app/module/chat/domain/use-case/message-get-attachment-localy-use-case.service';
|
||||
import { GetRoomListUseCaseService } from 'src/app/module/chat/domain/use-case/room-get-list-use-case.service';
|
||||
@@ -76,7 +77,8 @@ export class ChatServiceService {
|
||||
private RemoveMemberUseCaseService: RemoveMemberUseCaseService,
|
||||
private MessageReadAtByIdUseCaseService: MessageReadAtByIdUseCaseService,
|
||||
private SendLocalMessagesUseCaseService: SendLocalMessagesUseCaseService,
|
||||
private MessageMarkAsReadUseCaseService: MessageMarkAsReadUseCaseService
|
||||
private MessageMarkAsReadUseCaseService: MessageMarkAsReadUseCaseService,
|
||||
private SocketConnectUseCaseService: SocketConnectUseCaseService
|
||||
) {
|
||||
this.messageLiveSignalRDataSourceService.getMessageDelete()
|
||||
.pipe()
|
||||
@@ -123,8 +125,14 @@ export class ChatServiceService {
|
||||
}
|
||||
|
||||
async start() {
|
||||
await this.chatSync()
|
||||
this.SocketConnectUseCaseService.execute();
|
||||
}
|
||||
|
||||
|
||||
async chatSync() {
|
||||
await this.getRoomList();
|
||||
this.asyncAllRoomMessage();
|
||||
await this.asyncAllRoomMessage();
|
||||
}
|
||||
|
||||
removeMemberToRoom(data: UserRemoveListInputDTO) {
|
||||
|
||||
@@ -14,10 +14,8 @@ export class ListenSendMessageUseCase {
|
||||
|
||||
execute({roomId}: {roomId: string}) {
|
||||
|
||||
console.log('reciee message')
|
||||
return this.MessageSocketRepositoryService.listenToMessages().pipe(
|
||||
filter((message) => {
|
||||
console.log(message, roomId)
|
||||
return message?.requestId?.startsWith(InstanceId) && message?.roomId == roomId
|
||||
}),
|
||||
map(message => message)
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { MessageSocketRepositoryService } from 'src/app/module/chat/data/repository/message/message-live-signalr-data-source.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class SocketConnectUseCaseService {
|
||||
|
||||
constructor(
|
||||
private MessageSocketRepositoryService: MessageSocketRepositoryService
|
||||
) { }
|
||||
|
||||
execute() {
|
||||
return this.MessageSocketRepositoryService.connect()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import { ok } from 'neverthrow';
|
||||
import { RoomLocalRepository } from '../../data/repository/room-local-repository.service';
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
import { Logger } from 'src/app/services/logger/main/service';
|
||||
import { XTracerAsync, TracingType } from 'src/app/services/monitoring/opentelemetry/tracer';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -21,20 +22,27 @@ export class SyncAllRoomMessagesService {
|
||||
private roomLocalDataSourceService: RoomLocalRepository,
|
||||
) { }
|
||||
|
||||
async execute() {
|
||||
@XTracerAsync({name:'SyncAllRoomMessagesService', module:'chat', bugPrint: true})
|
||||
async execute(tracing?: TracingType) {
|
||||
|
||||
const allRooms = await this.roomLocalDataSourceService.findAll()
|
||||
|
||||
if(allRooms.isOk()) {
|
||||
if(allRooms.value.length == 0) {
|
||||
console.log('no room to sync')
|
||||
tracing.addEvent('no need to sync')
|
||||
} else {
|
||||
console.log('sync '+ allRooms.value.length)
|
||||
tracing.addEvent('total sync '+ allRooms.value.length)
|
||||
}
|
||||
|
||||
let n =0
|
||||
for(const room of allRooms.value) {
|
||||
|
||||
const result = await this.messageRemoteDataSourceService.getMessagesFromRoom(room.id)
|
||||
const localResult = await this.messageLocalDataSourceService.getItems(room.id)
|
||||
|
||||
tracing.addEvent('async n '+ n)
|
||||
n++
|
||||
|
||||
if(result.isOk()) {
|
||||
|
||||
const { addedItems, changedItems, deletedItems } = messageListDetermineChanges(result.value.data, localResult)
|
||||
|
||||
@@ -3,14 +3,14 @@ import { EntityTable } from 'Dexie';
|
||||
|
||||
export const MemberTableSchema = z.object({
|
||||
$roomIdUserId: z.string().optional(),
|
||||
id: z.string(),
|
||||
id: z.string().optional(), // useless
|
||||
roomId: z.string(),
|
||||
wxUserId: z.number(),
|
||||
wxFullName: z.string(),
|
||||
wxeMail: z.string(),
|
||||
userPhoto: z.string().nullable(),
|
||||
joinAt: z.string(),
|
||||
status: z.string(),
|
||||
status: z.string().optional(), // useless
|
||||
isAdmin: z.boolean()
|
||||
})
|
||||
|
||||
|
||||
@@ -65,10 +65,10 @@ export class SignalRService {
|
||||
}
|
||||
} catch(error) {}
|
||||
|
||||
this.establishConnection()
|
||||
// this.establishConnection()
|
||||
}
|
||||
|
||||
private async establishConnection() {
|
||||
async establishConnection() {
|
||||
|
||||
// const connection = new SignalRConnection({url:'https://41e3-41-63-166-54.ngrok-free.app/api/v2/chathub'})
|
||||
const connection = new SignalRConnection({url:'https://gdapi-dev.dyndns.info/stage/api/v2/chathub'})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { metrics } from '@opentelemetry/api';
|
||||
import { Histogram, metrics } from '@opentelemetry/api';
|
||||
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-http';
|
||||
import { MeterProvider, PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics';
|
||||
import { Subject } from 'rxjs';
|
||||
@@ -46,3 +46,10 @@ export const RequestCounter = meter.createCounter('post_requests', {
|
||||
export const UseCaseCounter = meter.createCounter('use_case', {
|
||||
description: 'use case counter',
|
||||
});
|
||||
|
||||
|
||||
// Assuming `meter` is your initialized Meter instance
|
||||
export const useCaseDurationHistogram: Histogram = meter.createHistogram('use_case_duration', {
|
||||
description: 'Duration of use cases',
|
||||
unit: 'milliseconds',
|
||||
});
|
||||
|
||||
@@ -5,7 +5,7 @@ import { OpentelemetryAgendaProvider, OpentelemetryChatProvider, OpentelemetryIn
|
||||
import { Device, DeviceInfo } from '@capacitor/device';
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { UseCaseCounter } from './matrix';
|
||||
import { UseCaseCounter, useCaseDurationHistogram } from './matrix';
|
||||
import { openTelemetryLogging } from './logging';
|
||||
import {
|
||||
SpanStatus, SpanStatusCode
|
||||
@@ -39,6 +39,9 @@ function convertAttributesToString(obj) {
|
||||
|
||||
|
||||
const createTracingInstance = ({bugPrint, name, module, autoFinish}): TracingType => {
|
||||
|
||||
const startTime = Date.now();
|
||||
|
||||
const requestId = uuidv4()
|
||||
|
||||
let _tracerInstance:Tracer
|
||||
@@ -141,6 +144,9 @@ const createTracingInstance = ({bugPrint, name, module, autoFinish}): TracingTyp
|
||||
console.error(name, data)
|
||||
}
|
||||
|
||||
const duration = Date.now() - (startTime as unknown as number);
|
||||
useCaseDurationHistogram.record(duration, { use_case: name });
|
||||
|
||||
finish = true
|
||||
},
|
||||
hasError:(message: string) => {
|
||||
@@ -165,6 +171,7 @@ export function XTracerAsync({ name, bugPrint, module = null, autoFinish = true,
|
||||
descriptor.value = async function (...args: unknown[]) {
|
||||
|
||||
|
||||
|
||||
const tracing = createTracingInstance({bugPrint, name, module, autoFinish})
|
||||
|
||||
tracing.setAttribute('User', SessionStore?.user?.FullName);
|
||||
|
||||
Reference in New Issue
Block a user