I am trying to figure out how the browser code is controlling the streaming of images from my server .
I am fairly new to web technologies, markup languages and javascript.
I am streaming images from a camera to a browser. To start the stream the user presses a button which executes javascript code
that populates an image elements source attribute. ie "192.168.1.23:81/stream" The streaming consists of sending data
frame by frame to the browser until steaming is stopped by the user by toggling the stream button.
The camera is made up of a microcontroller board with a camera attached and functions as the server.
The server is configured to continuously send a frame of image data to the browser until the stop button is activated on the browser.
There are other buttons and checkboxes on the browser to control things on the server but those things use a fetch command to
communicate with the server. The streaming does not use "fetch" to communicate with the server. It seems the stream starts
or stops when the src attribute is populated (start) or empty ("")(stopped).
So I am wondering how streaming actually works.
Only the stream uses port 81 everything else uses port 80.
Here are some code snippets
HTML Code
Javascript Code
I am fairly new to web technologies, markup languages and javascript.
I am streaming images from a camera to a browser. To start the stream the user presses a button which executes javascript code
that populates an image elements source attribute. ie "192.168.1.23:81/stream" The streaming consists of sending data
frame by frame to the browser until steaming is stopped by the user by toggling the stream button.
The camera is made up of a microcontroller board with a camera attached and functions as the server.
The server is configured to continuously send a frame of image data to the browser until the stop button is activated on the browser.
There are other buttons and checkboxes on the browser to control things on the server but those things use a fetch command to
communicate with the server. The streaming does not use "fetch" to communicate with the server. It seems the stream starts
or stops when the src attribute is populated (start) or empty ("")(stopped).
So I am wondering how streaming actually works.
Only the stream uses port 81 everything else uses port 80.
Here are some code snippets
HTML Code
Code:
<div id="stream-container" class="image-container">
<img id="stream" src="" crossorigin>
</div>
Javascript Code
Code:
var baseHost = document.location.origin //location origin
var streamUrl = baseHost + ':81' //for inside the lan only
const stopStream = () => {
window.stop(); //stops images from loading
streamButton.innerHTML = 'Start Stream'; //changes text on stream button
}
const startStream = () => {
view.src = `${streamUrl}/stream`; //assigns uri the source of the image frames
streamButton.innerHTML = 'Stop Stream'; //change text on stream btn
}
//triggers streaming on server
streamButton.onclick = () => {
const streamEnabled = streamButton.innerHTML === 'Stop Stream' //change text on stream btn
if (streamEnabled) {
stopStream();
} else
startStream();
}