/// <summary> /// All clients need to be initialized which creates an instance of an internal speckle client object, /// authenticates against the server and provides a manager object to receive inspector arguments from. /// </summary> /// <param name="manager">The manager instance that provides inspector values for this client.</param> /// <param name="url">The url of the speckle server to connect to.</param> /// <param name="apiToken">The authentication token of the user to connect as.</param> /// <returns>An async <c>Task</c> of the new operation.</returns> public override async Task InitializeClient(SpeckleUnityManager manager, string url, string apiToken) { if (streamRoot == null) { streamRoot = new GameObject().transform; streamRoot.name = "Default Stream Root: " + streamID; } this.manager = manager; client = new SpeckleApiClient(url.Trim(), true); client.BaseUrl = url.Trim(); RegisterClient(); await client.IntializeReceiver(streamID, Application.productName, "Unity", Guid.NewGuid().ToString(), apiToken); Debug.Log("Initialized stream: " + streamID); deserializedStreamObjects = new List <object> (); layerLookup = new Dictionary <Layer, Transform> (); speckleObjectLookup = new Dictionary <GameObject, SpeckleObject> (); numbers = new List <float> (); strings = new List <string> (); meshes = new List <Mesh> (); meshRenderers = new List <MeshRenderer> (); //after connected, call update global to get geometry await UpdateGlobal(); }
protected override void SolveInstance(IGH_DataAccess DA) { if (Paused) { SetObjects(DA); return; } string inputId = null; DA.GetData(0, ref inputId); if (inputId == null && StreamId == null) { return; } if (inputId != StreamId) { Debug.WriteLine("Changing streams: {0} ::> {1}", inputId, StreamId); StreamId = inputId; if (myReceiver != null) { myReceiver.Dispose(true); } myReceiver = new SpeckleApiClient(RestApi, true); InitReceiverEventsAndGlobals(); myReceiver.IntializeReceiver(StreamId, Document.DisplayName, "Grasshopper", Document.DocumentID.ToString(), AuthToken); return; } if (myReceiver == null) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "Receiver not intialised."); return; } if (!myReceiver.IsConnected) { return; } if (Expired) { Expired = false; UpdateGlobal(); return; } CalculateBoundingBox(); ExpirePreview(true); SetObjects(DA); }
private void ChangeStreamId(object sender, System.Timers.ElapsedEventArgs e) { Debug.WriteLine("Changing streams to {0}.", StreamId); Client = new SpeckleApiClient(RestApi, true); InitReceiverEventsAndGlobals(); Client.IntializeReceiver(StreamId, Document.DisplayName, "Grasshopper", Document.DocumentID.ToString(), AuthToken); }
public void Init(string inStreamID) { Client = new SpeckleApiClient(restURL); //Assign events Client.OnReady += Client_OnReady; Client.OnLogData += Client_OnLogData; Client.OnWsMessage += Client_OnWsMessage; Client.OnError += Client_OnError; //make sure convereter is loaded var hack = new ConverterHack(); SpeckleObjects = new List <SpeckleObject>(); StreamID = inStreamID; Client.IntializeReceiver(StreamID, "UnityTest", "Unity", "UnityGuid", authToken); UpdateGlobal(); }
public RhinoReceiver(string _payload, Interop _parent) { Context = _parent; dynamic payload = JsonConvert.DeserializeObject(_payload); StreamId = ( string )payload.streamId; Client = new SpeckleApiClient(( string )payload.account.restApi, true); Client.OnReady += Client_OnReady; Client.OnLogData += Client_OnLogData; Client.OnWsMessage += Client_OnWsMessage; Client.OnError += Client_OnError; Client.IntializeReceiver(( string )payload.streamId, Context.GetDocumentName(), "Rhino", Context.GetDocumentGuid(), ( string )payload.account.token); Display = new SpeckleDisplayConduit(); Display.Enabled = true; Objects = new List <SpeckleObject>(); }
public RevitReceiver(string payload, Interop parent) { Context = parent; dynamic p = JsonConvert.DeserializeObject(payload); StreamId = (string)p.streamId; Client = new SpeckleApiClient((string)p.account.restApi, true); Client.OnReady += Client_OnReady; Client.OnLogData += Client_OnLogData; Client.OnWsMessage += Client_OnWsMessage; Client.OnError += Client_OnError; Client.IntializeReceiver((string)p.streamId, Context.GetDocumentName(), "Revit", Context.GetDocumentGuid(), (string)p.account.apiToken); Objects = new List <SpeckleObject>(); }
//Initialize receiver IEnumerator InitAsync(string inStreamID, string URL) { Client = new SpeckleApiClient(URL); //Assign events Client.OnReady += Client_OnReady; Client.OnLogData += Client_OnLogData; Client.OnWsMessage += Client_OnWsMessage; Client.OnError += Client_OnError; //make sure convereter is loaded var hack = new ConverterHack(); SpeckleObjects = new List <SpeckleObject>(); StreamID = inStreamID; Client.IntializeReceiver(StreamID, "UnityTest", "Unity", "UnityGuid", authToken); var streamGetResponse = Client.StreamGetAsync(StreamID, null); while (!streamGetResponse.IsCompleted) { yield return(null); } Client.Stream = streamGetResponse.Result.Resource; if (rootGameObject == null) { rootGameObject = new GameObject(Client.Stream.Name); } //call event on SpeckleManager to allow users to do their own thing when a stream is created transform.GetComponent <UnitySpeckle>().OnReceiverCreated.Invoke(this); UpdateGlobal(); }