{"size": 1304, "ext": "js", "max_stars_repo_path": "examples/index.js", "max_stars_repo_name": "JdesEva/webRTC", "max_stars_repo_stars_event_min_datetime": "2020-11-25T02:07:06.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-25T02:07:06.000Z", "max_issues_repo_path": "examples/index.js", "max_issues_repo_name": "JdesEva/webRTC", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "examples/index.js", "max_forks_repo_name": "JdesEva/webRTC", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 28.347826087, "max_line_length": 71, "alphanum_fraction": 0.6917177914}
import RTCInstance from '../packages/main'

let client = null

const channel = '330106001'
const cButton = document.getElementById('my-button')

cButton.onclick = function () {
  const cInput = document.getElementById('appId')

  const APPID = cInput.value
  client = new RTCInstance({ codec: 'h264' })

  client.login(APPID, channel)

  client.subscribeRTCEvents()
  client.publishStream()
  console.log(client)

  client.on('published-stream', (localVideoTrack, localAudioTrack) => {
    console.log('published-stream', localVideoTrack, localAudioTrack)
    localVideoTrack.play('local-player')
    localAudioTrack.play()
  })

  client.on('user-published', (romoteVideoTrack, romoteAudioTrack) => {
    console.log(2222, romoteVideoTrack, romoteAudioTrack)
    romoteVideoTrack.forEach(row => {
      console.log('user-published', row.track)
      // 订阅完成后，从 `user` 中获取远端视频轨道对象。
      // 动态插入一个 DIV 节点作为播放远端视频轨道的容器。
      const playerContainer = document.createElement('div')
      // 给这个 DIV 节点指定一个 ID，这里指定的是远端用户的 UID。
      playerContainer.id = `player-${String(row.uid)}`
      document.body.append(playerContainer)
      row.track && row.track.play(`player-${String(row.uid)}`)
    })

    romoteAudioTrack.forEach(row => {
      row.track && row.track.play()
    })
  })
}

export default client
