SessionInfo.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 Guid? UserId { 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 NowViewingItemIdentifier { get; set; }
  58. /// <summary>
  59. /// Gets or sets the now playing item.
  60. /// </summary>
  61. /// <value>The now playing item.</value>
  62. public BaseItem NowPlayingItem { get; set; }
  63. /// <summary>
  64. /// Gets or sets the now playing position ticks.
  65. /// </summary>
  66. /// <value>The now playing position ticks.</value>
  67. public long? NowPlayingPositionTicks { get; set; }
  68. /// <summary>
  69. /// Gets or sets a value indicating whether this instance is paused.
  70. /// </summary>
  71. /// <value><c>true</c> if this instance is paused; otherwise, <c>false</c>.</value>
  72. public bool? IsPaused { get; set; }
  73. /// <summary>
  74. /// Gets or sets the device id.
  75. /// </summary>
  76. /// <value>The device id.</value>
  77. public string DeviceId { get; set; }
  78. /// <summary>
  79. /// Gets or sets the web socket.
  80. /// </summary>
  81. /// <value>The web socket.</value>
  82. public List<IWebSocketConnection> WebSockets { get; set; }
  83. /// <summary>
  84. /// Gets a value indicating whether this instance is active.
  85. /// </summary>
  86. /// <value><c>true</c> if this instance is active; otherwise, <c>false</c>.</value>
  87. public bool IsActive
  88. {
  89. get
  90. {
  91. if (WebSockets.Count > 0)
  92. {
  93. return WebSockets.Any(i => i.State == WebSocketState.Open);
  94. }
  95. return (DateTime.UtcNow - LastActivityDate).TotalMinutes <= 5;
  96. }
  97. }
  98. /// <summary>
  99. /// Gets a value indicating whether [supports remote control].
  100. /// </summary>
  101. /// <value><c>true</c> if [supports remote control]; otherwise, <c>false</c>.</value>
  102. public bool SupportsRemoteControl
  103. {
  104. get
  105. {
  106. return WebSockets.Any(i => i.State == WebSocketState.Open);
  107. }
  108. }
  109. }
  110. }