Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b445db9

Browse files
committedJan 13, 2019
Name your stream
1 parent 4bb21e0 commit b445db9

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed
 

‎Hubs/StreamHub.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public ChannelReader<string> WatchStream(string streamName)
2323
{
2424
// TODO:
2525
// Allow client to stop watching a stream, or is that automatic if they cancel on the client (double check this)
26-
26+
// There can be multiple consumers, so we'll need to do something about that so they all get the frames instead of getting (1 / # clients) frames
27+
2728
var stream = _streamManager.GetStream(streamName);
2829
return stream;
2930
}
@@ -36,7 +37,6 @@ public async Task StartStream(string streamName, ChannelReader<string> streamCon
3637
var channel = Channel.CreateBounded<string>(options: new BoundedChannelOptions(2) {
3738
FullMode = BoundedChannelFullMode.DropOldest
3839
});
39-
//var channel = Channel.CreateUnbounded<string>();
4040

4141
if (!_streamManager.AddStream(streamName, channel))
4242
{

‎Pages/Index.cshtml

+19-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ Available streams:
1111
</ul>
1212
</div>
1313

14+
Stream name: <input type="textbox" id="streamName" value="" />
1415
<input type="button" id="startStream" value="Start streaming" />
16+
<input type="button" id="stopStream" value="Stop streaming" disabled />
1517

1618
<pre id="myPre"></pre>
1719
<canvas id="myCanvas"></canvas>
@@ -58,8 +60,20 @@ async function startAsync() {
5860
}
5961
6062
const startStreamButton = document.getElementById('startStream');
63+
const stopStreamButton = document.getElementById('stopStream');
64+
stopStreamButton.onclick = function () {
65+
stopStreamButton.setAttribute("disabled", "disabled");
66+
startStreamButton.removeAttribute("disabled");
67+
if (isStreaming === true) {
68+
subject.complete();
69+
camera.stop();
70+
isStreaming = false;
71+
}
72+
}
6173
startStreamButton.onclick = async function () {
6274
startStreamButton.setAttribute("disabled", "disabled");
75+
stopStreamButton.removeAttribute("disabled");
76+
let streamName = document.getElementById("streamName").value;
6377
const asciiCanvas = document.getElementById("myPre");
6478
6579
subject = new signalR.Subject();
@@ -82,14 +96,18 @@ async function startAsync() {
8296
},
8397
8498
onSuccess: function() {
99+
isStreaming = true;
85100
},
86101
87102
onError: function(error) {
88103
console.log(error);
89104
}
90105
});
91106
92-
await connection.send("StartStream", "Some name", subject);
107+
if (streamName === "") {
108+
streamName = "random name " + Math.random() * 2;
109+
}
110+
await connection.send("StartStream", streamName, subject);
93111
}
94112
}
95113

‎Startup.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
6464
{
6565
route.MapHub<StreamHub>("/stream", o =>
6666
{
67-
o.TransportMaxBufferSize = 1000000;
68-
o.ApplicationMaxBufferSize = 1000000;
67+
//o.TransportMaxBufferSize = 1000000;
68+
//o.ApplicationMaxBufferSize = 1000000;
6969
});
7070
});
7171

0 commit comments

Comments
 (0)