mirror of
https://git.teknik.io/Teknikode/Teknik.git
synced 2023-08-02 14:16:22 +02:00
Started integrating rPi stream into website
This commit is contained in:
parent
2ecea12305
commit
0a24c595d3
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Teknik.Areas.Stream.ViewModels;
|
||||
@ -15,7 +16,54 @@ namespace Teknik.Areas.Stream.Controllers
|
||||
{
|
||||
ViewBag.Title = "Teknikam";
|
||||
StreamViewModel model = new StreamViewModel();
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[AllowAnonymous]
|
||||
public ActionResult ViewStream(int id)
|
||||
{
|
||||
if (Config.StreamConfig.Enabled)
|
||||
{
|
||||
if (id > 0 && id <= Config.StreamConfig.Sources.Count)
|
||||
{
|
||||
// ID is valid, so let's get the stream
|
||||
string source = Config.StreamConfig.Sources[id - 1];
|
||||
|
||||
System.IO.Stream stream = null;
|
||||
|
||||
//This controls how many bytes to read at a time and send to the client
|
||||
int bytesToRead = 10000;
|
||||
|
||||
// Buffer to read bytes in chunk size specified above
|
||||
byte[] buffer = new Byte[bytesToRead];
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
//Create a WebRequest to get the file
|
||||
HttpWebRequest fileReq = (HttpWebRequest)HttpWebRequest.Create(source);
|
||||
|
||||
//Create a response for this request
|
||||
HttpWebResponse fileResp = (HttpWebResponse)fileReq.GetResponse();
|
||||
|
||||
if (fileReq.ContentLength > 0)
|
||||
fileResp.ContentLength = fileReq.ContentLength;
|
||||
|
||||
//Get the Stream returned from the response
|
||||
stream = fileResp.GetResponseStream();
|
||||
|
||||
return File(stream, "image/jpeg");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Redirect(Url.SubRouteUrl("error", "Error.Http404"));
|
||||
}
|
||||
}
|
||||
return Redirect(Url.SubRouteUrl("error", "Error.Http404"));
|
||||
}
|
||||
return Redirect(Url.SubRouteUrl("error", "Error.Http403"));
|
||||
}
|
||||
}
|
||||
}
|
@ -25,6 +25,14 @@ namespace Teknik.Areas.Stream
|
||||
new { controller = "Stream", action = "Index" }, // Parameter defaults
|
||||
new[] { typeof(Controllers.StreamController).Namespace }
|
||||
);
|
||||
context.MapSubdomainRoute(
|
||||
"Stream.View", // Route name
|
||||
new List<string>() { "stream" }, // Subdomains
|
||||
new List<string>() { config.Host }, // domains
|
||||
"Stream/{id}", // URL with parameters
|
||||
new { controller = "Stream", action = "ViewStream" }, // Parameter defaults
|
||||
new[] { typeof(Controllers.StreamController).Namespace }
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@ -9,5 +9,11 @@ namespace Teknik.Areas.Stream.ViewModels
|
||||
{
|
||||
public class StreamViewModel : ViewModelBase
|
||||
{
|
||||
public List<string> Streams;
|
||||
|
||||
public StreamViewModel()
|
||||
{
|
||||
Streams = new List<string>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,12 +3,12 @@
|
||||
<div class="container">
|
||||
@if (Model.Config.StreamConfig.Enabled)
|
||||
{
|
||||
foreach (string src in Model.Config.StreamConfig.Sources)
|
||||
for (int i = 1; i <= Model.Config.StreamConfig.Sources.Count; i++)
|
||||
{
|
||||
<div class="row">
|
||||
<div class="col-ms-12">
|
||||
<div class="thumbnail" width="330" height="250">
|
||||
<img src="@src">
|
||||
<img src="@Url.SubRouteUrl("stream", "Stream.View", new { id = i })">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user