Remove firebase and empty resource config file

This commit is contained in:
Bond_009 2019-01-03 19:51:18 +01:00
parent 86275bcc55
commit db62648510
7 changed files with 12 additions and 286 deletions

View File

@ -2437,53 +2437,6 @@ namespace Emby.Server.Implementations
}
}
}
private Dictionary<string, string> _values;
public string GetValue(string name)
{
if (_values == null)
{
_values = LoadValues();
}
string value;
if (_values.TryGetValue(name, out value))
{
return value;
}
return null;
}
// TODO: @bond Remove?
private Dictionary<string, string> LoadValues()
{
Dictionary<string, string> values = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
using (var stream = typeof(ApplicationHost).Assembly.GetManifestResourceStream(typeof(ApplicationHost).Namespace + ".values.txt"))
{
using (var reader = new StreamReader(stream))
{
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
if (string.IsNullOrEmpty(line))
{
continue;
}
var index = line.IndexOf('=');
if (index != -1)
{
values[line.Substring(0, index)] = line.Substring(index + 1);
}
}
}
}
return values;
}
}
internal class CertificateInfo

View File

@ -1,131 +0,0 @@
using MediaBrowser.Controller.Session;
using MediaBrowser.Model.Net;
using MediaBrowser.Common.Net;
using MediaBrowser.Model.Serialization;
using System;
using System.Threading;
using System.Threading.Tasks;
using System.Text;
using MediaBrowser.Common;
namespace Emby.Server.Implementations.Session
{
public class FirebaseSessionController : ISessionController
{
private readonly IHttpClient _httpClient;
private readonly IJsonSerializer _json;
private readonly ISessionManager _sessionManager;
public SessionInfo Session { get; private set; }
private readonly string _token;
private IApplicationHost _appHost;
private string _senderId;
private string _applicationId;
public FirebaseSessionController(IHttpClient httpClient,
IApplicationHost appHost,
IJsonSerializer json,
SessionInfo session,
string token, ISessionManager sessionManager)
{
_httpClient = httpClient;
_json = json;
_appHost = appHost;
Session = session;
_token = token;
_sessionManager = sessionManager;
_applicationId = _appHost.GetValue("firebase_applicationid");
_senderId = _appHost.GetValue("firebase_senderid");
}
public static bool IsSupported(IApplicationHost appHost)
{
return !string.IsNullOrEmpty(appHost.GetValue("firebase_applicationid")) && !string.IsNullOrEmpty(appHost.GetValue("firebase_senderid"));
}
public bool IsSessionActive
{
get
{
return (DateTime.UtcNow - Session.LastActivityDate).TotalDays <= 3;
}
}
public bool SupportsMediaControl
{
get { return true; }
}
public async Task SendMessage<T>(string name, string messageId, T data, ISessionController[] allControllers, CancellationToken cancellationToken)
{
if (!IsSessionActive)
{
return;
}
if (string.IsNullOrEmpty(_senderId) || string.IsNullOrEmpty(_applicationId))
{
return;
}
foreach (var controller in allControllers)
{
// Don't send if there's an active web socket connection
if ((controller is WebSocketController) && controller.IsSessionActive)
{
return;
}
}
var msg = new WebSocketMessage<T>
{
Data = data,
MessageType = name,
MessageId = messageId,
ServerId = _appHost.SystemId
};
var req = new FirebaseBody<T>
{
to = _token,
data = msg
};
var byteArray = Encoding.UTF8.GetBytes(_json.SerializeToString(req));
var enableLogging = false;
#if DEBUG
enableLogging = true;
#endif
var options = new HttpRequestOptions
{
Url = "https://fcm.googleapis.com/fcm/send",
RequestContentType = "application/json",
RequestContentBytes = byteArray,
CancellationToken = cancellationToken,
LogRequest = enableLogging,
LogResponse = enableLogging,
LogErrors = enableLogging
};
options.RequestHeaders["Authorization"] = string.Format("key={0}", _applicationId);
options.RequestHeaders["Sender"] = string.Format("id={0}", _senderId);
using (var response = await _httpClient.Post(options).ConfigureAwait(false))
{
}
}
}
internal class FirebaseBody<T>
{
public string to { get; set; }
public WebSocketMessage<T> data { get; set; }
}
}

View File

@ -1577,14 +1577,6 @@ namespace Emby.Server.Implementations.Session
{
session.Capabilities = capabilities;
if (!string.IsNullOrEmpty(capabilities.PushToken))
{
if (string.Equals(capabilities.PushTokenType, "firebase", StringComparison.OrdinalIgnoreCase) && FirebaseSessionController.IsSupported(_appHost))
{
EnsureFirebaseController(session, capabilities.PushToken);
}
}
if (saveCapabilities)
{
EventHelper.FireEventIfNotNull(CapabilitiesChanged, this, new SessionEventArgs
@ -1604,11 +1596,6 @@ namespace Emby.Server.Implementations.Session
}
}
private void EnsureFirebaseController(SessionInfo session, string token)
{
session.EnsureController<FirebaseSessionController>(s => new FirebaseSessionController(_httpClient, _appHost, _jsonSerializer, s, token, this));
}
private ClientCapabilities GetSavedCapabilities(string deviceId)
{
return _deviceManager.GetCapabilities(deviceId);

View File

@ -135,7 +135,5 @@ namespace MediaBrowser.Common
object CreateInstance(Type type);
PackageVersionClass SystemUpdateLevel { get; }
string GetValue(string name);
}
}

