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 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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.indexOf('-') + 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. * An object that carries the info about specific media type advertised by
  50. * participant in the signaling channel.
  51. * @typedef {Object} PeerMediaInfo
  52. * @property {boolean} muted indicates if the media is currently muted
  53. * @property {VideoType|undefined} videoType the type of the video if applicable
  54. */
  55. /**
  56. * Interface used to expose the information carried over the signaling channel
  57. * which is not available to the RTC module in the media SDP.
  58. *
  59. * @interface SignalingLayer
  60. */
  61. export default class SignalingLayer extends Listenable {
  62. /**
  63. * Obtains the endpoint ID for given SSRC.
  64. * @param {number} ssrc the SSRC number.
  65. * @return {string|null} the endpoint ID for given media SSRC.
  66. */
  67. getSSRCOwner(ssrc) { // eslint-disable-line no-unused-vars
  68. throw new Error('not implemented');
  69. }
  70. /**
  71. * Obtains the info about given media advertised in the MUC presence of
  72. * the participant identified by the given MUC JID.
  73. * @param {string} owner the MUC jid of the participant for whom
  74. * {@link PeerMediaInfo} will be obtained.
  75. * @param {MediaType} mediaType the type of the media for which presence
  76. * @param {SourceName} sourceName - The name of the source for which the info is to be obtained.
  77. * info will be obtained.
  78. * @return {PeerMediaInfo|null} presenceInfo an object with media presence
  79. * info or <tt>null</tt> either if there is no presence available for given
  80. * JID or if the media type given is invalid.
  81. *
  82. * @deprecated This method is to be replaced with getPeerSourceInfo.
  83. */
  84. getPeerMediaInfo(owner, mediaType, sourceName) { // eslint-disable-line no-unused-vars
  85. throw new Error('not implemented');
  86. }
  87. /**
  88. * Obtains the info about a source for given name and endpoint ID.
  89. * @param {EndpointId} owner - The owner's endpoint ID.
  90. * @param {SourceName} sourceName - The name of the source for which the info is to be obtained.
  91. * @returns {SourceInfo | undefined}
  92. */
  93. getPeerSourceInfo(owner, sourceName) { // eslint-disable-line no-unused-vars
  94. throw new Error('not implemented');
  95. }
  96. /**
  97. * Obtains the source name for given SSRC.
  98. * @param {number} ssrc the track's SSRC identifier.
  99. * @returns {SourceName | undefined} the track's source name.
  100. */
  101. getTrackSourceName(ssrc) { // eslint-disable-line no-unused-vars
  102. throw new Error('not implemented');
  103. }
  104. /**
  105. * Set an SSRC owner.
  106. * @param {number} ssrc an SSRC to be owned
  107. * @param {string} endpointId owner's ID (MUC nickname)
  108. * @throws TypeError if <tt>ssrc</tt> is not a number
  109. */
  110. setSSRCOwner(ssrc, endpointId) { // eslint-disable-line no-unused-vars
  111. }
  112. /**
  113. * Adjusts muted status of given track.
  114. *
  115. * @param {SourceName} sourceName - the name of the track's source.
  116. * @param {boolean} muted - the new muted status.
  117. * @returns {boolean}
  118. */
  119. setTrackMuteStatus(sourceName, muted) { // eslint-disable-line no-unused-vars
  120. }
  121. /**
  122. * Saves the source name for a track identified by it's ssrc.
  123. * @param {number} ssrc the ssrc of the target track.
  124. * @param {SourceName} sourceName the track's source name to save.
  125. * @throws TypeError if <tt>ssrc</tt> is not a number
  126. */
  127. setTrackSourceName(ssrc, sourceName) { // eslint-disable-line no-unused-vars
  128. }
  129. /**
  130. * Sets track's video type.
  131. * @param {SourceName} sourceName - the track's source name.
  132. * @param {VideoType} videoType - the new video type.
  133. * @returns {boolean}
  134. */
  135. setTrackVideoType(sourceName, videoType) { // eslint-disable-line no-unused-vars
  136. }
  137. }