Skip to content

Commit

Permalink
Added IsMultiplayer
Browse files Browse the repository at this point in the history
  • Loading branch information
JR-Morgan committed Apr 22, 2023
1 parent 2aaaf65 commit 32533dd
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,10 @@ private async Task Receive()

try
{
Commit selectedCommit = Branches[SelectedBranchIndex].commits.items[SelectedCommitIndex];
// Receive Speckle Objects
var @base = await Operations.Receive(
Branches[SelectedBranchIndex].commits.items[SelectedCommitIndex].referencedObject,
selectedCommit.referencedObject,
remoteTransport: transport,
onProgressAction: dict =>
{
Expand All @@ -179,8 +180,15 @@ private async Task Receive()
);

EditorUtility.ClearProgressBar();

Analytics.TrackEvent(SelectedAccount, Analytics.Events.Receive);

Analytics.TrackEvent(SelectedAccount, Analytics.Events.Receive, new Dictionary<string, object>()
{
{"mode", nameof(StreamManagerEditor)},
{"sourceHostApp", HostApplications.GetHostAppFromString(selectedCommit.sourceApplication).Slug},
{"sourceHostAppVersion", selectedCommit.sourceApplication ?? ""},
{"hostPlatform", Application.platform.ToString()},
{"isMultiplayer", selectedCommit.authorId != SelectedAccount.userInfo.id},
});

//Convert Speckle Objects
int childrenConverted = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
using Speckle.Core.Transports;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Sentry;
using Speckle.ConnectorUnity.Components;
using Speckle.Core.Kits;
Expand Down Expand Up @@ -93,7 +95,7 @@ public void Receive()
if (!mainBranch.commits.items.Any())
throw new Exception("This branch has no commits");
var commit = mainBranch.commits.items[0];
GetAndConvertObject(commit.referencedObject, commit.id);
GetAndConvertObject(commit.referencedObject, commit.id, commit.sourceApplication, commit.authorId);
}
catch (Exception e)
{
Expand All @@ -116,12 +118,12 @@ protected virtual void Client_OnCommitCreated(object sender, CommitInfo e)
if (e.branchName == BranchName)
{
Debug.Log("New commit created");
GetAndConvertObject(e.objectId, e.id);
GetAndConvertObject(e.objectId, e.id, e.sourceApplication, e.authorId);
}
}


private async void GetAndConvertObject(string objectId, string commitId)
private async void GetAndConvertObject(string objectId, string commitId, string sourceApplication, string authorId)
{
try
{
Expand All @@ -136,7 +138,14 @@ private async void GetAndConvertObject(string objectId, string commitId)
disposeTransports: true
);

Analytics.TrackEvent(Client.Account, Analytics.Events.Receive);
Analytics.TrackEvent(Client.Account, Analytics.Events.Receive, new Dictionary<string, object>()
{
{"mode", nameof(Receiver)},
{"sourceHostApp", HostApplications.GetHostAppFromString(sourceApplication).Slug},
{"sourceHostAppVersion", sourceApplication ?? ""},
{"hostPlatform", Application.platform.ToString()},
{"isMultiplayer", authorId != null && authorId != Client.Account.userInfo.id},
});

Dispatcher.Instance().Enqueue(() =>
{
Expand Down Expand Up @@ -186,4 +195,4 @@ private void OnDestroy()

#endregion
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Threading;
Expand Down Expand Up @@ -86,7 +87,7 @@ public IEnumerator ReceiveAndConvertRoutine(SpeckleReceiver speckleReceiver, str
client: client,
streamId: stream.id,
objectId: commit.referencedObject,
commitId: commit.id,
commit: commit,
onProgressAction: dict => OnReceiveProgressAction.Invoke(dict),
onErrorAction: (m, e) => OnErrorAction.Invoke(m, e),
onTotalChildrenCountKnown: c => OnTotalChildrenCountKnown.Invoke(c)
Expand All @@ -100,7 +101,7 @@ public IEnumerator ReceiveAndConvertRoutine(SpeckleReceiver speckleReceiver, str
/// <param name="client"></param>
/// <param name="streamId"></param>
/// <param name="objectId"></param>
/// <param name="commitId"></param>
/// <param name="commit"></param>
/// <param name="onProgressAction"></param>
/// <param name="onErrorAction"></param>
/// <param name="onTotalChildrenCountKnown"></param>
Expand All @@ -109,7 +110,7 @@ public IEnumerator ReceiveAndConvertRoutine(SpeckleReceiver speckleReceiver, str
Client client,
string streamId,
string objectId,
string? commitId,
Commit? commit,
Action<ConcurrentDictionary<string, int>>? onProgressAction = null,
Action<string, Exception>? onErrorAction = null,
Action<int>? onTotalChildrenCountKnown = null)
Expand All @@ -134,7 +135,14 @@ public IEnumerator ReceiveAndConvertRoutine(SpeckleReceiver speckleReceiver, str
disposeTransports: false
).ConfigureAwait(false);

Analytics.TrackEvent(client.Account, Analytics.Events.Receive);
Analytics.TrackEvent(client.Account, Analytics.Events.Receive, new Dictionary<string, object>()
{
{"mode", nameof(SpeckleReceiver)},
{"sourceHostApp", HostApplications.GetHostAppFromString(commit?.sourceApplication).Slug},
{"sourceHostAppVersion", commit?.sourceApplication ?? ""},
{"hostPlatform", Application.platform.ToString()},
{"isMultiplayer", commit != null && commit.authorId != client.Account.userInfo.id},
});

token.ThrowIfCancellationRequested();

Expand All @@ -144,7 +152,7 @@ public IEnumerator ReceiveAndConvertRoutine(SpeckleReceiver speckleReceiver, str
await client.CommitReceived(token, new CommitReceivedInput
{
streamId = streamId,
commitId = commitId,
commitId = commit?.id,
message = $"received commit from {Application.unityVersion}",
sourceApplication = HostApplications.Unity.GetVersion(CoreUtils.GetHostAppVersion())
}).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ public static async Task<string> SendDataAsync(CancellationToken cancellationTok
onErrorAction: onErrorAction
);

Analytics.TrackEvent(client.Account, Analytics.Events.Send);
Analytics.TrackEvent(client.Account, Analytics.Events.Send, new Dictionary<string, object>()
{
{"mode", nameof(SpeckleSender)},
{"hostPlatform", Application.platform.ToString()},
});

if (createCommit && !cancellationToken.IsCancellationRequested)
{
Expand Down

0 comments on commit 32533dd

Please sign in to comment.