Skip to content

Commit 0ab3f3c

Browse files
committed
Make the Cordova app suitable for Android+Crosswalk.
1 parent 5a50a03 commit 0ab3f3c

File tree

2 files changed

+41
-38
lines changed

2 files changed

+41
-38
lines changed

www/appwindow.html

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -116,48 +116,63 @@ <h1>AppRTC</h1>
116116
</div>
117117

118118

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>
122119
<script type="text/javascript" src="js/performance.now.js"></script>
123120
<script type="text/javascript" src="cordova.js"></script>
124121

125122
<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");
128125

129-
document.addEventListener('deviceready', function () {
130-
console.log('iOSRTCApp >>> "deviceready" event');
126+
document.addEventListener("deviceready", function () {
127+
console.log("iOSRTCApp >>> deviceready event");
131128

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("*");
135132

136133
// Pollute global namespace with WebRTC stuff.
137134
cordova.plugins.iosrtc.registerGlobals();
138135

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) {
141165
setTimeout(function () {
142-
var script = document.createElement('script');
166+
var script = document.createElement("script");
143167

144-
script.type = 'text/javascript';
168+
script.type = "text/javascript";
145169
script.src = path;
146-
document.getElementsByTagName('head')[0].appendChild(script);
170+
document.getElementsByTagName("head")[0].appendChild(script);
147171
});
148172
});
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>');
152173
}, 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.
161176
</script>
162177

163178
</body>

www/js/apprtc.debug.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,15 +2199,3 @@ apprtc.windowPort = apprtc.windowPort || {};
21992199
return port_;
22002200
};
22012201
})();
2202-
2203-
2204-
function updateVideos() {
2205-
trace("Update iosrtc videos");
2206-
2207-
// NOTE: hack, but needed due to CSS transitions and so on.
2208-
[0, 500, 1000, 1500].forEach(function (delay) {
2209-
setTimeout(function () {
2210-
cordova.plugins.iosrtc.refreshVideos();
2211-
}, delay);
2212-
});
2213-
}

0 commit comments

Comments
 (0)