SessionInfo.cs 5.8 KB

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