Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* global connection, Strophe, updateLargeVideo, focusedVideoSrc*/
  2. // cache datachannels to avoid garbage collection
  3. // https://code.google.com/p/chromium/issues/detail?id=405545
  4. var _dataChannels = [];
  5. /**
  6. * Callback triggered by PeerConnection when new data channel is opened
  7. * on the bridge.
  8. * @param event the event info object.
  9. */
  10. function onDataChannel(event)
  11. {
  12. var dataChannel = event.channel;
  13. dataChannel.onopen = function ()
  14. {
  15. console.info("Data channel opened by the Videobridge!", dataChannel);
  16. // Code sample for sending string and/or binary data
  17. // Sends String message to the bridge
  18. //dataChannel.send("Hello bridge!");
  19. // Sends 12 bytes binary message to the bridge
  20. //dataChannel.send(new ArrayBuffer(12));
  21. };
  22. dataChannel.onerror = function (error)
  23. {
  24. console.error("Data Channel Error:", error, dataChannel);
  25. };
  26. dataChannel.onmessage = function (event)
  27. {
  28. var data = event.data;
  29. // JSON
  30. var obj;
  31. try
  32. {
  33. obj = JSON.parse(data);
  34. }
  35. catch (e)
  36. {
  37. console.error(
  38. "Failed to parse data channel message as JSON: ",
  39. data,
  40. dataChannel);
  41. }
  42. if (('undefined' !== typeof(obj)) && (null !== obj))
  43. {
  44. var colibriClass = obj.colibriClass;
  45. if ("DominantSpeakerEndpointChangeEvent" === colibriClass)
  46. {
  47. // Endpoint ID from the Videobridge.
  48. var dominantSpeakerEndpoint = obj.dominantSpeakerEndpoint;
  49. console.info(
  50. "Data channel new dominant speaker event: ",
  51. dominantSpeakerEndpoint);
  52. $(document).trigger(
  53. 'dominantspeakerchanged',
  54. [dominantSpeakerEndpoint]);
  55. }
  56. else if ("LastNEndpointsChangeEvent" === colibriClass)
  57. {
  58. // The new/latest list of last-n endpoint IDs.
  59. var lastNEndpoints = obj.lastNEndpoints;
  60. /*
  61. * The list of endpoint IDs which are entering the list of
  62. * last-n at this time i.e. were not in the old list of last-n
  63. * endpoint IDs.
  64. */
  65. var endpointsEnteringLastN = obj.endpointsEnteringLastN;
  66. var stream = obj.stream;
  67. console.log(
  68. "Data channel new last-n event: ",
  69. lastNEndpoints, endpointsEnteringLastN, obj);
  70. $(document).trigger(
  71. 'lastnchanged',
  72. [lastNEndpoints, endpointsEnteringLastN, stream]);
  73. }
  74. else
  75. {
  76. console.debug("Data channel JSON-formatted message: ", obj);
  77. }
  78. }
  79. };
  80. dataChannel.onclose = function ()
  81. {
  82. console.info("The Data Channel closed", dataChannel);
  83. var idx = _dataChannels.indexOf(dataChannel);
  84. if (idx > -1)
  85. _dataChannels = _dataChannels.splice(idx, 1);
  86. };
  87. _dataChannels.push(dataChannel);
  88. }
  89. /**
  90. * Binds "ondatachannel" event listener to given PeerConnection instance.
  91. * @param peerConnection WebRTC peer connection instance.
  92. */
  93. function bindDataChannelListener(peerConnection)
  94. {
  95. peerConnection.ondatachannel = onDataChannel;
  96. // Sample code for opening new data channel from Jitsi Meet to the bridge.
  97. // Although it's not a requirement to open separate channels from both bridge
  98. // and peer as single channel can be used for sending and receiving data.
  99. // So either channel opened by the bridge or the one opened here is enough
  100. // for communication with the bridge.
  101. /*var dataChannelOptions =
  102. {
  103. reliable: true
  104. };
  105. var dataChannel
  106. = peerConnection.createDataChannel("myChannel", dataChannelOptions);
  107. // Can be used only when is in open state
  108. dataChannel.onopen = function ()
  109. {
  110. dataChannel.send("My channel !!!");
  111. };
  112. dataChannel.onmessage = function (event)
  113. {
  114. var msgData = event.data;
  115. console.info("Got My Data Channel Message:", msgData, dataChannel);
  116. };*/
  117. }