SessionInfo.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. using MediaBrowser.Model.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. PlayState = new PlayerStateInfo();
  18. }
  19. public PlayerStateInfo PlayState { get; set; }
  20. public List<SessionUserInfo> AdditionalUsers { get; set; }
  21. public ClientCapabilities Capabilities { get; set; }
  22. /// <summary>
  23. /// Gets or sets the remote end point.
  24. /// </summary>
  25. /// <value>The remote end point.</value>
  26. public string RemoteEndPoint { get; set; }
  27. /// <summary>
  28. /// Gets or sets the queueable media types.
  29. /// </summary>
  30. /// <value>The queueable media types.</value>
  31. public List<string> QueueableMediaTypes { get; set; }
  32. /// <summary>
  33. /// Gets or sets the playable media types.
  34. /// </summary>
  35. /// <value>The playable media types.</value>
  36. public List<string> PlayableMediaTypes
  37. {
  38. get
  39. {
  40. if (Capabilities == null)
  41. {
  42. return new List<string>();
  43. }
  44. return Capabilities.PlayableMediaTypes;
  45. }
  46. }
  47. /// <summary>
  48. /// Gets or sets the id.
  49. /// </summary>
  50. /// <value>The id.</value>
  51. public string Id { get; set; }
  52. /// <summary>
  53. /// Gets or sets the user id.
  54. /// </summary>
  55. /// <value>The user id.</value>
  56. public Guid? UserId { get; set; }
  57. /// <summary>
  58. /// Gets or sets the username.
  59. /// </summary>
  60. /// <value>The username.</value>
  61. public string UserName { get; set; }
  62. /// <summary>
  63. /// Gets or sets the type of the client.
  64. /// </summary>
  65. /// <value>The type of the client.</value>
  66. public string Client { get; set; }
  67. /// <summary>
  68. /// Gets or sets the last activity date.
  69. /// </summary>
  70. /// <value>The last activity date.</value>
  71. public DateTime LastActivityDate { get; set; }
  72. /// <summary>
  73. /// Gets or sets the last playback check in.
  74. /// </summary>
  75. /// <value>The last playback check in.</value>
  76. public DateTime LastPlaybackCheckIn { get; set; }
  77. /// <summary>
  78. /// Gets or sets the name of the device.
  79. /// </summary>
  80. /// <value>The name of the device.</value>
  81. public string DeviceName { get; set; }
  82. /// <summary>
  83. /// Gets or sets the name of the now viewing item.
  84. /// </summary>
  85. /// <value>The name of the now viewing item.</value>
  86. public BaseItemInfo NowViewingItem { get; set; }
  87. /// <summary>
  88. /// Gets or sets the now playing item.
  89. /// </summary>
  90. /// <value>The now playing item.</value>
  91. public BaseItemInfo NowPlayingItem { get; set; }
  92. /// <summary>
  93. /// Gets or sets the device id.
  94. /// </summary>
  95. /// <value>The device id.</value>
  96. public string DeviceId { get; set; }
  97. /// <summary>
  98. /// Gets or sets the application version.
  99. /// </summary>
  100. /// <value>The application version.</value>
  101. public string ApplicationVersion { get; set; }
  102. /// <summary>
  103. /// Gets or sets the session controller.
  104. /// </summary>
  105. /// <value>The session controller.</value>
  106. public ISessionController SessionController { get; set; }
  107. /// <summary>
  108. /// Gets or sets the application icon URL.
  109. /// </summary>
  110. /// <value>The application icon URL.</value>
  111. public string AppIconUrl { get; set; }
  112. /// <summary>
  113. /// Gets or sets the supported commands.
  114. /// </summary>
  115. /// <value>The supported commands.</value>
  116. public List<string> SupportedCommands
  117. {
  118. get
  119. {
  120. if (Capabilities == null)
  121. {
  122. return new List<string>();
  123. }
  124. return Capabilities.SupportedCommands;
  125. }
  126. }
  127. public TranscodingInfo TranscodingInfo { get; set; }
  128. /// <summary>
  129. /// Gets a value indicating whether this instance is active.
  130. /// </summary>
  131. /// <value><c>true</c> if this instance is active; otherwise, <c>false</c>.</value>
  132. public bool IsActive
  133. {
  134. get
  135. {
  136. if (SessionController != null)
  137. {
  138. return SessionController.IsSessionActive;
  139. }
  140. return (DateTime.UtcNow - LastActivityDate).TotalMinutes <= 10;
  141. }
  142. }
  143. public bool SupportsMediaControl
  144. {
  145. get
  146. {
  147. if (Capabilities == null || !Capabilities.SupportsMediaControl)
  148. {
  149. return false;
  150. }
  151. if (SessionController != null)
  152. {
  153. return SessionController.SupportsMediaControl;
  154. }
  155. return false;
  156. }
  157. }
  158. public bool ContainsUser(string userId)
  159. {
  160. return ContainsUser(new Guid(userId));
  161. }
  162. public bool ContainsUser(Guid userId)
  163. {
  164. return (UserId ?? Guid.Empty) == userId || AdditionalUsers.Any(i => userId == new Guid(i.UserId));
  165. }
  166. }
  167. }