選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

data_channels.js 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* global connection, Strophe, updateLargeVideo, focusedVideoSrc*/
  2. /**
  3. * Callback triggered by PeerConnection when new data channel is opened
  4. * on the bridge.
  5. * @param event the event info object.
  6. */
  7. function onDataChannel(event)
  8. {
  9. var dataChannel = event.channel;
  10. dataChannel.onopen = function ()
  11. {
  12. console.info("Data channel opened by the bridge !!!", dataChannel);
  13. // Code sample for sending string and/or binary data
  14. // Sends String message to the bridge
  15. //dataChannel.send("Hello bridge!");
  16. // Sends 12 bytes binary message to the bridge
  17. //dataChannel.send(new ArrayBuffer(12));
  18. };
  19. dataChannel.onerror = function (error)
  20. {
  21. console.error("Data Channel Error:", error, dataChannel);
  22. };
  23. dataChannel.onmessage = function (event)
  24. {
  25. var msgData = event.data;
  26. console.info("Got Data Channel Message:", msgData, dataChannel);
  27. // Active speaker event
  28. if (msgData.indexOf('activeSpeaker') === 0)
  29. {
  30. // Endpoint ID from the bridge
  31. var resourceJid = msgData.split(":")[1];
  32. console.info(
  33. "Data channel new active speaker event: " + resourceJid);
  34. $(document).trigger('activespeakerchanged', [resourceJid]);
  35. }
  36. };
  37. dataChannel.onclose = function ()
  38. {
  39. console.info("The Data Channel closed", dataChannel);
  40. };
  41. }
  42. /**
  43. * Binds "ondatachannel" event listener to given PeerConnection instance.
  44. * @param peerConnection WebRTC peer connection instance.
  45. */
  46. function bindDataChannelListener(peerConnection)
  47. {
  48. peerConnection.ondatachannel = onDataChannel;
  49. // Sample code for opening new data channel from Jitsi Meet to the bridge.
  50. // Although it's not a requirement to open separate channels from both bridge
  51. // and peer as single channel can be used for sending and receiving data.
  52. // So either channel opened by the bridge or the one opened here is enough
  53. // for communication with the bridge.
  54. /*var dataChannelOptions =
  55. {
  56. reliable: true
  57. };
  58. var dataChannel
  59. = peerConnection.createDataChannel("myChannel", dataChannelOptions);
  60. // Can be used only when is in open state
  61. dataChannel.onopen = function ()
  62. {
  63. dataChannel.send("My channel !!!");
  64. };
  65. dataChannel.onmessage = function (event)
  66. {
  67. var msgData = event.data;
  68. console.info("Got My Data Channel Message:", msgData, dataChannel);
  69. };*/
  70. }