SessionInfo.cs 5.1 KB

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