MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / Connect

Method Connect

sdks/csharp/src/SpacetimeDBClient.cs:608–658  ·  view source on GitHub ↗

Connect to a remote spacetime instance. URI of the SpacetimeDB server (ex: https://maincloud.spacetimedb.com) The name or address of the database to connect to The compression settings to use Whether or not to request light updates

(string? token, string uri, string addressOrName, Compression compression, bool light, bool? confirmedReads)

Source from the content-addressed store, hash-verified

606 /// If not set, the server chooses the default.
607 /// </param>
608 void IDbConnection.Connect(string? token, string uri, string addressOrName, Compression compression, bool light, bool? confirmedReads)
609 {
610 isClosing = false;
611 connectionClosed = false;
612 Identity = null;
613 initialConnectionId = null;
614 onConnectInvoked = false;
615 while (_parseQueue.TryTake(out _)) { }
616 while (_applyQueue.TryTake(out _)) { }
617
618 uri = uri.Replace("http://", "ws://");
619 uri = uri.Replace("https://", "wss://");
620 if (!uri.StartsWith("ws://") && !uri.StartsWith("wss://"))
621 {
622 uri = $"ws://{uri}";
623 }
624 // Things fail surprisingly if we have a trailing slash, because we later manually append strings
625 // like `/foo` and then end up with `//` in the URI.
626 uri = uri.TrimEnd('/');
627
628 Log.Info($"SpacetimeDBClient: Connecting to {uri} {addressOrName}");
629 if (!IsTesting)
630 {
631#if UNITY_WEBGL && !UNITY_EDITOR
632 async Task Function()
633#else
634 Task.Run(async () =>
635#endif
636 {
637 try
638 {
639 await webSocket.Connect(token, uri, addressOrName, ConnectionId, compression, light, confirmedReads);
640 }
641 catch (Exception e)
642 {
643 if (connectionClosed)
644 {
645 Log.Info("Connection closed gracefully.");
646 return;
647 }
648
649 Log.Exception(e);
650 }
651#if UNITY_WEBGL && !UNITY_EDITOR
652 }
653 _ = Function();
654#else
655 });
656#endif
657 }
658 }
659
660
661 private void ApplyUpdate(IEventContext eventContext, ParsedDatabaseUpdate dbOps)

Callers

nothing calls this directly

Calls 4

FunctionFunction · 0.85
InfoMethod · 0.45
ConnectMethod · 0.45
ExceptionMethod · 0.45

Tested by

no test coverage detected