SessionInfo.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. using MediaBrowser.Controller.Entities;
  2. using MediaBrowser.Model.Session;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. namespace MediaBrowser.Controller.Session
  7. {
  8. /// <summary>
  9. /// Class SessionInfo
  10. /// </summary>
  11. public class SessionInfo
  12. {
  13. public SessionInfo()
  14. {
  15. QueueableMediaTypes = new List<string>();
  16. AdditionalUsers = new List<SessionUserInfo>();
  17. }
  18. public List<SessionUserInfo> AdditionalUsers { get; set; }
  19. /// <summary>
  20. /// Gets or sets the remote end point.
  21. /// </summary>
  22. /// <value>The remote end point.</value>
  23. public string RemoteEndPoint { get; set; }
  24. /// <summary>
  25. /// Gets or sets a value indicating whether this instance can seek.
  26. /// </summary>
  27. /// <value><c>true</c> if this instance can seek; otherwise, <c>false</c>.</value>
  28. public bool CanSeek { get; set; }
  29. /// <summary>
  30. /// Gets or sets the queueable media types.
  31. /// </summary>
  32. /// <value>The queueable media types.</value>
  33. public List<string> QueueableMediaTypes { get; set; }
  34. /// <summary>
  35. /// Gets or sets the id.
  36. /// </summary>
  37. /// <value>The id.</value>
  38. public Guid Id { get; set; }
  39. /// <summary>
  40. /// Gets or sets the user id.
  41. /// </summary>
  42. /// <value>The user id.</value>
  43. public Guid? UserId { get; set; }
  44. /// <summary>
  45. /// Gets or sets the username.
  46. /// </summary>
  47. /// <value>The username.</value>
  48. public string UserName { get; set; }
  49. /// <summary>
  50. /// Gets or sets the type of the client.
  51. /// </summary>
  52. /// <value>The type of the client.</value>
  53. public string Client { get; set; }
  54. /// <summary>
  55. /// Gets or sets the last activity date.
  56. /// </summary>
  57. /// <value>The last activity date.</value>
  58. public DateTime LastActivityDate { get; set; }
  59. /// <summary>
  60. /// Gets or sets the name of the device.
  61. /// </summary>
  62. /// <value>The name of the device.</value>
  63. public string DeviceName { get; set; }
  64. /// <summary>
  65. /// Gets or sets the now viewing context.
  66. /// </summary>
  67. /// <value>The now viewing context.</value>
  68. public string NowViewingContext { get; set; }
  69. /// <summary>
  70. /// Gets or sets the type of the now viewing item.
  71. /// </summary>
  72. /// <value>The type of the now viewing item.</value>
  73. public string NowViewingItemType { get; set; }
  74. /// <summary>
  75. /// Gets or sets the now viewing item identifier.
  76. /// </summary>
  77. /// <value>The now viewing item identifier.</value>
  78. public string NowViewingItemId { get; set; }
  79. /// <summary>
  80. /// Gets or sets the name of the now viewing item.
  81. /// </summary>
  82. /// <value>The name of the now viewing item.</value>
  83. public string NowViewingItemName { get; set; }
  84. /// <summary>
  85. /// Gets or sets the now playing item.
  86. /// </summary>
  87. /// <value>The now playing item.</value>
  88. public BaseItem NowPlayingItem { get; set; }
  89. /// <summary>
  90. /// Gets or sets the now playing position ticks.
  91. /// </summary>
  92. /// <value>The now playing position ticks.</value>
  93. public long? NowPlayingPositionTicks { get; set; }
  94. /// <summary>
  95. /// Gets or sets a value indicating whether this instance is paused.
  96. /// </summary>
  97. /// <value><c>true</c> if this instance is paused; otherwise, <c>false</c>.</value>
  98. public bool IsPaused { get; set; }
  99. /// <summary>
  100. /// Gets or sets a value indicating whether this instance is muted.
  101. /// </summary>
  102. /// <value><c>true</c> if this instance is muted; otherwise, <c>false</c>.</value>
  103. public bool IsMuted { get; set; }
  104. /// <summary>
  105. /// Gets or sets the device id.
  106. /// </summary>
  107. /// <value>The device id.</value>
  108. public string DeviceId { get; set; }
  109. /// <summary>
  110. /// Gets or sets the application version.
  111. /// </summary>
  112. /// <value>The application version.</value>
  113. public string ApplicationVersion { get; set; }
  114. /// <summary>
  115. /// Gets or sets the session controller.
  116. /// </summary>
  117. /// <value>The session controller.</value>
  118. public ISessionController SessionController { get; set; }
  119. /// <summary>
  120. /// Gets a value indicating whether this instance is active.
  121. /// </summary>
  122. /// <value><c>true</c> if this instance is active; otherwise, <c>false</c>.</value>
  123. public bool IsActive
  124. {
  125. get
  126. {
  127. if (SessionController != null)
  128. {
  129. return SessionController.IsSessionActive;
  130. }
  131. return (DateTime.UtcNow - LastActivityDate).TotalMinutes <= 10;
  132. }
  133. }
  134. /// <summary>
  135. /// Gets a value indicating whether [supports remote control].
  136. /// </summary>
  137. /// <value><c>true</c> if [supports remote control]; otherwise, <c>false</c>.</value>
  138. public bool SupportsRemoteControl
  139. {
  140. get
  141. {
  142. if (SessionController != null)
  143. {
  144. return SessionController.SupportsMediaRemoteControl;
  145. }
  146. return false;
  147. }
  148. }
  149. public bool ContainsUser(Guid userId)
  150. {
  151. return (UserId ?? Guid.Empty) == UserId || AdditionalUsers.Any(i => userId == new Guid(i.UserId));
  152. }
  153. }
  154. }