Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ sysinfo.txt

# Crashlytics generated file
crashlytics-build.properties

**/.DS_Store
64 changes: 41 additions & 23 deletions Assets/FirebaseWebGL/Plugins/firebaseauth.jslib
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
mergeInto(LibraryManager.library, {

SignInAnonymously: function (objectName, callback, fallback) {
SignInAnonymously: function (objectName, id, callback, fallback) {
var parsedObjectName = UTF8ToString(objectName);
var parsedCallback = UTF8ToString(callback);
var parsedFallback = UTF8ToString(fallback);

try {
firebase.auth().signInAnonymously().then(function (result) {
unityInstance.Module.SendMessage(parsedObjectName, parsedCallback, "Success: signed up for " + result);
unityInstance.Module.SendMessage(parsedObjectName, parsedCallback, JSON.stringify({id: id, result: "Success: signed up for " + result}));
}).catch(function (error) {
unityInstance.Module.SendMessage(parsedObjectName, parsedFallback, JSON.stringify(error, Object.getOwnPropertyNames(error)));
var errorStringfy = JSON.stringify(error, Object.getOwnPropertyNames(error))
unityInstance.Module.SendMessage(parsedObjectName, parsedFallback, JSON.stringify({ id: id, result: JSON.parse(errorStringfy) }));
});

} catch (error) {
unityInstance.Module.SendMessage(parsedObjectName, parsedFallback, JSON.stringify(error, Object.getOwnPropertyNames(error)));
var errorStringfy = JSON.stringify(error, Object.getOwnPropertyNames(error))
unityInstance.Module.SendMessage(parsedObjectName, parsedFallback, JSON.stringify({ id: id, result: JSON.parse(errorStringfy) }));
}
},

CreateUserWithEmailAndPassword: function (email, password, objectName, callback, fallback) {
CreateUserWithEmailAndPassword: function (email, password, objectName, id, callback, fallback) {
var parsedEmail = UTF8ToString(email);
var parsedPassword = UTF8ToString(password);
var parsedObjectName = UTF8ToString(objectName);
Expand All @@ -27,17 +29,21 @@ mergeInto(LibraryManager.library, {
try {

firebase.auth().createUserWithEmailAndPassword(parsedEmail, parsedPassword).then(function (unused) {
unityInstance.Module.SendMessage(parsedObjectName, parsedCallback, "Success: signed up for " + parsedEmail);

unityInstance.Module.SendMessage(parsedObjectName, parsedCallback, JSON.stringify({id: id, result: "Success: signed up for " + parsedEmail}));
}).catch(function (error) {
unityInstance.Module.SendMessage(parsedObjectName, parsedFallback, JSON.stringify(error, Object.getOwnPropertyNames(error)));

var errorStringfy = JSON.stringify(error, Object.getOwnPropertyNames(error))
unityInstance.Module.SendMessage(parsedObjectName, parsedFallback, JSON.stringify({ id: id, result: JSON.parse(errorStringfy) }));
});

} catch (error) {
unityInstance.Module.SendMessage(parsedObjectName, parsedFallback, JSON.stringify(error, Object.getOwnPropertyNames(error)));
var errorStringfy = JSON.stringify(error, Object.getOwnPropertyNames(error))
unityInstance.Module.SendMessage(parsedObjectName, parsedFallback, JSON.stringify({ id: id, result: JSON.parse(errorStringfy) }));
}
},

SignInWithEmailAndPassword: function (email, password, objectName, callback, fallback) {
SignInWithEmailAndPassword: function (email, password, objectName, id, callback, fallback) {
var parsedEmail = UTF8ToString(email);
var parsedPassword = UTF8ToString(password);
var parsedObjectName = UTF8ToString(objectName);
Expand All @@ -47,62 +53,74 @@ mergeInto(LibraryManager.library, {
try {

firebase.auth().signInWithEmailAndPassword(parsedEmail, parsedPassword).then(function (unused) {
unityInstance.Module.SendMessage(parsedObjectName, parsedCallback, "Success: signed in for " + parsedEmail);
unityInstance.Module.SendMessage(parsedObjectName, parsedCallback, JSON.stringify({id: id, result: "Success: signed in for " + parsedEmail}));
}).catch(function (error) {
unityInstance.Module.SendMessage(parsedObjectName, parsedFallback, JSON.stringify(error, Object.getOwnPropertyNames(error)));

var errorStringfy = JSON.stringify(error, Object.getOwnPropertyNames(error))
unityInstance.Module.SendMessage(parsedObjectName, parsedFallback, JSON.stringify({ id: id, result: JSON.parse(errorStringfy) }));
});

} catch (error) {
unityInstance.Module.SendMessage(parsedObjectName, parsedFallback, JSON.stringify(error, Object.getOwnPropertyNames(error)));

var errorStringfy = JSON.stringify(error, Object.getOwnPropertyNames(error))
unityInstance.Module.SendMessage(parsedObjectName, parsedFallback, JSON.stringify({ id: id, result: JSON.parse(errorStringfy) }));
}
},

SignInWithGoogle: function (objectName, callback, fallback) {
SignInWithGoogle: function (objectName, id, callback, fallback) {
var parsedObjectName = UTF8ToString(objectName);
var parsedCallback = UTF8ToString(callback);
var parsedFallback = UTF8ToString(fallback);

try {
var provider = new firebase.auth.GoogleAuthProvider();
firebase.auth().signInWithRedirect(provider).then(function (unused) {
unityInstance.Module.SendMessage(parsedObjectName, parsedCallback, "Success: signed in with Google!");
unityInstance.Module.SendMessage(parsedObjectName, parsedCallback, JSON.stringify({id: id, result: "Success: signed in with Google!"}));
}).catch(function (error) {
unityInstance.Module.SendMessage(parsedObjectName, parsedFallback, JSON.stringify(error, Object.getOwnPropertyNames(error)));

var errorStringfy = JSON.stringify(error, Object.getOwnPropertyNames(error))
unityInstance.Module.SendMessage(parsedObjectName, parsedFallback, JSON.stringify({ id: id, result: JSON.parse(errorStringfy) }));
});

} catch (error) {
unityInstance.Module.SendMessage(parsedObjectName, parsedFallback, JSON.stringify(error, Object.getOwnPropertyNames(error)));

var errorStringfy = JSON.stringify(error, Object.getOwnPropertyNames(error))
unityInstance.Module.SendMessage(parsedObjectName, parsedFallback, JSON.stringify({ id: id, result: JSON.parse(errorStringfy) }));
}
},

SignInWithFacebook: function (objectName, callback, fallback) {
SignInWithFacebook: function (objectName, id, callback, fallback) {
var parsedObjectName = UTF8ToString(objectName);
var parsedCallback = UTF8ToString(callback);
var parsedFallback = UTF8ToString(fallback);

try {
var provider = new firebase.auth.FacebookAuthProvider();
firebase.auth().signInWithRedirect(provider).then(function (unused) {
unityInstance.Module.SendMessage(parsedObjectName, parsedCallback, "Success: signed in with Facebook!");
unityInstance.Module.SendMessage(parsedObjectName, parsedCallback, JSON.stringify({id: id, result: "Success: signed in with Facebook!"}));
}).catch(function (error) {
unityInstance.Module.SendMessage(parsedObjectName, parsedFallback, JSON.stringify(error, Object.getOwnPropertyNames(error)));

var errorStringfy = JSON.stringify(error, Object.getOwnPropertyNames(error))
unityInstance.Module.SendMessage(parsedObjectName, parsedFallback, JSON.stringify({ id: id, result: JSON.parse(errorStringfy) }));
});

} catch (error) {
unityInstance.Module.SendMessage(parsedObjectName, parsedFallback, JSON.stringify(error, Object.getOwnPropertyNames(error)));

var errorStringfy = JSON.stringify(error, Object.getOwnPropertyNames(error))
unityInstance.Module.SendMessage(parsedObjectName, parsedFallback, JSON.stringify({ id: id, result: JSON.parse(errorStringfy) }));
}
},

OnAuthStateChanged: function (objectName, onUserSignedIn, onUserSignedOut) {
OnAuthStateChanged: function (objectName, id, onUserSignedIn, onUserSignedOut) {
var parsedObjectName = UTF8ToString(objectName);
var parsedOnUserSignedIn = UTF8ToString(onUserSignedIn);
var parsedOnUserSignedOut = UTF8ToString(onUserSignedOut);

firebase.auth().onAuthStateChanged(function(user) {
if (user) {
unityInstance.Module.SendMessage(parsedObjectName, parsedOnUserSignedIn, JSON.stringify(user));
unityInstance.Module.SendMessage(parsedObjectName, parsedOnUserSignedIn, JSON.stringify({id: id, result: user}));
} else {
unityInstance.Module.SendMessage(parsedObjectName, parsedOnUserSignedOut, "User signed out");
unityInstance.Module.SendMessage(parsedObjectName, parsedOnUserSignedOut, JSON.stringify({id: id, result: "User signed out"}));
}
});

Expand Down
28 changes: 17 additions & 11 deletions Assets/FirebaseWebGL/Scripts/FirebaseBridge/FirebaseAuth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,63 +8,69 @@ public static class FirebaseAuth
/// Creates and signs in a user anonymous
/// </summary>
/// <param name="objectName"> Name of the gameobject to call the callback/fallback of </param>
/// <param name="id"> Id of event </param>
/// <param name="callback"> Name of the method to call when the operation was successful. Method must have signature: void Method(string output) </param>
/// <param name="fallback"> Name of the method to call when the operation was unsuccessful. Method must have signature: void Method(string output). Will return a serialized FirebaseError object </param>
[DllImport("__Internal")]
public static extern void SignInAnonymously(string objectName, string callback, string fallback);
public static extern void SignInAnonymously(string objectName, string id, string callback, string fallback);

/// <summary>
/// Creates a user with email and password
/// </summary>
/// <param name="email"> User email </param>
/// <param name="password"> User password </param>
/// <param name="objectName"> Name of the gameobject to call the callback/fallback of </param>
/// <param name="id"> Id of event </param>
/// <param name="callback"> Name of the method to call when the operation was successful. Method must have signature: void Method(string output) </param>
/// <param name="fallback"> Name of the method to call when the operation was unsuccessful. Method must have signature: void Method(string output). Will return a serialized FirebaseError object </param>
[DllImport("__Internal")]
public static extern void CreateUserWithEmailAndPassword(string email, string password, string objectName, string callback,
public static extern void CreateUserWithEmailAndPassword(string email, string password, string objectName, string id, string callback,
string fallback);

/// <summary>
/// Signs in a user with email and password
/// </summary>
/// <param name="email"> User email </param>
/// <param name="password"> User password </param>
/// <param name="objectName"> Name of the gameobject to call the callback/fallback of </param>
/// <param name="id"> Id of event </param>
/// <param name="callback"> Name of the method to call when the operation was successful. Method must have signature: void Method(string output) </param>
/// <param name="fallback"> Name of the method to call when the operation was unsuccessful. Method must have signature: void Method(string output). Will return a serialized FirebaseError object </param>
[DllImport("__Internal")]
public static extern void SignInWithEmailAndPassword(string email, string password, string objectName, string callback,
public static extern void SignInWithEmailAndPassword(string email, string password, string objectName, string id, string callback,
string fallback);

/// <summary>
/// Signs in a user with Google
/// </summary>
/// <param name="objectName"> Name of the gameobject to call the callback/fallback of </param>
/// <param name="id"> Id of event </param>
/// <param name="callback"> Name of the method to call when the operation was successful. Method must have signature: void Method(string output) </param>
/// <param name="fallback"> Name of the method to call when the operation was unsuccessful. Method must have signature: void Method(string output). Will return a serialized FirebaseError object </param>
[DllImport("__Internal")]
public static extern void SignInWithGoogle(string objectName, string callback,
public static extern void SignInWithGoogle(string objectName, string id, string callback,
string fallback);

/// <summary>
/// Signs in a user with Facebook
/// </summary>
/// <param name="objectName"> Name of the gameobject to call the callback/fallback of </param>
/// <param name="id"> Id of event </param>
/// <param name="callback"> Name of the method to call when the operation was successful. Method must have signature: void Method(string output) </param>
/// <param name="fallback"> Name of the method to call when the operation was unsuccessful. Method must have signature: void Method(string output). Will return a serialized FirebaseError object </param>
[DllImport("__Internal")]
public static extern void SignInWithFacebook(string objectName, string callback,
public static extern void SignInWithFacebook(string objectName, string id, string callback,
string fallback);

/// <summary>
/// Listens for changes of the auth state (sign in/sign out)
/// </summary>
/// <param name="objectName"> Name of the gameobject to call the onUserSignedIn/onUserSignedOut of </param>
/// <param name="id"> Id of event </param>
/// <param name="onUserSignedIn"> Name of the method to call when the user signs in. Method must have signature: void Method(string output). Will return a serialized FirebaseUser object </param>
/// <param name="onUserSignedOut"> Name of the method to call when the operation was unsuccessful. Method must have signature: void Method(string output) </param>
[DllImport("__Internal")]
public static extern void OnAuthStateChanged(string objectName, string onUserSignedIn,
public static extern void OnAuthStateChanged(string objectName, string id, string onUserSignedIn,
string onUserSignedOut);
}
}
35 changes: 35 additions & 0 deletions Assets/FirebaseWebGLInterface/Firestore/DocumentSnapshot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FirebaseWebglInterface.Firestore
{
public class DocumentSnapshot
{
public string Id;
public bool Exists { get; }
public Dictionary<string, object> dict;
public bool TryGetValue<T>(string path, out T value)
{
value = default(T);
return false;
}
public T GetValue<T>(string path)
{
return default(T);
}

public bool ContainsField(string path)
{
return false;
}

public Dictionary<string, object> ToDictionary()
{
return null;
}

}
}
11 changes: 11 additions & 0 deletions Assets/FirebaseWebGLInterface/Firestore/DocumentSnapshot.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions Assets/FirebaseWebGLInterface/Firestore/FirebaseCollection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FirebaseWebglInterface.Firestore
{
public class FirebaseCollection
{
private string path;
public FirebaseCollection(string path)
{
this.path = path;
}
public FirebaseCollection OrderByDescending(string orderBy)
{
return this;
}

public FirebaseCollection Limit(int limit)
{
return this;
}
public ListenerRegistration Listen(Action<QuerySnapshot> action)
{
return new ListenerRegistration();
}

public FirebaseDocument Document(string document)
{
return new FirebaseDocument(path + "/" + document);
}
}
}
11 changes: 11 additions & 0 deletions Assets/FirebaseWebGLInterface/Firestore/FirebaseCollection.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions Assets/FirebaseWebGLInterface/Firestore/FirebaseDocument.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FirebaseWebglInterface.Firestore
{
public class FirebaseDocument
{
private string path;
public FirebaseDocument(string path)
{
this.path = path;
}
public ListenerRegistration Listen(Action<DocumentSnapshot> action)
{
//new EmptyGameObject..(name - path)
//GetObjectByName().GetComponent<ObjectUpdate>()
//firebaseBridge.listen(path, docId, false, "EmptyGameObject")
return new ListenerRegistration();
}

public FirebaseCollection Collection(string collection)
{
return new FirebaseCollection(path + "/" + collection);
}
}
}

11 changes: 11 additions & 0 deletions Assets/FirebaseWebGLInterface/Firestore/FirebaseDocument.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions Assets/FirebaseWebGLInterface/Firestore/FirebaseFirestore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FirebaseWebglInterface.Firestore
{
public class FirebaseFirestore
{
public static FirebaseFirestore DefaultInstance = new FirebaseFirestore();

public FirebaseDocument Document(string path)
{
return new FirebaseDocument(path);
}

public FirebaseCollection Collection(string path)
{
return new FirebaseCollection(path);
}
}
}
Loading