Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebSocket hack loads iff iOS Cordova #138

Merged
merged 3 commits into from
May 10, 2016
Merged

WebSocket hack loads iff iOS Cordova #138

merged 3 commits into from
May 10, 2016

Conversation

apparition47
Copy link
Contributor

There's no easy way to for us to have conditional <script> tags for each individual platform in our index.html. The easiest way seems to be just to have conditional execution right in the ios-websocket-hack.js file itself. This way, all platforms can load the same script but only iOS Cordova will have this WS hack enabled.

@ibc
Copy link
Collaborator

ibc commented Mar 7, 2016

It makes sense. BTW, is this 100% reliable?:

window.cordova.platformId === 'ios'

@apparition47
Copy link
Contributor Author

platformId has been present on the standard CordovaJS object since v3.1.0 (for 3 years now). But now that you mention it, this line should probably be in a document.addEventListener("deviceready", onDeviceReady, false); kind of setup in case this script is loaded before Cordova is loaded.

@ibc
Copy link
Collaborator

ibc commented Mar 7, 2016

If the WS wrapper is loaded once Cordova is ready that would lead to issues with JS scripts that are loaded synchronously and use the window.WebSocket reference.

Is there some way of detecting the platform before Cordova "deviceready" event?

@apparition47
Copy link
Contributor Author

In that case, this will work as is. You just need to ensure that <script src="Cordova.js"> is before <script src="ios-websocket-hack.js"> in your index.html. It appears that cordova.platformId is available before device ready; I've been playing around with this and it works well.

Sent from my iPhone

On Mar 7, 2016, at 3:21 AM, Iñaki Baz Castillo notifications@github.com wrote:

If the WS wrapper is loaded once Cordova is ready that would lead to issues with JS scripts that are loaded synchronously and use the window.WebSocket reference.

Is there some way of detecting the platform before Cordova "deviceready" event?


Reply to this email directly or view it on GitHub.

@ibc
Copy link
Collaborator

ibc commented Mar 18, 2016

I don't add <script src="cordova.js"> into the HTML, should I? would the above work without adding it?

@@ -17,6 +17,9 @@


(function () {
// run on iOS Cordova only
if (!(window.cordova && window.cordova.platformId === 'ios')) return;

// Store a reference of the native WebSocket class.
var NativeWebSocket = window.WebSocket;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May you please keep the project indentation and use TAB instead of spaces? Running gulp should throw one or more lint/style errors.

@apparition47
Copy link
Contributor Author

This ios-websocket-hack.js won't use your WS workaround without <script src="cordova.js">, so it's required.

I assumed <script src="cordova.js"> was in every Cordova project. I know that it certainly is in both Ionic 1 and 2 seeds. Is this an invalid assumption?

@derwaldgeist
Copy link
Contributor

I want to support this pull request. As Meteor is using Websockets heavily, I did not want to let the hack to be run outside the iOS context, so I patched this file manually.

@ibc ibc merged commit 3d4ed10 into cordova-rtc:master May 10, 2016
@ibc
Copy link
Collaborator

ibc commented May 10, 2016

Will be available in version 3.0.1. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants