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.

CustomSignalingLayer.ts 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import { getLogger } from '@jitsi/logger';
  2. import { MediaType } from '../../service/RTC/MediaType';
  3. import { type IPeerMediaInfo, default as SignalingLayer } from '../../service/RTC/SignalingLayer';
  4. import ChatRoom from '../xmpp/ChatRoom';
  5. const logger = getLogger('modules/proxyconnection/CustomSignalingLayer');
  6. /**
  7. * Custom semi-mock implementation for the Proxy connection service.
  8. */
  9. export default class CustomSignalingLayer extends SignalingLayer {
  10. /**
  11. * A map that stores SSRCs of remote streams.
  12. * @type {Map<number, string>} maps SSRC number to jid
  13. */
  14. private ssrcOwners: Map<number, string>;
  15. /**
  16. *
  17. * @type {ChatRoom|null}
  18. */
  19. public chatRoom: ChatRoom | null;
  20. /**
  21. * Creates new instance.
  22. */
  23. constructor() {
  24. super();
  25. this.ssrcOwners = new Map<number, string>();
  26. this.chatRoom = null;
  27. }
  28. /**
  29. * @inheritDoc
  30. */
  31. getPeerMediaInfo(_owner: string, _mediaType: MediaType, _sourceName: string): IPeerMediaInfo {
  32. return { };
  33. }
  34. /**
  35. * @inheritDoc
  36. */
  37. getPeerSourceInfo(_owner: string, _sourceName: string): any {
  38. return undefined;
  39. }
  40. /**
  41. * @inheritDoc
  42. */
  43. getSSRCOwner(ssrc: number): string | undefined {
  44. return this.ssrcOwners.get(ssrc);
  45. }
  46. /**
  47. * @inheritDoc
  48. */
  49. getTrackSourceName(_ssrc: number): string | undefined {
  50. return undefined;
  51. }
  52. /**
  53. * @inheritDoc
  54. */
  55. removeSSRCOwners(ssrcList: number[]): void {
  56. if (!ssrcList?.length) {
  57. return;
  58. }
  59. for (const ssrc of ssrcList) {
  60. this.ssrcOwners.delete(ssrc);
  61. }
  62. }
  63. /**
  64. * Sets the <tt>ChatRoom</tt> instance used.
  65. * @param {ChatRoom} room
  66. */
  67. setChatRoom(room: ChatRoom): void {
  68. this.chatRoom = room;
  69. }
  70. /**
  71. * @inheritDoc
  72. */
  73. setSSRCOwner(ssrc: number, endpointId: string): void {
  74. if (typeof ssrc !== 'number') {
  75. throw new TypeError(`SSRC(${ssrc}) must be a number`);
  76. }
  77. // Now signaling layer instance is shared between different JingleSessionPC instances, so although very unlikely
  78. // an SSRC conflict could potentially occur. Log a message to make debugging easier.
  79. const existingOwner = this.ssrcOwners.get(ssrc);
  80. if (existingOwner && existingOwner !== endpointId) {
  81. logger.error(`SSRC owner re-assigned from ${existingOwner} to ${endpointId}`);
  82. }
  83. this.ssrcOwners.set(ssrc, endpointId);
  84. }
  85. /**
  86. * @inheritDoc
  87. */
  88. setTrackMuteStatus(_sourceName: string, _muted: boolean): boolean {
  89. return false;
  90. }
  91. /**
  92. * @inheritDoc
  93. */
  94. setTrackVideoType(_sourceName: string, _videoType: string): boolean {
  95. return false;
  96. }
  97. /**
  98. * @inheritDoc
  99. */
  100. updateSsrcOwnersOnLeave(id: string): void {
  101. const ssrcs = Array.from(this.ssrcOwners)
  102. .filter((entry: [number, string]) => entry[1] === id)
  103. .map((entry: [number, string]) => entry[0]);
  104. if (!ssrcs?.length) {
  105. return;
  106. }
  107. this.removeSSRCOwners(ssrcs);
  108. }
  109. }