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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import Listenable from '../../modules/util/Listenable';
  2. import * as 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. * info will be obtained.
  77. * @return {PeerMediaInfo|null} presenceInfo an object with media presence
  78. * info or <tt>null</tt> either if there is no presence available for given
  79. * JID or if the media type given is invalid.
  80. *
  81. * @deprecated This method is to be replaced with getPeerSourceInfo.
  82. */
  83. getPeerMediaInfo(owner, mediaType) { // eslint-disable-line no-unused-vars
  84. throw new Error('not implemented');
  85. }
  86. /**
  87. * Obtains the info about a source for given name and endpoint ID.
  88. * @param {EndpointId} owner - The owner's endpoint ID.
  89. * @param {SourceName} sourceName - The name of the source for which the info is to be obtained.
  90. * @returns {SourceInfo | undefined}
  91. */
  92. getPeerSourceInfo(owner, sourceName) { // eslint-disable-line no-unused-vars
  93. throw new Error('not implemented');
  94. }
  95. /**
  96. * Obtains the source name for given SSRC.
  97. * @param {number} ssrc the track's SSRC identifier.
  98. * @returns {SourceName | undefined} the track's source name.
  99. */
  100. getTrackSourceName(ssrc) { // eslint-disable-line no-unused-vars
  101. throw new Error('not implemented');
  102. }
  103. }