Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

CustomSignalingLayer.ts 3.2KB

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