Skip to content

Commit 06540f3

Browse files
committed
fix unhandled error when streaming data on WebGL platform
1 parent 87a9b71 commit 06540f3

File tree

5 files changed

+24
-26
lines changed

5 files changed

+24
-26
lines changed

Assets/FirebaseREST/Database/DatabaseReference.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,16 @@ void DisposedUnityWebRequestIfNoReferences()
274274
{
275275
#if UNITY_WEBGL
276276
if (esGL != null)
277+
{
277278
esGL.Close();
279+
esGL = null;
280+
}
278281
#else
279-
if (webReq != null)
280-
webReq.Dispose();
282+
if (webReq != null)
283+
{
284+
webReq.Dispose();
285+
webReq = null;
286+
}
281287
#endif
282288
}
283289
}

Assets/FirebaseREST/Database/FirebaseDatabase.cs

+3-10
Original file line numberDiff line numberDiff line change
@@ -129,26 +129,19 @@ public static void EventSourceErrorCallback(int id, string error)
129129
Debug.Log("Unity ES Error");
130130
if (esWebGLMap.ContainsKey(id))
131131
{
132-
esWebGLMap[id].Close();
133132
if (esWebGLMap[id].EventSourceError != null)
134133
esWebGLMap[id].EventSourceError(new FirebaseEventSourceErrorArgs(error));
134+
esWebGLMap[id].Close();
135+
esWebGLMap[id] = null;
135136
esWebGLMap.Remove(id);
136137
}
137138
}
138139

139-
[MonoPInvokeCallback(typeof(_EventSourceClosedArgs))]
140-
public static void EventSourceClosedCallback(int id)
141-
{
142-
Debug.Log("Unitt ES Closed");
143-
if (esWebGLMap.ContainsKey(id))
144-
esWebGLMap.Remove(id);
145-
}
146-
147140
[DllImport("__Internal")]
148141
static extern int CreateEventSource(string urlPtr, bool withCredentials, _EventSourceOpenArgs onOpen,
149142
_EventSourceMessageArgs onMessage, _EventSourceErrorArgs onError);
150143

151144
[DllImport("__Internal")]
152-
static extern void CloseEventSource(int id, _EventSourceClosedArgs onClosed);
145+
static extern void CloseEventSource(int id);
153146
}
154147
}

Assets/FirebaseREST/Database/FirebaseEventSourceWebGL.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ public FirebaseEventSourceWebGL(string url, bool withCredentials, Action<Firebas
3030

3131
public void Close()
3232
{
33-
CloseEventSource(this.Id, EventSourceClosedCallback);
33+
CloseEventSource(_id);
34+
if (esWebGLMap.ContainsKey(_id))
35+
{
36+
esWebGLMap.Remove(_id);
37+
}
3438
}
3539
}
3640
}

Assets/Plugins/FirebaseREST/FirebaseEventSource.jslib

+4-11
Original file line numberDiff line numberDiff line change
@@ -109,20 +109,13 @@
109109
return es.Set(event);
110110
},
111111

112-
CloseEventSource: function(id,onSuccess)
112+
CloseEventSource: function(id)
113113
{
114114
console.log(id + ' ES_Close');
115-
116115
var event = es.Get(id);
117-
118-
try
119-
{
120-
event.close();
121-
es.Remove(id);
122-
Runtime.dynCall('vi', onSuccess, [id]);
123-
}
124-
catch(e) {
125-
es._callOnError(event.onError, id, e.name + ': ' + e.message);
116+
if(event){
117+
event.eventImpl.close();
118+
es.Remove(id);
126119
}
127120
}
128121
};

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
# Unity C# Firebase Realtime Database (REST API)
1+
# Unity Firebase Realtime Database REST API
22
Write, Read, Remove and Streaming data using [Firebase's database REST API](https://firebase.google.com/docs/reference/rest/database)
33

44
This is not firebase's official plugins library.
55

6-
Contributions to this project are welcome!
6+
Tested on Android and WebGL platform. should work well on other platforms too since most of the implementation is only a simple http REST request.
7+
8+
Contributions to this project are welcome!.
79

810
## Sample Usage
911

0 commit comments

Comments
 (0)