Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question]: Whats wrong with the code web client's player IDs ? SOLVED #1123

Closed
Vitaee opened this issue Oct 25, 2023 · 0 comments
Closed

[Question]: Whats wrong with the code web client's player IDs ? SOLVED #1123

Vitaee opened this issue Oct 25, 2023 · 0 comments

Comments

@Vitaee
Copy link

Vitaee commented Oct 25, 2023

How can we help?

I have below code for my django web project. I serve worker js with nginx there is no any issue.
The below code block was working fine until yesterday. But now i don't know what happened its just stopped working.

Still i can see the notification prompt for the subscription but even giving all permissions from browser, no one was registered in to onesignal.

So i can't send any notification to my clients. I have growth plan on onesignal.

<script src="https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.page.js" defer></script>
  <script>
    window.OneSignalDeferred = window.OneSignalDeferred || [];
    OneSignalDeferred.push(function(OneSignal) {
      OneSignal.init({
        appId: "my-best-app-id",
      });

      OneSignal.User.PushSubscription.addEventListener("change", pushSubscriptionChangeListener);


    });

    function pushSubscriptionChangeListener(event) {
        console.log("pushSubscriptionChangeListener triggered!")
        console.log(event)
        console.log("^^^^^^^^EVENT PRINTED^^^^^^^^")
        
        if (event.current.token) {
          console.log(`The push subscription has received a token!`);
          console.log(event.current)

          const url = 'https://www.bestwebsite.com/store-onesignal-id/';
          var userToken = `{{ token }}`

          const data = { onesignal_id: event.current.id };

              fetch(url, {
                method: 'POST',
                headers: {
                  'Content-Type': 'application/json',
                  'Authorization': `token ${userToken}`
                },
                body: JSON.stringify(data),
              });
          }
       }
  </script>

please see the below screenshot:

ss

for debug purposes i simple print the event object and i got null objects. These objects are weren't null.

Why everything is null ? and Whats wrong with my code? or how can i get player ID on web is there any other way?

@Vitaee Vitaee changed the title [Question]: Whats wrong with my code ? [Question]: Whats wrong with the code web client's player IDs ? Oct 25, 2023
@Vitaee Vitaee closed this as completed Oct 26, 2023
@Vitaee Vitaee changed the title [Question]: Whats wrong with the code web client's player IDs ? [Question]: Whats wrong with the code web client's player IDs ? SOLVED Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant