DnSdk.js 1.3 KB

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