static void Main(string[] args) { Console.WriteLine("Hello Smelly Sockets"); SelectedAccount = SpkConsole.Program.GetAccount(); var spkClient_A = new SpeckleApiClient(SelectedAccount.RestApi, false, "console application"); var spkClient_B = new SpeckleApiClient(SelectedAccount.RestApi, false, "console application"); spkClient_A.AuthToken = SelectedAccount.Token; spkClient_B.AuthToken = SelectedAccount.Token; //gen streamid DummyStreamId = spkClient_A.StreamCreateAsync(new SpeckleStream() { Name = "WS Test" }).Result.Resource.StreamId; Console.WriteLine($"Created dummy stream: {DummyStreamId}. Press any key to continue stuff."); // Add event handlers and setup streamId on both ws clients. The event handlers just spit out what they get. spkClient_A.StreamId = DummyStreamId; spkClient_A.SetupWebsocket(); spkClient_A.OnWsMessage += SpkClient_A_OnWsMessage; spkClient_B.StreamId = DummyStreamId; spkClient_B.SetupWebsocket(); spkClient_B.OnWsMessage += SpkClient_B_OnWsMessage; Console.WriteLine("Waiting for 200ms, ensure connection actually happened. This is an issue with core, it doesn't expose a 'onwsconnection' event :/"); Thread.Sleep(200); // Flop them in a room - this is important if you want to broadcast messages. spkClient_A.JoinRoom("stream", DummyStreamId); spkClient_B.JoinRoom("stream", DummyStreamId); // Same hack as above. Thread.Sleep(200); // Send some dummy broadcasts spkClient_A.BroadcastMessage("stream", DummyStreamId, new { customEventType = "update-mesh", data = "42" }); spkClient_A.BroadcastMessage("stream", DummyStreamId, new { customEventType = "update-mesh-other", data = "wow" }); spkClient_B.BroadcastMessage("stream", DummyStreamId, new { customEventType = "update-mesh-other", data = "wow" }); spkClient_B.SendMessage(spkClient_A.ClientId, new { what = "This is a direct, 1-1 message from B to A." }); Console.WriteLine("Press any key to continue testing the barebones approach!"); BareBonesApproach(); Console.WriteLine("Done. Press any key to continue."); spkClient_A.StreamDeleteAsync(DummyStreamId); Console.ReadLine(); }
static async Task TestStreams(SpeckleApiClient myClient) { string streamId = "lol"; string secondStreamId = "hai"; var myPoint = new SpecklePoint() { Value = new List <double>() { 1, 2, 3 } }; var mySecondPoint = new SpecklePoint() { Value = new List <double>() { 23, 33, 12 } }; var myCircle = new SpeckleCircle() { Radius = 21 }; myPoint.Properties = new Dictionary <string, object>(); myPoint.Properties.Add("Really", mySecondPoint); myCircle.Properties = new Dictionary <string, object>(); myCircle.Properties.Add("a property", "Hello!"); myCircle.Properties.Add("point", myPoint); SpeckleStream myStream = new SpeckleStream() { Name = "Hello World My Little Stream", Objects = new List <SpeckleObject>() { myCircle, myPoint } }; SpeckleStream secondStream = new SpeckleStream() { Name = "Second Little Stream", Objects = new List <SpeckleObject>() { myCircle, mySecondPoint } }; Console.WriteLine(); try { Console.WriteLine("Creating a stream."); var Response = await myClient.StreamCreateAsync(myStream); Console.WriteLine("OK: " + Response.Resource.ToJson()); streamId = Response.Resource.StreamId; } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine(); try { Console.WriteLine("Creating a second stream."); var Response = await myClient.StreamCreateAsync(secondStream); Console.WriteLine("OK: " + Response.Resource.ToJson()); secondStreamId = Response.Resource.StreamId; } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine(); try { Console.WriteLine("Diffing two streams!"); var Response = await myClient.StreamDiffAsync(streamId, secondStreamId); Console.WriteLine("OK: " + Response.Message); } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine(); try { Console.WriteLine("Getting a stream."); var Response = await myClient.StreamGetAsync(streamId, null); Console.WriteLine("OK: " + Response.Resource.ToJson()); } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine(); try { Console.WriteLine("Getting a stream's objects."); var Response = await myClient.StreamGetObjectsAsync(streamId, null); Console.WriteLine("OK: " + Response.Resources.Count); } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine(); try { Console.WriteLine("Updating a stream."); var Response = await myClient.StreamUpdateAsync(streamId, new SpeckleStream() { Name = "I hate api testing", ViewerLayers = new List <object>() { new { test = "test" } } }); Console.WriteLine("OK: " + Response.Message); } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine(); try { Console.WriteLine("Getting a stream field."); var Response = await myClient.StreamGetAsync(streamId, "fields=viewerLayers,name,owner"); Console.WriteLine("OK: " + Response.Resource.ToJson()); } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine(); try { Console.WriteLine("Getting all users's streams."); var Response = await myClient.StreamsGetAllAsync(); Console.WriteLine("OK: " + Response.Resources.Count); } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine(); try { Console.WriteLine("Cloning a stream."); var Response = await myClient.StreamCloneAsync(streamId); Console.WriteLine("OK: " + Response.Message); } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine(); try { Console.WriteLine("Deleting a stream: " + streamId); var Response = await myClient.StreamDeleteAsync(streamId); Console.WriteLine("OK: " + Response.Message); } catch (Exception e) { Console.WriteLine(e.Message); } }