You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SignalingLayer.js 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. import Listenable from '../../modules/util/Listenable';
  2. import { MediaType } from '../../service/RTC/MediaType';
  3. /**
  4. * @typedef {string} EndpointId
  5. */
  6. /**
  7. * @typedef {string} SourceName
  8. */
  9. /**
  10. * @typedef {Object} SourceInfo
  11. *
  12. * @property {SourceName} sourceName - Name of the media source.
  13. * @property {boolean} [muted=false] - Tells if the source is muted (paused?).
  14. * @property {string} [videoType] - Type of the video for video type.
  15. */
  16. /**
  17. * Generates a source name.
  18. *
  19. * @param {EndpointId} endpointId - Jitsi Endpoint Id.
  20. * @param {MediaType} mediaType - the media type string.
  21. * @param {number} trackIdx - Track index (or sender idx? - to be figured out) starting from 0.
  22. * @returns {SourceName} eg. endpointA-v0
  23. */
  24. export function getSourceNameForJitsiTrack(endpointId, mediaType, trackIdx) {
  25. const firstLetterOfMediaType = mediaType.substring(0, 1);
  26. return `${endpointId}-${firstLetterOfMediaType}${trackIdx}`;
  27. }
  28. /**
  29. * Extracts MediaType from give source name (must be in the correct format as generated by
  30. * {@link getSourceNameForJitsiTrack}).
  31. *
  32. * @param {SourceName} sourceName - the source name.
  33. * @returns {MediaType}
  34. */
  35. export function getMediaTypeFromSourceName(sourceName) {
  36. const firstLetterOfMediaTypeIdx = sourceName.lastIndexOf('-') + 1;
  37. if (firstLetterOfMediaTypeIdx <= 0) {
  38. throw new Error(`Invalid source name: ${sourceName}`);
  39. }
  40. const firstLetterOfMediaType = sourceName.substr(firstLetterOfMediaTypeIdx, 1);
  41. for (const type of Object.values(MediaType)) {
  42. if (type.substr(0, 1) === firstLetterOfMediaType) {
  43. return type;
  44. }
  45. }
  46. throw new Error(`Invalid source name: ${sourceName}`);
  47. }
  48. /**
  49. * Extracts source index (zero based) from a given source name (must be in the correct format as generated by
  50. * {@link getSourceNameForJitsiTrack}).
  51. *
  52. * @param {SourceName} sourceName - the source name, eg. endpointA-v0.
  53. * @returns {number}
  54. */
  55. export function getSourceIndexFromSourceName(sourceName) {
  56. const nameParts = sourceName.split('-');
  57. const trackIdx = Number(nameParts[nameParts.length - 1].substring(1));
  58. if (Number.isNaN(trackIdx)) {
  59. throw new Error(`Failed to parse track idx for source name: ${sourceName}`);
  60. }
  61. return trackIdx;
  62. }
  63. /**
  64. * An object that carries the info about specific media type advertised by
  65. * participant in the signaling channel.
  66. * @typedef {Object} PeerMediaInfo
  67. * @property {boolean} muted indicates if the media is currently muted
  68. * @property {VideoType|undefined} videoType the type of the video if applicable
  69. */
  70. /**
  71. * Interface used to expose the information carried over the signaling channel
  72. * which is not available to the RTC module in the media SDP.
  73. *
  74. * @interface SignalingLayer
  75. */
  76. export default class SignalingLayer extends Listenable {
  77. /**
  78. * Obtains the info about given media advertised in the MUC presence of
  79. * the participant identified by the given MUC JID.
  80. * @param {string} owner the MUC jid of the participant for whom
  81. * {@link PeerMediaInfo} will be obtained.
  82. * @param {MediaType} mediaType the type of the media for which presence
  83. * @param {SourceName} sourceName - The name of the source for which the info is to be obtained.
  84. * info will be obtained.
  85. * @return {PeerMediaInfo|null} presenceInfo an object with media presence
  86. * info or <tt>null</tt> either if there is no presence available for given
  87. * JID or if the media type given is invalid.
  88. *
  89. * @deprecated This method is to be replaced with getPeerSourceInfo.
  90. */
  91. getPeerMediaInfo(owner, mediaType, sourceName) { // eslint-disable-line no-unused-vars
  92. throw new Error('not implemented');
  93. }
  94. /**
  95. * Obtains the info about a source for given name and endpoint ID.
  96. * @param {EndpointId} owner - The owner's endpoint ID.
  97. * @param {SourceName} sourceName - The name of the source for which the info is to be obtained.
  98. * @returns {SourceInfo | undefined}
  99. */
  100. getPeerSourceInfo(owner, sourceName) { // eslint-disable-line no-unused-vars
  101. throw new Error('not implemented');
  102. }
  103. /**
  104. * Obtains the endpoint ID for given SSRC.
  105. * @param {number} ssrc the SSRC number.
  106. * @return {string|null} the endpoint ID for given media SSRC.
  107. */
  108. getSSRCOwner(ssrc) { // eslint-disable-line no-unused-vars
  109. throw new Error('not implemented');
  110. }
  111. /**
  112. * Obtains the source name for given SSRC.
  113. * @param {number} ssrc the track's SSRC identifier.
  114. * @returns {SourceName | undefined} the track's source name.
  115. */
  116. getTrackSourceName(ssrc) { // eslint-disable-line no-unused-vars
  117. throw new Error('not implemented');
  118. }
  119. /**
  120. * Removes the association between a given SSRC and its current owner so that it can re-used when the SSRC gets
  121. * remapped to another source from a different endpoint.
  122. * @param {number} ssrc a list of SSRCs.
  123. */
  124. removeSSRCOwners(ssrcList) { // eslint-disable-line no-unused-vars
  125. }
  126. /**
  127. * Set an SSRC owner.
  128. * @param {number} ssrc an SSRC to be owned
  129. * @param {string} endpointId owner's ID (MUC nickname)
  130. * @throws TypeError if <tt>ssrc</tt> is not a number
  131. */
  132. setSSRCOwner(ssrc, endpointId) { // eslint-disable-line no-unused-vars
  133. }
  134. /**
  135. * Adjusts muted status of given track.
  136. *
  137. * @param {SourceName} sourceName - the name of the track's source.
  138. * @param {boolean} muted - the new muted status.
  139. * @returns {boolean}
  140. */
  141. setTrackMuteStatus(sourceName, muted) { // eslint-disable-line no-unused-vars
  142. }
  143. /**
  144. * Saves the source name for a track identified by it's ssrc.
  145. * @param {number} ssrc the ssrc of the target track.
  146. * @param {SourceName} sourceName the track's source name to save.
  147. * @throws TypeError if <tt>ssrc</tt> is not a number
  148. */
  149. setTrackSourceName(ssrc, sourceName) { // eslint-disable-line no-unused-vars
  150. }
  151. /**
  152. * Sets track's video type.
  153. * @param {SourceName} sourceName - the track's source name.
  154. * @param {VideoType} videoType - the new video type.
  155. * @returns {boolean}
  156. */
  157. setTrackVideoType(sourceName, videoType) { // eslint-disable-line no-unused-vars
  158. }
  159. /**
  160. * Removes the SSRCs associated with a given endpoint from the SSRC owners.
  161. *
  162. * @param {string} id endpoint id of the participant leaving the call.
  163. * @returns {void}
  164. */
  165. updateSsrcOwnersOnLeave(id) { // eslint-disable-line no-unused-vars
  166. }
  167. }