pusher.js 918 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { DEFAULT_PUSHER_CONFIG } from "../common/constants";
  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;