Skip to content

Commit b126915

Browse files
committed
Added streaming and embed code capabilities
1 parent a9784d2 commit b126915

File tree

5 files changed

+37
-14
lines changed

5 files changed

+37
-14
lines changed

embed.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
ctrl.streamPresence(function(m){
7070
here_now.innerHTML = m.occupancy;
7171
});
72+
ctrl.unable(function(){ handleNoStream(); });
7273

7374
// Get URL params
7475
function urlparams() {
@@ -82,7 +83,7 @@
8283
}
8384

8485
function handleNoStream(){
85-
vid_out.innerHTML="<h1>That stream no longer exists!</h1>";
86+
video_out.innerHTML="<h1>That stream no longer exists!</h1>";
8687
stream_info.hidden=true;
8788
}
8889

embed_test.html

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

js/rtc-controller.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,27 @@ var CONTROLLER = window.CONTROLLER = function(phone){
1919
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
2020
// Setup Phone and Session callbacks.
2121
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
22-
var readycb = function(session){};
22+
var readycb = function(){};
23+
var unablecb = function(){};
2324
var receivecb = function(session){};
24-
var authcb = function(){};
2525
var videotogglecb = function(session, isEnabled){};
2626
var audiotogglecb = function(session, isEnabled){};
2727

2828
CONTROLLER.ready = function(cb) { readycb = cb };
29-
CONTROLLER.auth = function(cb) { authcb = cb }
29+
CONTROLLER.unable = function(cb) { unablecb = cb };
3030
CONTROLLER.receive = function(cb) { receivecb = cb };
3131
CONTROLLER.videoToggled = function(cb) { videotogglecb = cb };
3232
CONTROLLER.audioToggled = function(cb) { audiotogglecb = cb };
3333

3434
phone.ready(function(){ readycb() });
35+
phone.unable(function(){ unablecb() });
3536
phone.receive(function(session){
3637
manage_users(session);
3738
receivecb(session);
3839
});
3940

40-
// Require some boolean form of authentication to accept a call
41+
/* Require some boolean form of authentication to accept a call
42+
var authcb = function(){};
4143
CONTROLLER.answerCall = function(session, auth, cb){
4244
auth(acceptCall(session, cb), session);
4345
}
@@ -47,7 +49,7 @@ var CONTROLLER = window.CONTROLLER = function(phone){
4749
if (accept) cb(session);
4850
else phone.hangup(session.number);
4951
}
50-
}
52+
}*/
5153

5254
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
5355
// Setup broadcasting, your screen to all.

js/webrtc.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,9 @@ var PHONE = window.PHONE = function(config) {
189189
talk.message = function(cb) {talk.usermsg = cb; return talk};
190190

191191
// Add Local Media Streams Audio Video Mic Camera
192-
if (!isAnswer)
193-
talk.pc.addStream(mystream); // Add null here on the receiving end of streaming to go one-way.
192+
// If answering and oneway streaming, do not attach stream
193+
if (!isAnswer || !oneway)
194+
talk.pc.addStream(mystream); // Add null here on the receiving end of streaming to go one-way.
194195

195196
// Notify of Call Status
196197
update_conversation( talk, 'connecting' );
@@ -415,6 +416,7 @@ var PHONE = window.PHONE = function(config) {
415416
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
416417
function getusermedia() { //Do something if not requesting any media?
417418
if (oneway){
419+
if (!PeerConnection){ return unablecb(); }
418420
onready();
419421
subscribe();
420422
return;

streams.html

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,16 @@
5252
</form>
5353

5454
<div id="inStream">
55-
<button id="end" onclick="end()">Done</button>
55+
<button id="end" onclick="end()">Done</button> <br>
56+
Embed Style: <button onclick="genEmbed(400,600)">Tall</button><button onclick="genEmbed(600,400)">Wide</button><button onclick="genEmbed(500,500)">Square</button><br>
57+
<div id="embed-code"></div>
58+
<div id="embed-demo"></div>
5659
</div>
5760
<div id="logs"></div>
5861

5962
<p><b>To Use:</b></p>
60-
<p>Type a username and click Log in. If input turns green you are ready to receive/place a call.</p>
61-
<p>In a separate browser window, log in with a different username, and place a call to the first.</p>
63+
<p>Type a channel to stream to and click Stream.</p>
64+
<p>In a separate browser window, join the steam you created.</p>
6265

6366
<!-- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -->
6467
<!-- WebRTC Peer Connections -->
@@ -70,10 +73,13 @@
7073

7174
<script type="text/javascript">
7275

73-
var video_out = document.getElementById("vid-box");
76+
var video_out = document.getElementById("vid-box");
77+
var embed_code = document.getElementById("embed-code");
78+
var embed_demo = document.getElementById("embed-demo");
79+
var streamName;
7480

7581
function stream(form) {
76-
var streamName = form.streamname.value || Math.floor(Math.random()*100)+'';
82+
streamName = form.streamname.value || Math.floor(Math.random()*100)+'';
7783
var phone = window.phone = PHONE({
7884
number : streamName, // listen on username line else random
7985
publish_key : 'pub-c-561a7378-fa06-4c50-a331-5c0056d0163c', // Your Pub Key
@@ -135,6 +141,18 @@
135141
$('#logs').append("<p>"+log+"</p>");
136142
}
137143

144+
function genEmbed(w,h){
145+
if (!streamName) return;
146+
var url = "http://kevingleason.me/SimpleRTC/embed.html?stream=" + streamName;
147+
var embed = document.createElement('iframe');
148+
embed.src = url;
149+
embed.width = w;
150+
embed.height = h;
151+
embed_demo.innerHTML = embed.outerHTML;
152+
embed_code.innerHTML = '';
153+
embed_code.appendChild(document.createTextNode(embed.outerHTML));
154+
}
155+
138156
</script>
139157
</body>
140158
</html>

0 commit comments

Comments
 (0)