2
0

SessionInfo.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 supported commands.
  109. /// </summary>
  110. /// <value>The supported commands.</value>
  111. public List<string> SupportedCommands
  112. {
  113. get
  114. {
  115. if (Capabilities == null)
  116. {
  117. return new List<string>();
  118. }
  119. return Capabilities.SupportedCommands;
  120. }
  121. }
  122. public TranscodingInfo TranscodingInfo { get; set; }
  123. /// <summary>
  124. /// Gets a value indicating whether this instance is active.
  125. /// </summary>
  126. /// <value><c>true</c> if this instance is active; otherwise, <c>false</c>.</value>
  127. public bool IsActive
  128. {
  129. get
  130. {
  131. if (SessionController != null)
  132. {
  133. return SessionController.IsSessionActive;
  134. }
  135. return (DateTime.UtcNow - LastActivityDate).TotalMinutes <= 10;
  136. }
  137. }
  138. public bool SupportsMediaControl
  139. {
  140. get
  141. {
  142. if (Capabilities == null || !Capabilities.SupportsMediaControl)
  143. {
  144. return false;
  145. }
  146. if (SessionController != null)
  147. {
  148. return SessionController.SupportsMediaControl;
  149. }
  150. return false;
  151. }
  152. }
  153. public bool ContainsUser(string userId)
  154. {
  155. return ContainsUser(new Guid(userId));
  156. }
  157. public bool ContainsUser(Guid userId)
  158. {
  159. return (UserId ?? Guid.Empty) == userId || AdditionalUsers.Any(i => userId == new Guid(i.UserId));
  160. }
  161. }
  162. }