This repository has been archived by the owner on Aug 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Workshop code + ReadMe
- Loading branch information
Showing
13 changed files
with
417 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.