@@ -11,7 +11,9 @@ Available streams:
11
11
</ul >
12
12
</div >
13
13
14
+ Stream name: <input type =" textbox" id =" streamName" value =" " />
14
15
<input type =" button" id =" startStream" value =" Start streaming" />
16
+ <input type =" button" id =" stopStream" value =" Stop streaming" disabled />
15
17
16
18
<pre id =" myPre" ></pre >
17
19
<canvas id =" myCanvas" ></canvas >
@@ -58,8 +60,20 @@ async function startAsync() {
58
60
}
59
61
60
62
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
+ }
61
73
startStreamButton .onclick = async function () {
62
74
startStreamButton .setAttribute (" disabled" , " disabled" );
75
+ stopStreamButton .removeAttribute (" disabled" );
76
+ let streamName = document .getElementById (" streamName" ).value ;
63
77
const asciiCanvas = document .getElementById (" myPre" );
64
78
65
79
subject = new signalR.Subject ();
@@ -82,14 +96,18 @@ async function startAsync() {
82
96
},
83
97
84
98
onSuccess : function () {
99
+ isStreaming = true ;
85
100
},
86
101
87
102
onError : function (error ) {
88
103
console .log (error);
89
104
}
90
105
});
91
106
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);
93
111
}
94
112
}
95
113
0 commit comments