jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/servernotifications.js

39 lines
1.1 KiB
JavaScript
Raw Normal View History

2016-04-12 10:37:58 -07:00
define(['connectionManager', 'events'], function (connectionManager, events) {
2016-10-17 22:06:48 -07:00
'use strict';
2016-04-12 10:37:58 -07:00
var serverNotifications = {};
function onWebSocketMessageReceived(e, msg) {
var apiClient = this;
2016-07-27 22:19:24 -07:00
if (msg.MessageType === "UserDataChanged") {
2016-04-12 10:37:58 -07:00
2016-10-17 22:06:48 -07:00
if (msg.Data.UserId === apiClient.getCurrentUserId()) {
2016-04-12 10:37:58 -07:00
for (var i = 0, length = msg.Data.UserDataList.length; i < length; i++) {
events.trigger(serverNotifications, 'UserDataChanged', [apiClient, msg.Data.UserDataList[i]]);
}
}
}
2016-07-27 22:19:24 -07:00
else {
2016-06-08 10:10:07 -07:00
events.trigger(serverNotifications, msg.MessageType, [apiClient, msg.Data]);
}
2016-04-12 10:37:58 -07:00
}
function bindEvents(apiClient) {
events.off(apiClient, "websocketmessage", onWebSocketMessageReceived);
events.on(apiClient, "websocketmessage", onWebSocketMessageReceived);
}
2017-01-10 23:20:44 -07:00
connectionManager.getApiClients().forEach(bindEvents);
2016-04-12 10:37:58 -07:00
events.on(connectionManager, 'apiclientcreated', function (e, newApiClient) {
bindEvents(newApiClient);
});
return serverNotifications;
});