@{
	ViewData["Title"] = "Home Page";
}
<script src="~/js/jquery.min.js"></script>
<script src="~/js/jquery.js"></script>
<div class="text-center">
	<h1 class="display-4">Welcome</h1>
	<p>Learn about <a href="https://learn.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
</div>
<script src="~/lib/microsoft/signalr/dist/browser/signalr.js"></script>
<script src="~/lib/microsoft/signalr/dist/browser/signalr.min.js"></script>
<div id="events"></div>
@* <script type="text/javascript">
	$(function()
	{

		var connection = new signalR.HubConnectionBuilder().withUrl("/tongzhi").build();

		connection.on("ReceiveMessage", function (message) {
			// 处理收到的消息
			console.log(message);
		});

		connection.start().then(function () {
				console.log("11111111111");
			// 连接成功
		}).catch(function (error) {
				console.log("2222222222222");
			// 连接失败
		});

		$("#aa").click(function()
		{
			  await connection.invoke("SendMessage", "1111111111", "你好").catch(function (err) {
					return console.error(err.toString());
			  });
			  
		});
	});

</script> *@

<h1>Server Status</h1>
<div id="status">
	<p>Loading...</p>
</div>

<script>
	const eventSource = new EventSource('/api/home/StreamSSEvents');

	eventSource.onmessage = function (event) {
		console.log(event.data);
		document.getElementById('status').innerHTML = event.data;
	};

	eventSource.onerror = function (error) {
		console.error("Error occurred: ", error);
	};
</script>
