Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
Workshop
Browse files Browse the repository at this point in the history
Workshop code + ReadMe
  • Loading branch information
Briggs599 committed Feb 14, 2023
1 parent 560d61b commit 96081b2
Show file tree
Hide file tree
Showing 13 changed files with 417 additions and 1 deletion.
51 changes: 51 additions & 0 deletions 1-viewer-app/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Dolby.io Streaming Workshop: Part 1
// App.js manages the viewer functionality.
// Web Docs: https://docs.dolby.io/streaming-apis/docs/web#viewer

let joinBtn = document.getElementById("joinBtn");
let leaveBtn = document.getElementById("leaveBtn");
let videoPlayer = document.getElementById("videoPlayer");

function addStreamToYourVideoTag(mediaTrack) {
// Takes in a stream and assigns it to the <video> element
videoPlayer.srcObject = mediaTrack;
videoPlayer.hidden = false;
videoPlayer.autoplay = true;
}

/////////////////////////////////////////////////////////////////////////////////
//Part 1: Authenticate Connection to Dolby.io Streaming servers (Millicast)

/////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////
//Part 2: Connect to a stream.
async function connectStream() {
leaveBtn.disabled = false;
joinBtn.disabled = true;

//Specify the join options.
const options = {
disableVideo: false,
disableAudio: true,
bandwidth: 0, //Sets it to the max (un-throttled)
};

//Add stream to the video tag.


// Connecting to the stream.
try {

// Broadcasts can be started from the Dolby.io Dashboard https://streaming.dolby.io/#/tokens
} catch (e) {
console.log("Connection failed, handle error", e);

}
}
/////////////////////////////////////////////////////////////////////////////////

function stopStream() {
//Closes Stream and resets browser.
location.reload();
}
58 changes: 58 additions & 0 deletions 1-viewer-app/complete-sample/app-complete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Dolby.io Streaming Workshop: Part 1
// App.js manages the viewer functionality.
// Web Docs: https://docs.dolby.io/streaming-apis/docs/web#viewer

let joinBtn = document.getElementById("joinBtn");
let leaveBtn = document.getElementById("leaveBtn");
let videoPlayer = document.getElementById("videoPlayer");

function addStreamToYourVideoTag(mediaTrack) {
// Takes in a stream and assigns it to the <video> element
videoPlayer.srcObject = mediaTrack;
videoPlayer.hidden = false;
videoPlayer.autoplay = true;
}

/////////////////////////////////////////////////////////////////////////////////
//Part 1: Authenticate Connection to Dolby.io Streaming servers (Millicast)
const tokenGenerator = () =>
window.millicast.Director.getSubscriber({
streamName: "YOUR STREAM NAME",
streamAccountId: "YOUR ACCOUNT ID",
});

const millicastView = new window.millicast.View("ldm5fm0w", tokenGenerator);
/////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////
//Part 2: Connect to a stream.
async function connectStream() {
leaveBtn.disabled = false;
joinBtn.disabled = true;
//Specify the join options.
const options = {
disableVideo: false,
disableAudio: true,
bandwidth: 0, //Sets it to the max (un-throttled)
};

//Add stream to the video tag.
millicastView.on("track", (event) => {
addStreamToYourVideoTag(event.streams[0]);
});

// Connecting to the stream.
try {
await millicastView.connect(options);
// Broadcasts can be started from the Dolby.io Dashboard https://streaming.dolby.io/#/tokens
} catch (e) {
console.log("Connection failed, handle error", e);
millicastView.reconnect();
}
}
/////////////////////////////////////////////////////////////////////////////////

function stopStream() {
//Closes Stream and resets browser.
location.reload();
}
24 changes: 24 additions & 0 deletions 1-viewer-app/complete-sample/index-complete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<title>Dolby.io Stream Viewer App</title>
<meta name="description" content="Dolby.io Workshop Part #1: Building a WebRTC stream viewing app." />

<script src="https://cdn.jsdelivr.net/npm/@millicast/sdk/dist/millicast.umd.min.js"></script>
<link rel="stylesheet" href="style-complete.css" />
</head>
<body>
<h1>Dolby.io Workshop Part #1: WebRTC Stream Viewer</h1>
<button id="joinBtn" onclick="connectStream()">Join Stream</button>
<button id="leaveBtn" disabled onclick="stopStream()">Leave Stream</button>
<video width="640" height="360" id="videoPlayer" class="vidBox" hidden controls>
Your browser does not support the video playback with the video tag.
</video>
<div>
<a href="https://bit.ly/dolbyio-at-treehacks" target="_blank">Create a Dolby.io Account</a> |
<a href="https://docs.dolby.io/streaming-apis/docs/web#viewer" target="_blank">Dolby.io Streaming Docs</a> |
<a href="url">Hackathon Quick Start</a>
</div>
<script src="app-complete.js"></script>
</body>
</html>
18 changes: 18 additions & 0 deletions 1-viewer-app/complete-sample/style-complete.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
body {
font-family: "Helvetica", Sans-Serif;
color: white;
background-color: black;
margin: auto;
max-width: 640px;
}
video {
border-radius: 10px;
margin-top: 20px;
}
h1 {
margin-top: 15%;
}
div {
margin-top: 10px;
font-size: large;
}
24 changes: 24 additions & 0 deletions 1-viewer-app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<title>Dolby.io Stream Viewer App</title>
<meta name="description" content="Dolby.io Workshop Part #1: Building a WebRTC stream viewing app." />

<script src=""></script>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<h1>Dolby.io Workshop Part #1: WebRTC Stream Viewer</h1>
<button id="joinBtn" onclick="connectStream()">Join Stream</button>
<button id="leaveBtn" disabled onclick="stopStream()">Leave Stream</button>
<video width="640" height="360" id="videoPlayer" class="vidBox" hidden controls>
Your browser does not support the video playback with the video tag.
</video>
<div>
<a href="https://bit.ly/dolbyio-at-treehacks" target="_blank">Create a Dolby.io Account</a> |
<a href="https://docs.dolby.io/streaming-apis/docs/web#viewer" target="_blank">Dolby.io Streaming Docs</a> |
<a href="url">Hackathon Quick Start</a>
</div>
<script src="app.js"></script>
</body>
</html>
18 changes: 18 additions & 0 deletions 1-viewer-app/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
body {
font-family: "Helvetica", Sans-Serif;
color: white;
background-color: black;
margin: auto;
max-width: 640px;
}
video {
border-radius: 10px;
margin-top: 20px;
}
h1 {
margin-top: 15%;
}
div {
margin-top: 10px;
font-size: large;
}
40 changes: 40 additions & 0 deletions 2-publisher-app/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Dolby.io Streaming Workshop: Part 2
// App.js manages the publisher functionality.
// Web Docs: https://docs.dolby.io/streaming-apis/docs/web#publish-a-stream

let startBtn = document.getElementById("startBtn");
let endBtn = document.getElementById("endBtn");
let videoPlayer = document.getElementById("videoPlayer");

function addStreamToYourVideoTag(mediaTrack) {
// Takes in a stream and assigns it to the <video> element
videoPlayer.srcObject = mediaTrack;
videoPlayer.hidden = false;
videoPlayer.autoplay = true;
}

/////////////////////////////////////////////////////////////////////////////////
//Part 1: Authenticate Connection to Dolby.io Streaming servers (Millicast)

/////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////
//Part 2: Broadcast Stream.
async function connectStream() {
startBtn.disabled = true;
endBtn.disabled = false;

// Start broadcast
try {
//To view the stream navigate to: https://viewer.millicast.com?streamId=YOUR_ACCOUNT_ID/YOUR_STREAM_NAME
} catch (e) {
console.error("Connection failed, handle error", e);
}
}
/////////////////////////////////////////////////////////////////////////////////

function stopStream() {
//Ends Stream and resets browser.

location.reload();
}
53 changes: 53 additions & 0 deletions 2-publisher-app/complete-sample/app-complete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Dolby.io Streaming Workshop: Part 2
// App.js manages the publisher functionality.
// Web Docs: https://docs.dolby.io/streaming-apis/docs/web#publish-a-stream

let startBtn = document.getElementById("startBtn");
let endBtn = document.getElementById("endBtn");
let videoPlayer = document.getElementById("videoPlayer");

function addStreamToYourVideoTag(mediaTrack) {
// Takes in a stream and assigns it to the <video> element
videoPlayer.srcObject = mediaTrack;
videoPlayer.hidden = false;
videoPlayer.autoplay = true;
}

/////////////////////////////////////////////////////////////////////////////////
//Part 1: Authenticate Connection to Dolby.io Streaming servers (Millicast)
const tokenGenerator = () =>
window.millicast.Director.getPublisher({
token: "YOUR TOKEN",
streamName: "YOUR STREAM NAME",
});

const publisher = new window.millicast.Publish("my-stream-name", tokenGenerator);
/////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////
//Part 2: Broadcast Stream.
async function connectStream() {
startBtn.disabled = true;
endBtn.disabled = false;
const mediaStream = await navigator.mediaDevices.getUserMedia({ audio: false, video: true });
addStreamToYourVideoTag(mediaStream);

const broadcastOptions = {
mediaStream: mediaStream
};

// Start broadcast
try {
await publisher.connect(broadcastOptions);
//To view the stream navigate to: https://viewer.millicast.com?streamId=YOUR_ACCOUNT_ID/YOUR_STREAM_NAME
} catch (e) {
console.error('Connection failed, handle error', e);
}
}
/////////////////////////////////////////////////////////////////////////////////

function stopStream() {
//Ends Stream and resets browser.
publisher.stop();
location.reload();
}
28 changes: 28 additions & 0 deletions 2-publisher-app/complete-sample/index-complete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<title>Dolby.io Stream Publisher App</title>
<meta name="description" content="Dolby.io Workshop Part #2: Building a WebRTC publisher app." />

<script src="https://cdn.jsdelivr.net/npm/@millicast/sdk/dist/millicast.umd.min.js"></script>
<link rel="stylesheet" href="style-complete.css" />
</head>
<body>
<h1>Dolby.io Workshop Part #2: WebRTC Broadcaster</h1>
<button id="startBtn" onclick="connectStream()">Start Stream</button>
<button id="endBtn" disabled onclick="stopStream()">End Stream</button>
<video width="640" height="360" id="videoPlayer" class="vidBox" hidden controls>
Your browser does not support the video playback with the video tag.
</video>
<div>
<a href="https://bit.ly/dolbyio-at-treehacks" target="_blank">Create a Dolby.io Account</a> |
<a href="https://docs.dolby.io/streaming-apis/docs/web#publish-a-stream" target="_blank"
>Dolby.io Streaming Docs</a
>
|
<a href="url">Hackathon Quick Start</a>
</div>
<b>Live broadcasts can be found at: https://viewer.millicast.com?streamId=ACCOUNT_ID/STREAM_NAME</b>
<script src="app-complete.js"></script>
</body>
</html>
23 changes: 23 additions & 0 deletions 2-publisher-app/complete-sample/style-complete.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
body {
font-family: "Helvetica", Sans-Serif;
color: black;
background-color: white;
margin: auto;
max-width: 640px;
}
video {
border-radius: 10px;
margin-top: 20px;
}
h1 {
margin-top: 15%;
}
div {
margin-top: 10px;
font-size: large;
}
b {
font-size: small;
background-color: bisque;

}
28 changes: 28 additions & 0 deletions 2-publisher-app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<title>Dolby.io Stream Publisher App</title>
<meta name="description" content="Dolby.io Workshop Part #2: Building a WebRTC publisher app." />

<script src=""></script>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<h1>Dolby.io Workshop Part #2: WebRTC Broadcaster</h1>
<button id="startBtn" onclick="connectStream()">Start Stream</button>
<button id="endBtn" disabled onclick="stopStream()">End Stream</button>
<video width="640" height="360" id="videoPlayer" class="vidBox" hidden controls>
Your browser does not support the video playback with the video tag.
</video>
<div>
<a href="https://bit.ly/dolbyio-at-treehacks" target="_blank">Create a Dolby.io Account</a> |
<a href="https://docs.dolby.io/streaming-apis/docs/web#publish-a-stream" target="_blank"
>Dolby.io Streaming Docs</a
>
|
<a href="url">Hackathon Quick Start</a>
</div>
<b>Live broadcasts can be found at: https://viewer.millicast.com?streamId=ACCOUNT_ID/STREAM_NAME</b>
<script src="app.js"></script>
</body>
</html>
Loading

0 comments on commit 96081b2

Please sign in to comment.