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.ts 6.4KB

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