globalCall.js 974 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { MEDIA_TYPE } from '../../utils/constants';
  2. Page({
  3. TUICallKit: null,
  4. data: {
  5. config: {
  6. },
  7. },
  8. async onLoad(option) {
  9. const config = JSON.parse(option.configData);
  10. this.setData(
  11. {
  12. config: { ...this.data.config, ...config },
  13. },
  14. async () => {
  15. this.TUICallKit = this.selectComponent('#TUICallKit-component');
  16. try {
  17. await this.TUICallKit.init(config);
  18. const event = JSON.parse(option.data);
  19. wx.$TUICallEngine.setPusherAttributesHandler({
  20. enableCamera: event.data.inviteData.callType === MEDIA_TYPE.VIDEO,
  21. });
  22. wx.$TUICallEngine.TRTCCallingDelegate.onInvited(event.data);
  23. wx.createLivePusherContext().startPreview();
  24. } catch (error) {
  25. console.error(error);
  26. }
  27. },
  28. );
  29. },
  30. /**
  31. * 生命周期函数--监听页面卸载
  32. */
  33. onUnload() {
  34. this.TUICallKit.destroyed();
  35. },
  36. onShow() {},
  37. });