pusher.js 906 B

123456789101112131415161718192021222324252627282930313233
  1. import { DEFAULT_PUSHER_CONFIG } from '../common/constants.js'
  2. class Pusher {
  3. constructor(options) {
  4. Object.assign(this, DEFAULT_PUSHER_CONFIG, {
  5. isVisible: true, // 手Q初始化时不能隐藏 puser和player 否则黑屏
  6. }, options)
  7. }
  8. /**
  9. * 通过wx.createLivePusherContext 获取<live-pusher> context
  10. * @param {Object} context 组件上下文
  11. * @returns {Object} livepusher context
  12. */
  13. getPusherContext(context) {
  14. if (!this.pusherContext) {
  15. this.pusherContext = wx.createLivePusherContext(context)
  16. }
  17. return this.pusherContext
  18. }
  19. reset() {
  20. console.log('Pusher reset', this.pusherContext)
  21. if (this.pusherContext) {
  22. console.log('Pusher pusherContext.stop()')
  23. this.pusherContext.stop()
  24. this.pusherContext = null
  25. }
  26. Object.assign(this, DEFAULT_PUSHER_CONFIG, {
  27. isVisible: true,
  28. })
  29. }
  30. }
  31. export default Pusher