SessionInfo.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 a value indicating whether this instance is muted.
  80. /// </summary>
  81. /// <value><c>true</c> if this instance is muted; otherwise, <c>false</c>.</value>
  82. public bool IsMuted { get; set; }
  83. /// <summary>
  84. /// Gets or sets the device id.
  85. /// </summary>
  86. /// <value>The device id.</value>
  87. public string DeviceId { get; set; }
  88. /// <summary>
  89. /// Gets or sets the web socket.
  90. /// </summary>
  91. /// <value>The web socket.</value>
  92. public List<IWebSocketConnection> WebSockets { get; set; }
  93. /// <summary>
  94. /// Gets or sets the application version.
  95. /// </summary>
  96. /// <value>The application version.</value>
  97. public string ApplicationVersion { get; set; }
  98. /// <summary>
  99. /// Gets a value indicating whether this instance is active.
  100. /// </summary>
  101. /// <value><c>true</c> if this instance is active; otherwise, <c>false</c>.</value>
  102. public bool IsActive
  103. {
  104. get
  105. {
  106. if (WebSockets.Count > 0)
  107. {
  108. return WebSockets.Any(i => i.State == WebSocketState.Open);
  109. }
  110. return (DateTime.UtcNow - LastActivityDate).TotalMinutes <= 5;
  111. }
  112. }
  113. /// <summary>
  114. /// Gets a value indicating whether [supports remote control].
  115. /// </summary>
  116. /// <value><c>true</c> if [supports remote control]; otherwise, <c>false</c>.</value>
  117. public bool SupportsRemoteControl
  118. {
  119. get
  120. {
  121. return WebSockets.Any(i => i.State == WebSocketState.Open);
  122. }
  123. }
  124. }
  125. }