UNPKG

@microsoft/windows-admin-center-sdk

Version:

Microsoft - Windows Admin Center Shell

105 lines (103 loc) 3.68 kB
import { from } from 'rxjs'; import { RpcNotificationClient } from '../rpc/notification/rpc-notification-client'; import { ClientNotificationType } from './client-notification'; import { ClientNotificationInstance } from './client-notification-instance'; import { NotificationManager } from './notification-manager'; /** * Notification connection class. */ export class NotificationConnection { rpc; notificationManager; /** * Initializes a new instance of the NotificationConnection class. * * @param rpc the RPC object. */ constructor(rpc) { this.rpc = rpc; // create only if we are running in the shell window. if (MsftSme.isShell()) { this.notificationManager = new NotificationManager(this.rpc); } } /** * Create a new client notification instance. * * @param nodeName the node name. it should set node name of current action connection or gateway name. * Only shell code could set the node name be null if notification action against shell generic task. */ create(nodeName) { return new ClientNotificationInstance(this, nodeName); } /** * Send a client notification and an alert either directly to NotificationManager or through RPC. * * @param nodeName the node name. * @param notification the client notification object. */ notify(nodeName, notification) { const data = { ...notification, ...{ nodeName: nodeName, timestamp: Date.now() } }; if (this.notificationManager) { return this.notificationManager.notify(data); } return from(RpcNotificationClient.notify(this.rpc, data)); } /** * send updated notification with new message and state * @param nodeName the node name * @param state the new notification state * @param message the new message * @param notification the existing notification */ updateNotification(nodeName, notification, state, message) { notification.message = message; notification.state = state; this.notify(nodeName, notification); } /** * @deprecated * * Send an alert bar based client notification either directly to NotificationManager or through RPC. * * Please use create(), ClientNotificationInstance class or notify() instead. * Recommend to use create() or ClientNotificationInstance class which allows to display in-progress state of notification, * and properly set title, message and supported state. * * @param nodeName the node name of alert source. * @param state the notification state. * @param message the message of alert bar. * @param title the title of alert bar. */ alert(nodeName, state, message, title) { const global = window; const notification = { id: MsftSme.getUniqueId(), state: state, message: message, title: title, link: null, description: null, type: ClientNotificationType.NotificationCenter }; const data = { ...notification, ...{ sourceName: global.MsftSme.Environment.name, nodeName: nodeName, timestamp: Date.now() } }; if (this.notificationManager) { return this.notificationManager.notify(data); } return from(RpcNotificationClient.notify(this.rpc, data)); } } //# sourceMappingURL=notification-connection.js.map