pusher.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. // 2020/09/23 安卓端华为小米机型发现,安卓原生返回键,退房失败。
  23. // 会触发detached生命周期,调用到该方法,puhserContext.stop()调用不成功,但是清空url后,客户端调用的退房方法就会不生效
  24. // 这里做出改动,只有stop调用成功后,才会清空url,保持组件卸载流程的完整性,调用不成功的情况将由微信客户端兜底清除
  25. this.pusherContext.stop({
  26. success: () => {
  27. console.log('Pusher pusherContext.stop()')
  28. Object.assign(this, DEFAULT_PUSHER_CONFIG, {
  29. isVisible: true,
  30. })
  31. },
  32. })
  33. this.pusherContext = null
  34. }
  35. }
  36. }
  37. export default Pusher