SessionInfo.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. using MediaBrowser.Controller.Entities;
  2. using MediaBrowser.Model.Entities;
  3. using MediaBrowser.Model.Session;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  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. PlayableMediaTypes = new List<string>
  18. {
  19. MediaType.Audio,
  20. MediaType.Book,
  21. MediaType.Game,
  22. MediaType.Photo,
  23. MediaType.Video
  24. };
  25. AdditionalUsers = new List<SessionUserInfo>();
  26. }
  27. public List<SessionUserInfo> AdditionalUsers { get; set; }
  28. /// <summary>
  29. /// Gets or sets the remote end point.
  30. /// </summary>
  31. /// <value>The remote end point.</value>
  32. public string RemoteEndPoint { get; set; }
  33. /// <summary>
  34. /// Gets or sets a value indicating whether this instance can seek.
  35. /// </summary>
  36. /// <value><c>true</c> if this instance can seek; otherwise, <c>false</c>.</value>
  37. public bool CanSeek { get; set; }
  38. /// <summary>
  39. /// Gets or sets the queueable media types.
  40. /// </summary>
  41. /// <value>The queueable media types.</value>
  42. public List<string> QueueableMediaTypes { get; set; }
  43. /// <summary>
  44. /// Gets or sets the playable media types.
  45. /// </summary>
  46. /// <value>The playable media types.</value>
  47. public List<string> PlayableMediaTypes { get; set; }
  48. /// <summary>
  49. /// Gets or sets the id.
  50. /// </summary>
  51. /// <value>The id.</value>
  52. public Guid 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 name of the device.
  75. /// </summary>
  76. /// <value>The name of the device.</value>
  77. public string DeviceName { get; set; }
  78. /// <summary>
  79. /// Gets or sets the now viewing context.
  80. /// </summary>
  81. /// <value>The now viewing context.</value>
  82. public string NowViewingContext { get; set; }
  83. /// <summary>
  84. /// Gets or sets the type of the now viewing item.
  85. /// </summary>
  86. /// <value>The type of the now viewing item.</value>
  87. public string NowViewingItemType { get; set; }
  88. /// <summary>
  89. /// Gets or sets the now viewing item identifier.
  90. /// </summary>
  91. /// <value>The now viewing item identifier.</value>
  92. public string NowViewingItemId { get; set; }
  93. /// <summary>
  94. /// Gets or sets the name of the now viewing item.
  95. /// </summary>
  96. /// <value>The name of the now viewing item.</value>
  97. public string NowViewingItemName { get; set; }
  98. /// <summary>
  99. /// Gets or sets the now playing item.
  100. /// </summary>
  101. /// <value>The now playing item.</value>
  102. public BaseItem NowPlayingItem { get; set; }
  103. /// <summary>
  104. /// Gets or sets the now playing media version identifier.
  105. /// </summary>
  106. /// <value>The now playing media version identifier.</value>
  107. public string NowPlayingMediaSourceId { get; set; }
  108. /// <summary>
  109. /// Gets or sets the now playing run time ticks.
  110. /// </summary>
  111. /// <value>The now playing run time ticks.</value>
  112. public long? NowPlayingRunTimeTicks { get; set; }
  113. /// <summary>
  114. /// Gets or sets the now playing position ticks.
  115. /// </summary>
  116. /// <value>The now playing position ticks.</value>
  117. public long? NowPlayingPositionTicks { get; set; }
  118. /// <summary>
  119. /// Gets or sets a value indicating whether this instance is paused.
  120. /// </summary>
  121. /// <value><c>true</c> if this instance is paused; otherwise, <c>false</c>.</value>
  122. public bool IsPaused { get; set; }
  123. /// <summary>
  124. /// Gets or sets a value indicating whether this instance is muted.
  125. /// </summary>
  126. /// <value><c>true</c> if this instance is muted; otherwise, <c>false</c>.</value>
  127. public bool IsMuted { get; set; }
  128. /// <summary>
  129. /// Gets or sets the device id.
  130. /// </summary>
  131. /// <value>The device id.</value>
  132. public string DeviceId { get; set; }
  133. /// <summary>
  134. /// Gets or sets the application version.
  135. /// </summary>
  136. /// <value>The application version.</value>
  137. public string ApplicationVersion { get; set; }
  138. /// <summary>
  139. /// Gets or sets the session controller.
  140. /// </summary>
  141. /// <value>The session controller.</value>
  142. public ISessionController SessionController { get; set; }
  143. /// <summary>
  144. /// Gets or sets a value indicating whether [supports fullscreen toggle].
  145. /// </summary>
  146. /// <value><c>true</c> if [supports fullscreen toggle]; otherwise, <c>false</c>.</value>
  147. public bool SupportsFullscreenToggle { get; set; }
  148. /// <summary>
  149. /// Gets or sets a value indicating whether [supports osd toggle].
  150. /// </summary>
  151. /// <value><c>true</c> if [supports osd toggle]; otherwise, <c>false</c>.</value>
  152. public bool SupportsOsdToggle { get; set; }
  153. /// <summary>
  154. /// Gets or sets a value indicating whether [supports navigation commands].
  155. /// </summary>
  156. /// <value><c>true</c> if [supports navigation commands]; otherwise, <c>false</c>.</value>
  157. public bool SupportsNavigationControl { get; set; }
  158. /// <summary>
  159. /// Gets a value indicating whether this instance is active.
  160. /// </summary>
  161. /// <value><c>true</c> if this instance is active; otherwise, <c>false</c>.</value>
  162. public bool IsActive
  163. {
  164. get
  165. {
  166. if (SessionController != null)
  167. {
  168. return SessionController.IsSessionActive;
  169. }
  170. return (DateTime.UtcNow - LastActivityDate).TotalMinutes <= 10;
  171. }
  172. }
  173. /// <summary>
  174. /// Gets a value indicating whether [supports remote control].
  175. /// </summary>
  176. /// <value><c>true</c> if [supports remote control]; otherwise, <c>false</c>.</value>
  177. public bool SupportsRemoteControl
  178. {
  179. get
  180. {
  181. if (SessionController != null)
  182. {
  183. return SessionController.SupportsMediaRemoteControl;
  184. }
  185. return false;
  186. }
  187. }
  188. public bool ContainsUser(Guid userId)
  189. {
  190. return (UserId ?? Guid.Empty) == UserId || AdditionalUsers.Any(i => userId == new Guid(i.UserId));
  191. }
  192. }
  193. }