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 >
0 commit comments