@100mslive/hms-video-store
Version:
@100mslive Core SDK which abstracts the complexities of webRTC while providing a reactive store for data management with a unidirectional data flow
27 lines (23 loc) • 1.03 kB
text/typescript
import { HMSUpdateListener, SessionStoreUpdate } from '../../interfaces';
import { Store } from '../../sdk/store';
import { convertDateNumToDate } from '../../utils/date';
import { HMSNotificationMethod } from '../HMSNotificationMethod';
import { MetadataChangeNotification } from '../HMSNotifications';
export class SessionMetadataManager {
constructor(private store: Store, public listener?: HMSUpdateListener) {}
handleNotification(method: string, notification: any) {
if (method !== HMSNotificationMethod.METADATA_CHANGE) {
return;
}
this.handleMetadataChange(notification);
}
private handleMetadataChange(notification: MetadataChangeNotification) {
const updates: SessionStoreUpdate[] = notification.values.map(update => ({
key: update.key,
value: update.data,
updatedAt: convertDateNumToDate(update.updated_at),
updatedBy: update.updated_by ? this.store.getPeerById(update.updated_by) : undefined,
}));
this.listener?.onSessionStoreUpdate(updates);
}
}