void Start() { renderTexture = new RenderTexture(width, height, 24); rendCamera = this.GetComponent <Camera>(); texture = new Texture2D(width, height, TextureFormat.ARGB32, false); rect = new Rect(0, 0, width, height); // Get script WebSocketVideo from GameObject WebSocketVideo websocket = WebsocketPlayer.GetComponent <WebsocketPlayer>(); // Create name for socket service if null if (string.IsNullOrWhiteSpace(serviceName)) { serviceName = name; } serviceName = serviceName.Replace(" ", "_"); websocket.CreateSocketService(serviceName); Thread thread = new Thread(() => frameLoop(width, height)); thread.IsBackground = true; thread.SetApartmentState(System.Threading.ApartmentState.STA); thread.Start(); }
// Register HTTP GET/POST web routes here void Start() { // Create object of WebsocketPlayer instance websocket = GetComponent <WebsocketPlayer>(); // Hello world lambda syntax example Router.WebRoutes.Add(new WebRoute( "GET", "/hello_world", (HttpListenerRequest request, HttpListenerResponse response) => { response.ContentType = "text/html"; response.ContentEncoding = Encoding.UTF8; response.WriteContent(Encoding.UTF8.GetBytes("Hello World")); } )); Router.WebRoutes.Add(new WebRoute( "GET", "/api/websocketlist", WebsocketList )); Router.WebRoutes.Add(new WebRoute( "GET", "/api/touchevent", WebsocketList )); }