//---------------------------------------------------------------------------------------------------- // parse message and queue for dispatch on the game thread void OnMessage(WebSocket ws, byte[] data, bool isText) { try { if (isText == false) { throw new Exception("Unable to process binary messages"); } var json = Encoding.UTF8.GetString(data); var message = json.FromJson <Message>(); if (message == null || message.q == null) { throw new Exception("Failed to parse message"); } UniumComponent.Log(string.Format("[sock:{0}] {1}", mSocket.ID, json)); lock ( mMessageQueue ) { mMessageQueue.Add(message); } } catch (Exception e) { mSocketMessage.Error(ResponseCode.BadRequest); UniumComponent.Warn(string.Format("[sock:{0}] {1}", mSocket.ID, e.Message)); } }
static IEnumerator TakeScreenshot(RequestAdapter req, string path) { // save screenshot var filename = Path.Combine(HandlerFile.GetPath("persistent"), "screenshot.png"); #if UNITY_5 Application.CaptureScreenshot(filename); #else ScreenCapture.CaptureScreenshot(filename); #endif UniumComponent.Log("Screenshot '" + filename + "'"); // screenshots don't happen immediately, so defer a redirect for a small amount of time yield return(new WaitForSeconds(1.0f)); req.Redirect("/file/persistent/screenshot.png?cb=" + Util.RandomString()); }