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

Fix canvas bug when FB.Init doesn't not work. #86

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 19 additions & 8 deletions Facebook.Unity/Canvas/CanvasConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal static class CanvasConstants
// a raw string.
private const string JSCode = @"
window.FBUnity = {
init: function(connectFacebookUrl, locale, debug, initParams, status) {
init: function(connectFacebookUrl, locale, debug, initParams, status) {
// make element for js sdk
if(!document.getElementById('fb-root')) {
var fbroot = document.createElement('div');
Expand All @@ -38,12 +38,9 @@ internal static class CanvasConstants

// load js sdk
var js, id = 'facebook-jssdk', ref = document.getElementsByTagName('script')[0];
if (document.getElementById(id)) {return;}
js = document.createElement('script'); js.id = id; js.async = true;
js.src = connectFacebookUrl + '/' + locale + '/sdk' + (debug ? '/debug' : '') + '.js';
ref.parentNode.insertBefore(js, ref);
// once jssdk is loaded, init
window.fbAsyncInit = function () {

function on_fb_sdk_loaded()
{
initParams = JSON.parse(initParams);
initParams.hideFlashCallback = FBUnity.onHideUnity;
FB.init(initParams);
Expand All @@ -54,7 +51,21 @@ internal static class CanvasConstants
} else {
FBUnity.onInit();
}
};
}

if (document.getElementById(id)) {
//already loaded
//need add timeout for make unity some work
setTimeout(on_fb_sdk_loaded, 250);
}
else {
// once jssdk is loaded, init
window.fbAsyncInit = on_fb_sdk_loaded;
//load sdk
js = document.createElement('script'); js.id = id; js.async = true;
js.src = connectFacebookUrl + '/' + locale + '/sdk' + (debug ? '/debug' : '') + '.js';
ref.parentNode.insertBefore(js, ref);
}
},

sendMessage: function(method, param) {
Expand Down