Skip to content

Instantly share code, notes, and snippets.

@msell
Last active December 12, 2015 02:38
Show Gist options
  • Save msell/4700246 to your computer and use it in GitHub Desktop.
Save msell/4700246 to your computer and use it in GitHub Desktop.
example of how to stop the streaming
using System.Web.Mvc;
namespace MvcApplication2.Controllers
{
public class LiveStreamingController : Controller
{
public ActionResult Index(string id)
{
var vm = new ViewModel { VehicleName = id };
return View(vm);
}
[HttpPost]
public JsonResult Stop(string id)
{
var results = new {success = true};
return Json(results);
}
}
public class ViewModel
{
public string VehicleName { get; set; }
public string Department { get; set; }
public string Officer { get; set; }
}
}
<!--view: -->
@model MvcApplication2.Controllers.ViewModel
<div>
<button id="stopStreamingButton" onclick="makeItStop()">Stop Streaming</button>
</div>
<script type="text/javascript">
window.onbeforeunload = function() {
makeItStop();
};
var makeItStop = function stopStreaming() {
$.ajax({
type: 'POST',
contentType: 'application/json; charset=UTF-8',
dataType: "json",
url: 'LiveStreaming/Stop/'.concat('@Model.VehicleName'),
success: function () {
console.log("yee haw!");
},
error: function () {
console.log("sad panda.");
}
});
};
</script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment