@@ -116,48 +116,63 @@ <h1>AppRTC</h1>
116
116
</ div >
117
117
118
118
119
- <!-- Avoid iOS WebSocket crash.
120
- https://github.com/eface2face/cordova-plugin-iosrtc/issues/12 -->
121
- < script type ="text/javascript " src ="js/ios-websocket-hack.js "> </ script >
122
119
< script type ="text/javascript " src ="js/performance.now.js "> </ script >
123
120
< script type ="text/javascript " src ="cordova.js "> </ script >
124
121
125
122
< script type ="text/javascript ">
126
- window . addEventListener ( ' load' , function ( ) {
127
- console . log ( ' iOSRTCApp >>> DOM loaded' ) ;
123
+ window . addEventListener ( " load" , function ( ) {
124
+ console . log ( " iOSRTCApp >>> DOM loaded" ) ;
128
125
129
- document . addEventListener ( ' deviceready' , function ( ) {
130
- console . log ( ' iOSRTCApp >>> " deviceready" event' ) ;
126
+ document . addEventListener ( " deviceready" , function ( ) {
127
+ console . log ( " iOSRTCApp >>> deviceready event" ) ;
131
128
132
- // Wait a bit since we are adding more stuff into the DOM.
133
- setTimeout ( function ( ) {
134
- cordova . plugins . iosrtc . debug . enable ( '*' ) ;
129
+ // if iOS devices
130
+ if ( window . device . platform === "iOS" ) {
131
+ cordova . plugins . iosrtc . debug . enable ( "*" ) ;
135
132
136
133
// Pollute global namespace with WebRTC stuff.
137
134
cordova . plugins . iosrtc . registerGlobals ( ) ;
138
135
139
- // Hack.
140
- [ 'js/apprtc.debug.js' , 'js/appwindow.js' ] . forEach ( function ( path ) {
136
+ window . addEventListener ( "orientationchange" , function ( ) {
137
+ console . log ( "iOSRTCApp >>> orientationchange event" ) ;
138
+
139
+ updateVideos ( ) ;
140
+ } ) ;
141
+
142
+ window . updateVideos = function ( ) {
143
+ console . debug ( "iOSRTCApp >>> update iosrtc videos" ) ;
144
+
145
+ // NOTE: hack, but needed due to CSS transitions and so on.
146
+ [ 0 , 500 , 1000 , 1500 ] . forEach ( function ( delay ) {
147
+ setTimeout ( function ( ) {
148
+ cordova . plugins . iosrtc . refreshVideos ( ) ;
149
+ } , delay ) ;
150
+ } ) ;
151
+ } ;
152
+ }
153
+ // Non iOS devices.
154
+ else {
155
+ window . updateVideos = function ( ) { } ;
156
+ }
157
+
158
+ // Wait a bit since we are adding more stuff into the DOM.
159
+ setTimeout ( function ( ) {
160
+ // Avoid iOS WebSocket crash:
161
+ // https://github.com/eface2face/cordova-plugin-iosrtc/issues/12
162
+ // Also looad the original AppRTC JS scripts once Cordova is ready (so the iosrtc plugin
163
+ // has polluted the window namespace with WebRTC class/functions).
164
+ [ "js/ios-websocket-hack.js" , "js/apprtc.debug.js" , "js/appwindow.js" ] . forEach ( function ( path ) {
141
165
setTimeout ( function ( ) {
142
- var script = document . createElement ( ' script' ) ;
166
+ var script = document . createElement ( " script" ) ;
143
167
144
- script . type = ' text/javascript' ;
168
+ script . type = " text/javascript" ;
145
169
script . src = path ;
146
- document . getElementsByTagName ( ' head' ) [ 0 ] . appendChild ( script ) ;
170
+ document . getElementsByTagName ( " head" ) [ 0 ] . appendChild ( script ) ;
147
171
} ) ;
148
172
} ) ;
149
- // ...since this fails and creates an empty <body>.
150
- // document.write('<script type="text/javascript" src="js/apprtc.debug.js"><\/script>');
151
- // document.write('<script type="text/javascript" src="js/appwindow.js"><\/script>');
152
173
} , 1000 ) ;
153
- } ) ;
154
- } ) ;
155
-
156
- window . addEventListener ( 'orientationchange' , function ( ) {
157
- console . log ( 'iOSRTCApp >>> orientationchange event' ) ;
158
-
159
- updateVideos ( ) ;
160
- } ) ;
174
+ } ) ; // End of ondeviceready.
175
+ } ) ; // End of onload.
161
176
</ script >
162
177
163
178
</ body >
0 commit comments