0

I am trying to include Dailymotion in my web app. I have one javascript file (for Dailymotion) and an inline javascript.I am trying to get the recomemmended videos from DM, for which I have a function ready.

Dailymotion.js looks something like this

login();
function login(){
  getScreenname();
}
function getScreename(){
  // print some name
}
function getRecoVideos(callback){
  callback(result);
}

Inline.js

getRecoVideos(function(result){
  console.log(result);
});

In the inline.js file, the call to getRecoVideos doesn't work because, the login is not finished. How can I synchronize the calls?

4
  • 1
    How is the login finish signaled? Commented Mar 5, 2014 at 3:59
  • add a call back function to login and pass the getRecoVideos as a finish function m8 Commented Mar 5, 2014 at 4:01
  • Can you please show an example? Commented Mar 5, 2014 at 4:50
  • check out deferred promises: api.jquery.com/deferred.promise, or amplify publish/subscribe amplifyjs.com/api/pubsub Commented Mar 5, 2014 at 16:52

1 Answer 1

1

Per this documentation DM takes a response function that you can use to then call the getRecoVideos() function.

UPDATE:

To make it so you can receive the event from anywhere you could do the following:

DM.login(function() {
    $(document).trigger("dm-logged-in");
});

And then to receive the event:

$(document).on("dm-logged-in", function() {
    // Do what you want here...
});

This is using jQuery. If you don't use jQuery see this for more data on how to dispatch events in Java Script: How to trigger event in JavaScript?

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the reply. I have managed to get the recommended videos, but only if call the function from the same js file(Dailymotion.js). I want to call the function from a inline js. How can i signal if the login is complete using Javascript(not referring to the API docs)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.