Facebook
From Corrupt Pudu, 3 Years ago, written in JavaScript.
Embed
Download Paste or View Raw
Hits: 50
  1. class LocalDataTrack {
  2.   constructor() {
  3.     this.dataChannelMessages = []
  4.     this.builded = false
  5.   }
  6.  
  7.   build(janusRoom) {
  8.     this.janusRoom = janusRoom
  9.   }
  10.  
  11.   send(data) {
  12.     if (!this.janusRoom) {
  13.       this.dataChannelMessages.push(data)
  14.     }
  15.     else {
  16.       if (!this.builded) {
  17.         this.janusRoom._dataChannelMessages.push(...this.dataChannelMessages)
  18.         this.dataChannelMessages = []
  19.         this.builded = true
  20.       }
  21.       this.janusRoom._sendData(data)
  22.     }
  23.   }
  24. }
  25.  
  26. class JanusRoom {
  27.   constructor(newRoom) {
  28.     if (typeof newRoom === 'undefined') {
  29.       throw new Error('need to use build(token, connectOptions)')
  30.     }
  31.     this.janusRoom = newRoom
  32.     JanusRoom.LocalVideoTrack.build(newRoom)
  33.   }
  34. }
  35.  
  36. room = JanusRoom()
  37. localDataTracks.forEach(localDataTrack => localDataTracks.build(room))
  38.