play-co / facebook

Game Closure DevKit Plugin: Facebook
10 stars 13 forks source link

init > "status" parameter appears to be ignored #20

Open oodavid opened 9 years ago

oodavid commented 9 years ago

Self explanatory code:

var dealWithStatusAndAuth = function(){
    console.log('I should be triggered on account of the status parameter, but am not');
}
FB.Event.subscribe('auth.statusChange',        dealWithStatusAndAuth);
FB.Event.subscribe('auth.authResponseChanged', dealWithStatusAndAuth);
FB.init({
    appId:       CONFIG.modules.facebook.facebookAppID,
    displayName: CONFIG.modules.facebook.facebookDisplayName,
    version:     'v2.2',
    status:     true
});

Workaround: Manually call getLoginStatus after initialising

var dealWithStatusAndAuth = function(){
    console.log('I should be triggered on account of the getLoginStatus call');
}
FB.Event.subscribe('auth.statusChange',        dealWithStatusAndAuth);
FB.Event.subscribe('auth.authResponseChanged', dealWithStatusAndAuth);
FB.init({
    appId:       CONFIG.modules.facebook.facebookAppID,
    displayName: CONFIG.modules.facebook.facebookDisplayName,
    version:     'v2.2'
});
FB.getLoginStatus(function(response){
    dealWithStatusAndAuth(response); // Might be caught by the event handlers, but to be sure
}, true); // Force a round-trip
jwilm commented 9 years ago

Are you sure the auth.statusChange event doesn't fire? I am using that internally without issue. The 2nd argument to getLoginStatus isn't supported currently. I somehow missed that part of the interface.

Side note: those bind calls are not necessary. This code looks suspicious:

FB.getLoginStatus(bind(this, function(response){
    this.dealWithStatusAndAuth(response); // Might be caught by the event handlers, but to be sure
}), true); // Force a round-trip

You never assign anything to this.dealWithStatusAndAuth before you call it.

oodavid commented 9 years ago

I'll run a test shortly :)

oodavid commented 9 years ago

Right, just ran another test on iOS/XCode - I can confirm dealWithStatusAndAuth doesn't log anything to the console. Unless there's a circumstance where the code is run before the logger can catch it?

_PS_ - I've updated my initial post without the strange bind() scoping, it was piecemeal code that I lifted out of a context where it made sense!

jwilm commented 9 years ago

Are you on the 2.0 release tag? It looks like those events should be firing regardless of whether you pass the status flag.

- (void) onSessionStateChanged:(FBSession *)session state:(FBSessionState) state error:(NSError *)error {
  NSLOG(@"{facebook} onSessionStateChanged");

  switch (state) {
    case FBSessionStateOpen:
    case FBSessionStateOpenTokenExtended:
      if (!error) {
        NSDictionary * res = [self authResponse];
        [[PluginManager get]
          dispatchEvent:@"auth.authResponseChanged"
          forPlugin:self
          withData:res];

        [[PluginManager get]
          dispatchEvent:@"auth.statusChange"
          forPlugin:self
          withData:res];
  // ...