1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

update notifications

This commit is contained in:
Luke Pulverenti 2016-07-28 01:19:24 -04:00
parent d10ba94be9
commit e9151896b2
27 changed files with 710 additions and 667 deletions

View file

@ -14,12 +14,12 @@
},
"devDependencies": {},
"ignore": [],
"version": "1.4.123",
"_release": "1.4.123",
"version": "1.4.124",
"_release": "1.4.124",
"_resolution": {
"type": "version",
"tag": "1.4.123",
"commit": "9939e23191c1f45c2ea59e41a4e55c22c2839bb7"
"tag": "1.4.124",
"commit": "308546fe094fa18c356480d1d13c8790d43de971"
},
"_source": "https://github.com/MediaBrowser/emby-webcomponents.git",
"_target": "^1.2.0",

View file

@ -53,12 +53,18 @@ define(['browser'], function (browser) {
if (browser.tizen) {
return true;
}
if (isEdgeUniversal()) {
return true;
}
}
else if (format == 'wma') {
if (browser.tizen) {
return true;
}
if (isEdgeUniversal()) {
return true;
}
}
else if (format == 'opus') {
@ -84,13 +90,31 @@ define(['browser'], function (browser) {
return false;
}
function testCanPlayMkv() {
function isEdgeUniversal() {
if (browser.edge) {
var userAgent = navigator.userAgent.toLowerCase();
if (userAgent.indexOf('msapphost') != -1) {
return true;
}
}
return false;
}
function testCanPlayMkv(videoTestElement) {
if (videoTestElement.canPlayType('video/x-matroska') ||
videoTestElement.canPlayType('video/mkv')) {
return true;
}
var userAgent = navigator.userAgent.toLowerCase();
// Unfortunately there's no real way to detect mkv support
if (browser.chrome) {
var userAgent = navigator.userAgent.toLowerCase();
// Not supported on opera tv
if (browser.operaTv) {
return false;
@ -108,6 +132,11 @@ define(['browser'], function (browser) {
return true;
}
if (isEdgeUniversal()) {
return true;
}
return false;
}
@ -122,9 +151,11 @@ define(['browser'], function (browser) {
switch (container) {
case 'asf':
supported = browser.tizen || isEdgeUniversal();
break;
case '3gp':
case 'avi':
case 'asf':
case 'flv':
case 'mpg':
case 'mpeg':
@ -135,9 +166,11 @@ define(['browser'], function (browser) {
supported = browser.tizen;
break;
case 'm2ts':
case 'wmv':
supported = browser.tizen || browser.web0s;
break;
case 'wmv':
supported = browser.tizen || browser.web0s || isEdgeUniversal();
break;
case 'ts':
supported = browser.tizen || browser.web0s;
if (supported) {
@ -199,7 +232,7 @@ define(['browser'], function (browser) {
var canPlayWebm = videoTestElement.canPlayType('video/webm').replace(/no/, '');
var canPlayMkv = testCanPlayMkv();
var canPlayMkv = testCanPlayMkv(videoTestElement);
var canPlayTs = testCanPlayTs();
var profile = {};
@ -218,7 +251,7 @@ define(['browser'], function (browser) {
// Only put mp3 first if mkv support is there
// Otherwise with HLS and mp3 audio we're seeing some browsers
if (videoTestElement.canPlayType('audio/mp4; codecs="ac-3"').replace(/no/, '')) {
if (videoTestElement.canPlayType('audio/mp4; codecs="ac-3"').replace(/no/, '') || isEdgeUniversal()) {
// safari is lying
if (!browser.safari) {
videoAudioCodecs.push('ac3');
@ -266,7 +299,7 @@ define(['browser'], function (browser) {
}
// These are formats we can't test for but some devices will support
['m2ts', 'wmv', 'ts'].map(getDirectPlayProfileForVideoContainer).filter(function (i) {
['m2ts', 'wmv', 'ts', 'asf'].map(getDirectPlayProfileForVideoContainer).filter(function (i) {
return i != null;
}).forEach(function (i) {

View file

@ -1,117 +0,0 @@
define(['connectionManager', 'playbackManager', 'events', 'inputManager', 'focusManager', 'embyRouter'], function (connectionManager, playbackManager, events, inputManager, focusManager, embyRouter) {
function onOneDocumentClick() {
document.removeEventListener('click', onOneDocumentClick);
document.removeEventListener('keydown', onOneDocumentClick);
if (window.Notification) {
Notification.requestPermission();
}
}
document.addEventListener('click', onOneDocumentClick);
document.addEventListener('keydown', onOneDocumentClick);
function onLibraryChanged(data, apiClient) {
var newItems = data.ItemsAdded;
if (!newItems.length || /*AppInfo.isNativeApp ||*/ !window.Notification || Notification.permission !== "granted") {
return;
}
if (playbackManager.isPlayingVideo()) {
return;
}
apiClient.getItems(apiClient.getCurrentUserId(), {
Recursive: true,
Limit: 3,
IsFolder: false,
SortBy: "DateCreated",
SortOrder: "Descending",
ImageTypes: "Primary",
Ids: newItems.join(',')
}).then(function (result) {
var items = result.Items;
for (var i = 0, length = items.length ; i < length; i++) {
var item = items[i];
var notification = {
title: "New " + item.Type,
body: item.Name,
timeout: 15000,
vibrate: true,
data: {
//options: {
// url: LibraryBrowser.getHref(item)
//}
}
};
var imageTags = item.ImageTags || {};
if (imageTags.Primary) {
notification.icon = apiClient.getScaledImageUrl(item.Id, {
width: 80,
tag: imageTags.Primary,
type: "Primary"
});
}
var notif = new Notification(notification.title, notification);
if (notif.show) {
notif.show();
}
if (notification.timeout) {
setTimeout(function () {
if (notif.close) {
notif.close();
}
else if (notif.cancel) {
notif.cancel();
}
}, notification.timeout);
}
}
});
}
function onWebSocketMessageReceived(e, msg) {
var apiClient = this;
if (msg.MessageType === "LibraryChanged") {
var cmd = msg.Data;
onLibraryChanged(cmd, apiClient);
}
}
function bindEvents(apiClient) {
if (!apiClient) {
return;
}
events.off(apiClient, "websocketmessage", onWebSocketMessageReceived);
events.on(apiClient, "websocketmessage", onWebSocketMessageReceived);
}
bindEvents(connectionManager.currentApiClient());
events.on(connectionManager, 'apiclientcreated', function (e, newApiClient) {
bindEvents(newApiClient);
});
});

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

View file

@ -0,0 +1,182 @@
define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'require'], function (serverNotifications, playbackManager, events, globalize, require) {
function onOneDocumentClick() {
document.removeEventListener('click', onOneDocumentClick);
document.removeEventListener('keydown', onOneDocumentClick);
if (window.Notification) {
Notification.requestPermission();
}
}
document.addEventListener('click', onOneDocumentClick);
document.addEventListener('keydown', onOneDocumentClick);
function closeAfter(notification, timeoutMs) {
setTimeout(function () {
if (notification.close) {
notification.close();
}
else if (notification.cancel) {
notification.cancel();
}
}, timeoutMs);
}
function show(title, options, timeoutMs) {
try {
var notif = new Notification(title, options);
if (notif.show) {
notif.show();
}
if (timeoutMs) {
closeAfter(notif, timeoutMs);
}
} catch (err) {
if (options.actions) {
options.actions = [];
show(title, options, timeoutMs);
} else {
throw err;
}
}
}
function showNewItemNotification(item, apiClient) {
var notification = {
title: "New " + item.Type,
body: item.Name,
vibrate: true,
tag: "newItem" + item.Id,
data: {
//options: {
// url: LibraryBrowser.getHref(item)
//}
}
};
var imageTags = item.ImageTags || {};
if (imageTags.Primary) {
notification.icon = apiClient.getScaledImageUrl(item.Id, {
width: 80,
tag: imageTags.Primary,
type: "Primary"
});
}
show(notification.title, notification, 15000);
}
function onLibraryChanged(data, apiClient) {
var newItems = data.ItemsAdded;
if (!newItems.length || !window.Notification || Notification.permission !== "granted") {
return;
}
if (playbackManager.isPlayingVideo()) {
return;
}
apiClient.getItems(apiClient.getCurrentUserId(), {
Recursive: true,
Limit: 3,
IsFolder: false,
SortBy: "DateCreated",
SortOrder: "Descending",
ImageTypes: "Primary",
Ids: newItems.join(',')
}).then(function (result) {
var items = result.Items;
for (var i = 0, length = items.length ; i < length; i++) {
showNewItemNotification(items[i], apiClient);
}
});
}
function getIconUrl(name) {
return require.toUrl('.').split('?')[0] + '/' + name;
}
function showPackageInstallNotification(apiClient, installation, status) {
apiClient.getCurrentUser().then(function (user) {
if (!user.Policy.IsAdministrator) {
return;
}
var notification = {
tag: "install" + installation.Id,
data: {},
icon: getIconUrl('/notificationicon.png')
};
if (status == 'completed') {
notification.title = globalize.translate('LabelPackageInstallCompleted').replace('{0}', installation.Name + ' ' + installation.Version);
notification.vibrate = true;
}
else if (status == 'cancelled') {
notification.title = globalize.translate('LabelPackageInstallCancelled').replace('{0}', installation.Name + ' ' + installation.Version);
}
else if (status == 'failed') {
notification.title = globalize.translate('LabelPackageInstallFailed').replace('{0}', installation.Name + ' ' + installation.Version);
notification.vibrate = true;
}
else if (status == 'progress') {
notification.title = globalize.translate('LabelInstallingPackage').replace('{0}', installation.Name + ' ' + installation.Version);
notification.actions =
[
{ action: 'cancel', title: globalize.translate('ButtonCancel')/*, icon: 'https://example/like.png'*/ }
];
}
if (status == 'progress') {
var percentComplete = Math.round(installation.PercentComplete || 0);
notification.body = percentComplete + '% complete.';
}
var timeout = status == 'cancelled' ? 5000 : 0;
show(notification.title, notification, timeout);
});
}
events.on(serverNotifications, 'LibraryChanged', function (e, apiClient, data) {
onLibraryChanged(data, apiClient);
});
events.on(serverNotifications, 'PackageInstallationCompleted', function (e, apiClient, data) {
showPackageInstallNotification(apiClient, data, "completed");
});
events.on(serverNotifications, 'PackageInstallationFailed', function (e, apiClient, data) {
showPackageInstallNotification(apiClient, data, "failed");
});
events.on(serverNotifications, 'PackageInstallationCancelled', function (e, apiClient, data) {
showPackageInstallNotification(apiClient, data, "cancelled");
});
events.on(serverNotifications, 'PackageInstalling', function (e, apiClient, data) {
showPackageInstallNotification(apiClient, data, "progress");
});
});

View file

@ -6,18 +6,7 @@ define(['connectionManager', 'events'], function (connectionManager, events) {
var apiClient = this;
if (msg.MessageType === "LibraryChanged") {
}
else if (msg.MessageType === "ServerShuttingDown") {
events.trigger(serverNotifications, 'ServerShuttingDown', [apiClient]);
}
else if (msg.MessageType === "ServerRestarting") {
events.trigger(serverNotifications, 'ServerRestarting', [apiClient]);
}
else if (msg.MessageType === "RestartRequired") {
events.trigger(serverNotifications, 'RestartRequired', [apiClient]);
}
else if (msg.MessageType === "UserDataChanged") {
if (msg.MessageType === "UserDataChanged") {
if (msg.Data.UserId == apiClient.getCurrentUserId()) {
@ -26,7 +15,7 @@ define(['connectionManager', 'events'], function (connectionManager, events) {
}
}
}
else if (msg.MessageType === "TimerCreated" || msg.MessageType === "SeriesTimerCreated" || msg.MessageType === "TimerCancelled" || msg.MessageType === "SeriesTimerCancelled") {
else {
events.trigger(serverNotifications, msg.MessageType, [apiClient, msg.Data]);
}
@ -38,10 +27,10 @@ define(['connectionManager', 'events'], function (connectionManager, events) {
events.on(apiClient, "websocketmessage", onWebSocketMessageReceived);
}
//var current = connectionManager.currentApiClient();
//if (current) {
// bindEvents(current);
//}
var current = connectionManager.currentApiClient();
if (current) {
bindEvents(current);
}
events.on(connectionManager, 'apiclientcreated', function (e, newApiClient) {