DnSdk.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { SDK } from "../lib/dn-sdk-minigame/index"
  2. class DnSdk {
  3. static instance = null
  4. static overrideShareFunc = false
  5. constructor() {
  6. }
  7. static init(dnSdkOptions) {
  8. if (!dnSdkOptions) {
  9. console.warn("DnSdk.init错误,请传入腾讯广告小游戏SDK参数")
  10. return false
  11. }
  12. if (!this.instance) {
  13. this.instance = new SDK(dnSdkOptions)
  14. }
  15. if (!this.overrideShareFunc) {
  16. wx.shareAppMessage = (function () {
  17. const nativeShareAppMessage = wx.shareAppMessage
  18. return function (shareData) {
  19. console.log('override shareAppMessage exec')
  20. // 腾讯广告小游戏SDK上报
  21. DnSdk.getInstance().track('SHARE', {
  22. target: 'APP_MESSAGE'
  23. });
  24. return nativeShareAppMessage(shareData)
  25. }
  26. })()
  27. this.overrideShareFunc = true
  28. }
  29. }
  30. static getInstance() {
  31. if (!this.instance) {
  32. console.warn("请先执行wxxyssdk的init方法")
  33. return false
  34. }
  35. return this.instance;
  36. }
  37. }
  38. export default DnSdk