static async Task Main(string[] args) { Console.Error.WriteLine("This thread is {0}", Thread.CurrentThread.ManagedThreadId); using (var transport = new WebChannelWebSocketTransport()) { await transport.Connect(new Uri("ws://localhost:12345")); var channel = new QWebChannel.QWebChannel(transport); // Run the processing task in the background transport.ProcessMessages(); await channel.IsConnected; Console.WriteLine("Connected."); dynamic chatserver = channel.Objects["chatserver"]; string username = null; Func <Task <bool> > tryLogin = async() => { Console.Write("Enter your name: "); username = Console.ReadLine().Trim(); return(await chatserver.login(username)); }; while (!await tryLogin()) { Console.Error.WriteLine("Username already taken. Please enter a new one."); } Console.WriteLine("Successfully logged in as {0}!", username); ((Signal)chatserver.keepAlive).Connect(() => chatserver.keepAliveResponse(username)); ((Signal)chatserver.newMessage).Connect(delegate(string time, string user, string message) { Console.WriteLine("[{0}] {1}: {2}", time, user, message); }); ((Signal)chatserver.userListChanged).OnEmission += (sender, args) => { Console.WriteLine("User list: {0}", string.Join(", ", chatserver.userList)); }; while (true) { var msg = await Console.In.ReadLineAsync(); await chatserver.sendMessage(username, msg); } } }
public QObject(string name, JObject data, QWebChannel channel) { this.__id__ = name; this.webChannel = channel; lock (webChannel.lockObject) { webChannel.objects[name] = this; } if (data["methods"] != null) { foreach (var method in data["methods"]) { addMethod(method); } } if (data["properties"] != null) { foreach (var property in data["properties"]) { bindGetterSetter(property); } } if (data["signals"] != null) { foreach (var signal in data["signals"]) { addSignal(signal, false); } } if (data["enums"] != null) { foreach (var enumPair in (JObject)data["enums"]) { enums[enumPair.Key] = new EnumWrapper(enumPair.Key, (JObject)enumPair.Value); } } Enums = new ReadOnlyDictionary <string, EnumWrapper>(enums); }