Integrating GorillaStreaming on Client side
Installation
Install the streaming client library.
npm install @monkeyway/streaming-lib
Add an HTML video element for the stream to your website
To display the stream you will need an HTML video element.
Create a new StreamingService object
const options = {
baseUrl = '<Streaming backend URL>',
appEnvId = '<Your AppEnv ID>',
apiKey = '<Your client API key',
};
let streaming = new StreamingService(options);
Request a streaming session
const videoElem; // HTML video element for the stream
const streamInfo$ = streaming.start();
streamInfo$.subscribe({
next: info => {
if (!info) {
// session ended
} else {
// session established
videoElem.srcObject = info.stream;
videoElem.play();
}
},
error: async err => {
// error establishing streaming session
if (err instanceof SessionNotAvailableError) {
// no session available
}
}
});
End the streaming session
await streaming.stop();
info
If you want to enable the user to control your application, see Controlling the Application
caution
Integrating streaming this way will expose your client API key to user devices.