stream.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // 一个stream 对应一个 player
  2. import { DEFAULT_PLAYER_CONFIG } from "../common/constants";
  3. class Stream {
  4. constructor(options) {
  5. Object.assign(this, DEFAULT_PLAYER_CONFIG, {
  6. userID: '',
  7. // 该stream 关联的userID
  8. streamType: '',
  9. // stream 类型 [main small] aux
  10. isVisible: true,
  11. // 手Q初始化时不能隐藏 puser和player 否则黑屏。iOS 微信初始化时不能隐藏,否则同层渲染失败,player会置顶
  12. hasVideo: false,
  13. hasAudio: false,
  14. playerContext: undefined // playerContext 依赖component context来获取,目前只能在渲染后获取
  15. }, options);
  16. }
  17. /**
  18. * 大小流切换
  19. */
  20. switchMainSmallStream() {
  21. if (this.streamType === 'main' || this.streamType === 'small') {// 大小流切换逻辑
  22. // 修改 streamType 和 streamURL 并调用 componentContext setData()
  23. } else {
  24. console.log('aux 不支持大小流切换');
  25. }
  26. }
  27. reset() {
  28. if (!this.playerContext) {
  29. this.playerContext.stop();
  30. this.playerContext = null;
  31. }
  32. Object.assign(this, DEFAULT_PLAYER_CONFIG, {
  33. userID: '',
  34. // 该stream 关联的userID
  35. streamType: '',
  36. // stream 类型 [main small] aux
  37. streamID: '',
  38. isVisible: true,
  39. hasVideo: false,
  40. hasAudio: false,
  41. playerContext: undefined
  42. });
  43. }
  44. }
  45. export default Stream;