SessionInfo.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using MediaBrowser.Common.Net;
  4. using MediaBrowser.Controller.Entities;
  5. using MediaBrowser.Model.Net;
  6. using System;
  7. namespace MediaBrowser.Controller.Session
  8. {
  9. /// <summary>
  10. /// Class SessionInfo
  11. /// </summary>
  12. public class SessionInfo
  13. {
  14. public SessionInfo()
  15. {
  16. WebSockets = new List<IWebSocketConnection>();
  17. }
  18. /// <summary>
  19. /// Gets or sets the id.
  20. /// </summary>
  21. /// <value>The id.</value>
  22. public Guid Id { get; set; }
  23. /// <summary>
  24. /// Gets or sets the user id.
  25. /// </summary>
  26. /// <value>The user id.</value>
  27. public User User { get; set; }
  28. /// <summary>
  29. /// Gets or sets the type of the client.
  30. /// </summary>
  31. /// <value>The type of the client.</value>
  32. public string Client { get; set; }
  33. /// <summary>
  34. /// Gets or sets the last activity date.
  35. /// </summary>
  36. /// <value>The last activity date.</value>
  37. public DateTime LastActivityDate { get; set; }
  38. /// <summary>
  39. /// Gets or sets the name of the device.
  40. /// </summary>
  41. /// <value>The name of the device.</value>
  42. public string DeviceName { get; set; }
  43. /// <summary>
  44. /// Gets or sets the now viewing context.
  45. /// </summary>
  46. /// <value>The now viewing context.</value>
  47. public string NowViewingContext { get; set; }
  48. /// <summary>
  49. /// Gets or sets the type of the now viewing item.
  50. /// </summary>
  51. /// <value>The type of the now viewing item.</value>
  52. public string NowViewingItemType { get; set; }
  53. /// <summary>
  54. /// Gets or sets the now viewing item identifier.
  55. /// </summary>
  56. /// <value>The now viewing item identifier.</value>
  57. public string NowViewingItemId { get; set; }
  58. /// <summary>
  59. /// Gets or sets the name of the now viewing item.
  60. /// </summary>
  61. /// <value>The name of the now viewing item.</value>
  62. public string NowViewingItemName { get; set; }
  63. /// <summary>
  64. /// Gets or sets the now playing item.
  65. /// </summary>
  66. /// <value>The now playing item.</value>
  67. public BaseItem NowPlayingItem { get; set; }
  68. /// <summary>
  69. /// Gets or sets the now playing position ticks.
  70. /// </summary>
  71. /// <value>The now playing position ticks.</value>
  72. public long? NowPlayingPositionTicks { get; set; }
  73. /// <summary>
  74. /// Gets or sets a value indicating whether this instance is paused.
  75. /// </summary>
  76. /// <value><c>true</c> if this instance is paused; otherwise, <c>false</c>.</value>
  77. public bool? IsPaused { get; set; }
  78. /// <summary>
  79. /// Gets or sets the device id.
  80. /// </summary>
  81. /// <value>The device id.</value>
  82. public string DeviceId { get; set; }
  83. /// <summary>
  84. /// Gets or sets the web socket.
  85. /// </summary>
  86. /// <value>The web socket.</value>
  87. public List<IWebSocketConnection> WebSockets { get; set; }
  88. /// <summary>
  89. /// Gets a value indicating whether this instance is active.
  90. /// </summary>
  91. /// <value><c>true</c> if this instance is active; otherwise, <c>false</c>.</value>
  92. public bool IsActive
  93. {
  94. get
  95. {
  96. if (WebSockets.Count > 0)
  97. {
  98. return WebSockets.Any(i => i.State == WebSocketState.Open);
  99. }
  100. return (DateTime.UtcNow - LastActivityDate).TotalMinutes <= 5;
  101. }
  102. }
  103. /// <summary>
  104. /// Gets a value indicating whether [supports remote control].
  105. /// </summary>
  106. /// <value><c>true</c> if [supports remote control]; otherwise, <c>false</c>.</value>
  107. public bool SupportsRemoteControl
  108. {
  109. get
  110. {
  111. return WebSockets.Any(i => i.State == WebSocketState.Open);
  112. }
  113. }
  114. }
  115. }