View File

@ -1,5 +1,4 @@
using MediaBrowser.Model.Dlna;
using System;
namespace MediaBrowser.Model.Session
{
@ -12,8 +11,6 @@ namespace MediaBrowser.Model.Session
public bool SupportsMediaControl { get; set; }
public bool SupportsContentUploading { get; set; }
public string MessageCallbackUrl { get; set; }
public string PushToken { get; set; }
public string PushTokenType { get; set; }
public bool SupportsPersistentIdentifier { get; set; }
public bool SupportsSync { get; set; }
@ -30,4 +27,4 @@ namespace MediaBrowser.Model.Session
SupportsPersistentIdentifier = true;
}
}
}
}

View File

@ -720,82 +720,6 @@ namespace MediaBrowser.Providers.Music
return null;
}
private long _lastMbzUrlQueryTicks = 0;
private List<MbzUrl> _mbzUrls = null;
private MbzUrl _chosenUrl;
private async Task<MbzUrl> GetMbzUrl(bool forceMusicBrainzProper = false)
{
if (_chosenUrl == null || _mbzUrls == null || (DateTime.UtcNow.Ticks - _lastMbzUrlQueryTicks) > TimeSpan.FromHours(12).Ticks)
{
var urls = await RefreshMzbUrls(forceMusicBrainzProper).ConfigureAwait(false);
if (urls.Count > 1)
{
_chosenUrl = urls[new Random().Next(0, urls.Count)];
}
else
{
_chosenUrl = urls[0];
}
}
return _chosenUrl;
}
private async Task<List<MbzUrl>> RefreshMzbUrls(bool forceMusicBrainzProper = false)
{
List<MbzUrl> list = null;
if (!forceMusicBrainzProper)
{
var musicbrainzadminurl = _appHost.GetValue("musicbrainzadminurl");
if (!string.IsNullOrEmpty(musicbrainzadminurl))
{
try
{
var options = new HttpRequestOptions
{
Url = musicbrainzadminurl,
UserAgent = _appHost.Name + "/" + _appHost.ApplicationVersion
};
using (var response = await _httpClient.SendAsync(options, "GET").ConfigureAwait(false))
{
using (var stream = response.Content)
{
var results = await _json.DeserializeFromStreamAsync<List<MbzUrl>>(stream).ConfigureAwait(false);
list = results;
}
}
_lastMbzUrlQueryTicks = DateTime.UtcNow.Ticks;
}
catch (Exception ex)
{
_logger.LogError(ex, "Error getting music brainz info");
}
}
}
if (list == null)
{
list = new List<MbzUrl>
{
new MbzUrl
{
url = MusicBrainzBaseUrl,
throttleMs = 1000
}
};
}
_mbzUrls = list.ToList();
return list;
}
internal Task<HttpResponseInfo> GetMusicBrainzResponse(string url, bool isSearch, CancellationToken cancellationToken)
{
return GetMusicBrainzResponse(url, isSearch, false, cancellationToken);
@ -806,7 +730,7 @@ namespace MediaBrowser.Providers.Music
/// </summary>
internal async Task<HttpResponseInfo> GetMusicBrainzResponse(string url, bool isSearch, bool forceMusicBrainzProper, CancellationToken cancellationToken)
{
var urlInfo = await GetMbzUrl(forceMusicBrainzProper).ConfigureAwait(false);
var urlInfo = new MbzUrl(MusicBrainzBaseUrl, 1000);
var throttleMs = urlInfo.throttleMs;
if (throttleMs > 0)
@ -841,6 +765,12 @@ namespace MediaBrowser.Providers.Music
internal class MbzUrl
{
internal MbzUrl(string url, int throttleMs)
{
this.url = url;
this.throttleMs = throttleMs;
}
public string url { get; set; }
public int throttleMs { get; set; }
}

View File

@ -270,21 +270,13 @@ namespace MediaBrowser.Providers.Omdb
public static string GetOmdbUrl(string query, IApplicationHost appHost, CancellationToken cancellationToken)
{
var baseUrl = appHost.GetValue("omdb_baseurl");
const string url = "https://www.omdbapi.com?apikey=fe53f97e";
if (string.IsNullOrEmpty(baseUrl))
if (string.IsNullOrWhiteSpace(query))
{
baseUrl = "https://www.omdbapi.com";
return url;
}
var url = baseUrl + "?apikey=fe53f97e";
if (!string.IsNullOrWhiteSpace(query))
{
url += "&" + query;
}
return url;
return url + "&" + query;
}
private async Task<string> EnsureItemInfo(string imdbId, CancellationToken cancellationToken)