@@ -9,9 +9,18 @@ public class DittoPresenceViewer : ContentView, IDisposable
9
9
{
10
10
private readonly WebView _webView ;
11
11
private DittoPresenceObserver ? _observer ;
12
-
12
+ private readonly JsonSerializerOptions _presenceSerializerOptionsOptions ;
13
+
13
14
public DittoPresenceViewer ( )
14
15
{
16
+ _presenceSerializerOptionsOptions = new JsonSerializerOptions ( )
17
+ {
18
+ IncludeFields = true ,
19
+ PropertyNamingPolicy = JsonNamingPolicy . CamelCase ,
20
+ } ;
21
+ _presenceSerializerOptionsOptions . Converters . Add ( new ByteArrayToIntArrayConverter ( ) ) ;
22
+ _presenceSerializerOptionsOptions . Converters . Add ( new StringToEnumConverter < DittoConnectionType > ( ) ) ;
23
+
15
24
_webView = new WebView
16
25
{
17
26
HorizontalOptions = LayoutOptions . Fill ,
@@ -61,19 +70,10 @@ private static void OnDittoChanged(BindableObject source, object o, object n)
61
70
62
71
private static void OnDittoPresenceChange ( DittoPresenceViewer presenceViewer , DittoPresenceGraph presence )
63
72
{
64
- var options = new JsonSerializerOptions ( )
65
- {
66
- IncludeFields = true ,
67
- PropertyNamingPolicy = JsonNamingPolicy . CamelCase ,
68
- } ;
69
-
70
- options . Converters . Add ( new ByteArrayToIntArrayConverter ( ) ) ;
71
- options . Converters . Add ( new StringToEnumConverter < DittoConnectionType > ( ) ) ;
72
- var presenceGraphJSON = JsonSerializer . Serialize ( presence , options )
73
+ var presenceGraphJson = JsonSerializer . Serialize ( presence , presenceViewer . _presenceSerializerOptionsOptions )
73
74
. Replace ( "\" isDittoCloudConnected\" " , "\" isConnectedToDittoCloud\" " ) ; //INFO: hack. This property should be named isConnectedToDittoCloud to work with Presence Viewer, like in other SDKs
74
75
75
- var b64String = Convert . ToBase64String ( Encoding . UTF8 . GetBytes ( presenceGraphJSON ) ) ;
76
-
76
+ var b64String = Convert . ToBase64String ( Encoding . UTF8 . GetBytes ( presenceGraphJson ) ) ;
77
77
78
78
MainThread . BeginInvokeOnMainThread ( async ( ) =>
79
79
{
@@ -89,6 +89,5 @@ private static void OnDittoPresenceChange(DittoPresenceViewer presenceViewer, Di
89
89
90
90
var result = presenceViewer . _webView . EvaluateJavaScriptAsync ( $ "Presence.updateNetwork('{ b64String } ');") ;
91
91
} ) ;
92
-
93
92
}
94
93
}
0 commit comments