Skip to content

Commit a9784d2

Browse files
committed
Added embeddable feature
1 parent 3a4767b commit a9784d2

File tree

5 files changed

+98
-5
lines changed

5 files changed

+98
-5
lines changed

embed.html

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<html>
2+
<head>
3+
<style>
4+
#vid-box{
5+
width: 100%;
6+
height: 100%;
7+
}
8+
9+
#vid-box video{
10+
width: 100%;
11+
height: 100%;
12+
}
13+
14+
#stream-info{
15+
position: absolute;
16+
bottom: 3vh;
17+
right: 5vw;
18+
}
19+
20+
#stream-info img, #stream-info span {
21+
height: 30px;
22+
font-size: 30px;
23+
font-family: sans-serif;
24+
color: #777;
25+
}
26+
</style>
27+
</head>
28+
<body>
29+
<div id="vid-box"></div>
30+
<div id="stream-info" ><img src="img/person_dark.png"/><span id="here-now">0</span></div>
31+
</body>
32+
33+
<script src="https://cdn.pubnub.com/pubnub.min.js"></script>
34+
<script src="js/webrtc.js"></script>
35+
<script src="js/rtc-controller.js"></script>
36+
<script>
37+
38+
(function(){
39+
40+
var urlargs = urlparams();
41+
var video_out = document.getElementById("vid-box");
42+
var stream_info = document.getElementById("stream-info");
43+
var here_now = document.getElementById("here-now");
44+
45+
// Handle error if stream is not in urlargs.
46+
if (!('stream' in urlargs)) {
47+
handleNoStream();
48+
return;
49+
}
50+
var stream = urlargs.stream;
51+
52+
var phone = window.phone = PHONE({
53+
number : "EmbedViewer" + Math.floor(Math.random()*100), // listen on username line else random
54+
publish_key : 'pub-c-561a7378-fa06-4c50-a331-5c0056d0163c', // Your Pub Key
55+
subscribe_key : 'sub-c-17b7db8a-3915-11e4-9868-02ee2ddab7fe', // Your Sub Key
56+
oneway : true,
57+
});
58+
var ctrl = window.ctrl = CONTROLLER(phone);
59+
ctrl.ready(function(){
60+
ctrl.isStreaming(stream, function(isOn){
61+
if (isOn) ctrl.joinStream(stream);
62+
else handleNoStream();
63+
});
64+
});
65+
ctrl.receive(function(session){
66+
session.connected(function(session){ stream_info.hidden=false; video_out.appendChild(session.video); });
67+
session.ended(function(session){ handleNoStream(); });
68+
});
69+
ctrl.streamPresence(function(m){
70+
here_now.innerHTML = m.occupancy;
71+
});
72+
73+
// Get URL params
74+
function urlparams() {
75+
var params = {};
76+
if (location.href.indexOf('?') < 0) return params;
77+
PUBNUB.each(
78+
location.href.split('?')[1].split('&'),
79+
function(data) { var d = data.split('='); params[d[0]] = d[1]; }
80+
);
81+
return params;
82+
}
83+
84+
function handleNoStream(){
85+
vid_out.innerHTML="<h1>That stream no longer exists!</h1>";
86+
stream_info.hidden=true;
87+
}
88+
89+
}());
90+
91+
</script>

embed_test.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<iframe src="http://localhost:8001/embed.html?stream=a" width="600" height="600" frameborder="0"></iframe>

js/rtc-controller.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
(function(){
22

33

4-
var CONTROLLER = window.CONTROLLER = function(phone, stream){
4+
var CONTROLLER = window.CONTROLLER = function(phone){
55
if (!window.phone) window.phone = phone;
66
var ctrlChan = controlChannel(phone.number());
7-
var isStream = stream || false;
7+
var isStream = phone.oneway;
88
var pubnub = phone.pubnub;
99
var userArray = [];
1010
subscribe();

js/webrtc.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,9 @@ var PHONE = window.PHONE = function(config) {
298298
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
299299
// Expose local stream and pubnub object
300300
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
301-
PHONE.mystream = mystream;
302-
PHONE.pubnub = pubnub;
301+
PHONE.mystream = mystream;
302+
PHONE.pubnub = pubnub;
303+
PHONE.oneway = oneway;
303304

304305
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
305306
// Auto-hangup on Leave

streams.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
subscribe_key : 'sub-c-17b7db8a-3915-11e4-9868-02ee2ddab7fe', // Your Sub Key
8181
});
8282
phone.debug(function(m){ console.log(m); })
83-
var ctrl = window.ctrl = CONTROLLER(phone, true);
83+
var ctrl = window.ctrl = CONTROLLER(phone);
8484
ctrl.ready(function(){
8585
form.streamname.style.background="#55ff5b";
8686
form.streamname.value = phone.number();

0 commit comments

Comments
 (0)