|
| 1 | + |
| 2 | +<!-- dial.html --> |
| 3 | + |
| 4 | +<style> |
| 5 | +#video-out { |
| 6 | + position: relative; |
| 7 | +} |
| 8 | +#my-number { |
| 9 | + position: fixed; |
| 10 | + left: 10px; |
| 11 | + color: #fff; |
| 12 | + z-index: 100; |
| 13 | +} |
| 14 | +</style> |
| 15 | + |
| 16 | +<!-- Video Output Zone --> |
| 17 | +<input id="number" /><button onclick="call()">call</button> |
| 18 | +<div id="video-out"> |
| 19 | + <div id="my-number">Loading...</div> |
| 20 | +</div> |
| 21 | + |
| 22 | +<!-- Libs and Scripts --> |
| 23 | +<script src="https://cdn.pubnub.com/pubnub.js"></script> |
| 24 | +<!-- <script src="https://stephenlb.github.io/webrtc-sdk/js/webrtc-v2.js"></script> --> |
| 25 | +<script src="../js/webrtc-v2.js"></script> |
| 26 | + |
| 27 | +<script> |
| 28 | + var session = null; |
| 29 | + const number = (''+Math.random()*100000).split('.')[0]; |
| 30 | + console.log(number); |
| 31 | + document.getElementById('my-number').innerHTML = number; |
| 32 | + |
| 33 | + var phone = PHONE({ |
| 34 | + number : number, |
| 35 | + publish_key : 'pub-c-561a7378-fa06-4c50-a331-5c0056d0163c', |
| 36 | + subscribe_key : 'sub-c-17b7db8a-3915-11e4-9868-02ee2ddab7fe', |
| 37 | + media : { audio : true, video : true }, |
| 38 | + ssl : true |
| 39 | + }); |
| 40 | + |
| 41 | + phone.ready(function(){ |
| 42 | + console.log('Phone is ready'); |
| 43 | + }); |
| 44 | + |
| 45 | + phone.camera.ready(function(video){ |
| 46 | + console.log('Camera is ready', video); |
| 47 | + phone.$('video-out').append(video); //first attempt, all I get is an empty video tag |
| 48 | + }) |
| 49 | + |
| 50 | + // When Call Comes In or is to be Connected |
| 51 | + phone.receive(function(session){ |
| 52 | + console.log('Receiving call from Friend!'); |
| 53 | + session.connected(function(session){ |
| 54 | + // Display Your Friend's Live Video |
| 55 | + console.log("Showing your friend's video stream"); |
| 56 | + phone.$('video-out').appendChild(session.video); |
| 57 | + }); |
| 58 | + }); |
| 59 | + |
| 60 | + function call() { |
| 61 | + var callee = document.getElementById('number').value; |
| 62 | + console.log('calling ' + callee) |
| 63 | + session = phone.dial(callee); |
| 64 | + } |
| 65 | +</script> |
0 commit comments