SessionInfo.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. SupportedCommands = new List<string>();
  27. }
  28. public List<SessionUserInfo> AdditionalUsers { get; set; }
  29. /// <summary>
  30. /// Gets or sets the remote end point.
  31. /// </summary>
  32. /// <value>The remote end point.</value>
  33. public string RemoteEndPoint { get; set; }
  34. /// <summary>
  35. /// Gets or sets a value indicating whether this instance can seek.
  36. /// </summary>
  37. /// <value><c>true</c> if this instance can seek; otherwise, <c>false</c>.</value>
  38. public bool CanSeek { get; set; }
  39. /// <summary>
  40. /// Gets or sets the queueable media types.
  41. /// </summary>
  42. /// <value>The queueable media types.</value>
  43. public List<string> QueueableMediaTypes { get; set; }
  44. /// <summary>
  45. /// Gets or sets the playable media types.
  46. /// </summary>
  47. /// <value>The playable media types.</value>
  48. public List<string> PlayableMediaTypes { get; set; }
  49. /// <summary>
  50. /// Gets or sets the id.
  51. /// </summary>
  52. /// <value>The id.</value>
  53. public Guid Id { get; set; }
  54. /// <summary>
  55. /// Gets or sets the user id.
  56. /// </summary>
  57. /// <value>The user id.</value>
  58. public Guid? UserId { get; set; }
  59. /// <summary>
  60. /// Gets or sets the username.
  61. /// </summary>
  62. /// <value>The username.</value>
  63. public string UserName { get; set; }
  64. /// <summary>
  65. /// Gets or sets the type of the client.
  66. /// </summary>
  67. /// <value>The type of the client.</value>
  68. public string Client { get; set; }
  69. /// <summary>
  70. /// Gets or sets the last activity date.
  71. /// </summary>
  72. /// <value>The last activity date.</value>
  73. public DateTime LastActivityDate { get; set; }
  74. /// <summary>
  75. /// Gets or sets the name of the device.
  76. /// </summary>
  77. /// <value>The name of the device.</value>
  78. public string DeviceName { get; set; }
  79. /// <summary>
  80. /// Gets or sets the now viewing context.
  81. /// </summary>
  82. /// <value>The now viewing context.</value>
  83. public string NowViewingContext { get; set; }
  84. /// <summary>
  85. /// Gets or sets the type of the now viewing item.
  86. /// </summary>
  87. /// <value>The type of the now viewing item.</value>
  88. public string NowViewingItemType { get; set; }
  89. /// <summary>
  90. /// Gets or sets the now viewing item identifier.
  91. /// </summary>
  92. /// <value>The now viewing item identifier.</value>
  93. public string NowViewingItemId { get; set; }
  94. /// <summary>
  95. /// Gets or sets the name of the now viewing item.
  96. /// </summary>
  97. /// <value>The name of the now viewing item.</value>
  98. public string NowViewingItemName { get; set; }
  99. /// <summary>
  100. /// Gets or sets the now playing item.
  101. /// </summary>
  102. /// <value>The now playing item.</value>
  103. public BaseItem NowPlayingItem { get; set; }
  104. /// <summary>
  105. /// Gets or sets the now playing media version identifier.
  106. /// </summary>
  107. /// <value>The now playing media version identifier.</value>
  108. public string NowPlayingMediaSourceId { get; set; }
  109. /// <summary>
  110. /// Gets or sets the now playing run time ticks.
  111. /// </summary>
  112. /// <value>The now playing run time ticks.</value>
  113. public long? NowPlayingRunTimeTicks { get; set; }
  114. /// <summary>
  115. /// Gets or sets the now playing position ticks.
  116. /// </summary>
  117. /// <value>The now playing position ticks.</value>
  118. public long? NowPlayingPositionTicks { get; set; }
  119. /// <summary>
  120. /// Gets or sets a value indicating whether this instance is paused.
  121. /// </summary>
  122. /// <value><c>true</c> if this instance is paused; otherwise, <c>false</c>.</value>
  123. public bool IsPaused { get; set; }
  124. /// <summary>
  125. /// Gets or sets a value indicating whether this instance is muted.
  126. /// </summary>
  127. /// <value><c>true</c> if this instance is muted; otherwise, <c>false</c>.</value>
  128. public bool IsMuted { get; set; }
  129. /// <summary>
  130. /// Gets or sets the volume level, on a scale of 0-100
  131. /// </summary>
  132. /// <value>The volume level.</value>
  133. public int? VolumeLevel { get; set; }
  134. public int? NowPlayingAudioStreamIndex { get; set; }
  135. public int? NowPlayingSubtitleStreamIndex { get; set; }
  136. /// <summary>
  137. /// Gets or sets the device id.
  138. /// </summary>
  139. /// <value>The device id.</value>
  140. public string DeviceId { get; set; }
  141. /// <summary>
  142. /// Gets or sets the application version.
  143. /// </summary>
  144. /// <value>The application version.</value>
  145. public string ApplicationVersion { get; set; }
  146. /// <summary>
  147. /// Gets or sets the session controller.
  148. /// </summary>
  149. /// <value>The session controller.</value>
  150. public ISessionController SessionController { get; set; }
  151. /// <summary>
  152. /// Gets or sets the supported commands.
  153. /// </summary>
  154. /// <value>The supported commands.</value>
  155. public List<string> SupportedCommands { get; set; }
  156. /// <summary>
  157. /// Gets a value indicating whether this instance is active.
  158. /// </summary>
  159. /// <value><c>true</c> if this instance is active; otherwise, <c>false</c>.</value>
  160. public bool IsActive
  161. {
  162. get
  163. {
  164. if (SessionController != null)
  165. {
  166. return SessionController.IsSessionActive;
  167. }
  168. return (DateTime.UtcNow - LastActivityDate).TotalMinutes <= 10;
  169. }
  170. }
  171. /// <summary>
  172. /// Gets a value indicating whether [supports remote control].
  173. /// </summary>
  174. /// <value><c>true</c> if [supports remote control]; otherwise, <c>false</c>.</value>
  175. public bool SupportsRemoteControl
  176. {
  177. get
  178. {
  179. if (SessionController != null)
  180. {
  181. return SessionController.SupportsMediaRemoteControl;
  182. }
  183. return false;
  184. }
  185. }
  186. public bool ContainsUser(Guid userId)
  187. {
  188. return (UserId ?? Guid.Empty) == UserId || AdditionalUsers.Any(i => userId == new Guid(i.UserId));
  189. }
  190. }
  191. }