Skip to content

Commit 1c74415

Browse files
committed
torii client create
1 parent a33e843 commit 1c74415

File tree

6 files changed

+13
-19
lines changed

6 files changed

+13
-19
lines changed

Assets/Dojo/Plugins/WebGL/torii_c.jslib

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
mergeInto(LibraryManager.library, {
22
// Creates a new client and returns the pointer to it
33
CreateClient: async function (
4-
rpcUrl,
54
toriiUrl,
65
relayUrl,
76
worldAddress,
8-
// callbackObjectName,
9-
// callbackMethodName
107
cb
118
) {
129
let client = await wasm_bindgen.createClient({
13-
rpcUrl: UTF8ToString(rpcUrl),
1410
toriiUrl: UTF8ToString(toriiUrl),
1511
relayUrl: UTF8ToString(relayUrl),
1612
worldAddress: UTF8ToString(worldAddress),

Assets/Dojo/Runtime/Config/WorldManagerData.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ public class WorldManagerData : ScriptableObject
1111
{
1212
[Header("RPC")]
1313
public string toriiUrl = "http://localhost:8080";
14-
public string rpcUrl = "http://localhost:5050";
1514
public string relayUrl = "/ip4/127.0.0.1/tcp/9090";
1615
public string relayWebrtcUrl;
1716
[Header("World")]

Assets/Dojo/Runtime/Torii/ToriiClient.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@ public unsafe class ToriiClient
1616
private dojo.Subscription* entitySubscription;
1717
private dojo.Subscription* eventMessagesSubscription;
1818

19-
public ToriiClient(string toriiUrl, string rpcUrl, string relayUrl, FieldElement worldAddress, bool dispatchEventsToMainThread = true)
19+
public ToriiClient(string toriiUrl, string relayUrl, FieldElement worldAddress, bool dispatchEventsToMainThread = true)
2020
{
2121
CString ctoriiUrl = CString.FromString(toriiUrl);
22-
CString crpcUrl = CString.FromString(rpcUrl);
2322
CString crelayUrl = CString.FromString(relayUrl);
2423

25-
var result = dojo.client_new(ctoriiUrl, crpcUrl, crelayUrl, worldAddress.Inner);
24+
var result = dojo.client_new(ctoriiUrl, crelayUrl, worldAddress.Inner);
2625
if (result.tag == dojo.ResultToriiClient_Tag.ErrToriiClient)
2726
{
2827
throw new Exception(result.err.message);
@@ -48,9 +47,13 @@ public ToriiClient(string toriiUrl, string rpcUrl, string relayUrl, FieldElement
4847
public dojo.WorldMetadata WorldMetadata()
4948
{
5049
// TODO: implement a managed type for WorldMetadata too
51-
dojo.WorldMetadata worldMetadata = dojo.client_metadata(client);
50+
dojo.ResultWorldMetadata result = dojo.client_metadata(client);
51+
if (result.tag == dojo.ResultWorldMetadata_Tag.ErrWorldMetadata)
52+
{
53+
throw new Exception(result.err.message);
54+
}
5255

53-
return worldMetadata;
56+
return result.ok;
5457
}
5558

5659
// NOT USED? potentially deprecated

Assets/Dojo/Runtime/Torii/ToriiWasmClient.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,16 @@ namespace Dojo.Torii
1414
public class ToriiWasmClient
1515
{
1616
private string toriiUrl;
17-
private string rpcUrl;
1817
private string relayUrl;
1918
private FieldElement world;
2019
public IntPtr clientPtr;
2120

2221
IntPtr entitySubscription;
2322
IntPtr eventMessageSubscription;
2423

25-
public ToriiWasmClient(string toriiUrl, string rpcUrl, string relayUrl, FieldElement world)
24+
public ToriiWasmClient(string toriiUrl, string relayUrl, FieldElement world)
2625
{
2726
this.toriiUrl = toriiUrl;
28-
this.rpcUrl = rpcUrl;
2927
this.relayUrl = relayUrl;
3028
this.world = world;
3129
}
@@ -44,7 +42,7 @@ public static void Callback(IntPtr clientPtr)
4442
public async Task CreateClient()
4543
{
4644
CreateClientHelper.Tcs = new TaskCompletionSource<IntPtr>();
47-
ToriiWasmInterop.CreateClient(new CString(rpcUrl), new CString(toriiUrl), new CString(relayUrl), new CString(world.Hex()), CreateClientHelper.Callback);
45+
ToriiWasmInterop.CreateClient(new CString(toriiUrl), new CString(relayUrl), new CString(world.Hex()), CreateClientHelper.Callback);
4846
clientPtr = await CreateClientHelper.Tcs.Task;
4947

5048
entitySubscription = await RegisterEntityStateUpdateEvent(new KeysClause[] { });

Assets/Dojo/Runtime/Torii/ToriiWasmInterop.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class ToriiWasmInterop : MonoBehaviour
3434
{
3535
// Creates a new client and returns the pointer to it
3636
[DllImport("__Internal")]
37-
public static extern void CreateClient(CString rpcUrl, CString toriiUrl, CString relayUrl, CString worldAddress, Action<IntPtr> cb);
37+
public static extern void CreateClient(CString toriiUrl, CString relayUrl, CString worldAddress, Action<IntPtr> cb);
3838

3939
// Returns a dictionary of all of the entities
4040
[DllImport("__Internal")]

Assets/Dojo/Runtime/WorldManager.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ public class WorldManager : MonoBehaviour
1818
async void Awake()
1919
{
2020
#if UNITY_WEBGL && !UNITY_EDITOR
21-
wasmClient = new ToriiWasmClient(dojoConfig.toriiUrl, dojoConfig.rpcUrl,
22-
dojoConfig.relayWebrtcUrl, dojoConfig.worldAddress);
21+
wasmClient = new ToriiWasmClient(dojoConfig.toriiUrl, dojoConfig.relayWebrtcUrl, dojoConfig.worldAddress);
2322
await wasmClient.CreateClient();
2423
#else
25-
toriiClient = new ToriiClient(dojoConfig.toriiUrl, dojoConfig.rpcUrl,
26-
dojoConfig.relayUrl, dojoConfig.worldAddress);
24+
toriiClient = new ToriiClient(dojoConfig.toriiUrl, dojoConfig.relayUrl, dojoConfig.worldAddress);
2725
#endif
2826

2927
/* fetch entities from the world

0 commit comments

Comments
 (0)