Browser detection in Javascript for a WebGL app - webgl

OK, I want to do browser detection; I know that everyone say not to. But here's why. I have a WebGL app/page. Detecting WebGL is easy. But if WebGL is not supported, I want to give the user information on what to do next. To do that, I need the browser, the platform and the version. So I get why everyone says to use feature detection, but in this case if I want to give instructions I have to know the browser.
For example, with Firefox I'll tell a user to change an about:config setting whereas with Safari it's on a developer menu (if memory serves).
If there is a better approach, I'm all ears. If not, is there a decent browser detection library that is consistently maintained and deals with all the edge cases or inconsistencies in the way browsers are reported.

Check out this site: http://www.khronos.org/webgl/wiki/FAQ
On get.webgl you have subpage called troubleshooting.
That page detect your browser, OS and other.
You don't have to write it on your own when it's already done.
Detecting:
if(!window.WebGLRenderingContext) {
// the browser doesn't even know what WebGL is
alert("webgl not supported, visit http://get.webgl.org");
}
else {
var canvas = document.getElementById("canvasID");
var context = canvas.getContext("webgl") || canvas.getContext("experimental-webgl");
if(!context) {
// browser supports WebGL but initialization failed
alert("webgl is supported but here is another problem, visit http://get.webgl.org/troubleshooting");
}
}
It's everything what you have to do.

Related

Sidestep iOS13 Native PointerEvents

iOS13 implements PointerEvents but has issues (https://caniuse.com/#feat=pointer). The polyfil I've been using for Safari (PEP / Pointer Events Polyfil) is standing down because it appears there is native support, causing things to break.
I've attempted to check for iOS13/iPadOS and set window.PointerEvent==undefined before polyfil activation in a vain attempt to get it to kick in, but no luck--assume there's a range of things I don't know about that need addressed in order to fully sub out a custom system.
I've moved on to alerting users of the issue, and telling them how to to turn off pointer events in experimental features and then reload, which works -- unless the tool is being launched from the home screen as an installed PWA, in which case the setting has no effect (!).
Is there a way to sidestep native input implementation with a polyfil via JS, or to force-turn-off an 'experimental feature' via JS, or to turn off an experimental feature for a PWA in any way?

Can you turn only one page into an app in meteor?

I have just tried to run
meteor run ios
That command emulates my application as an app. But there is just one page that would be interesting to have as an app. Can you control this in some way?
I don't think this is possible. The whole app gets exported regardless of platform, hence the universal/isomorphic apps concept. And in the universal app concept is one that I'm starting to find fault in. That said there is a better middle ground.
We'll call it sudo-universal apps. (probably a horrible name, but whatever :D)
Essentially the concept is that you have 3 codebases, for each device (web/ios/andriod) but share many of the same modules via something like npm, or potentially some other way of sharing code.
Then you can focus on the ui for each device and its strengths and weaknesses, but keep all the important logic you've built.
Check out the following:
https://voice.kadira.io/say-no-to-isomorphic-apps-b7b7c419c634#.3bn5ovts1
https://forums.meteor.com/t/say-no-to-universal-apps/16813/7
Hope this helps!
You can check whether the client code is executed on iOS or not, and change the app accordingly:
if(navigator.userAgent.match(/(iPad|iPhone|iPod)/g)) {
// Disable the links, and redirect to which page you want
}
But Justin's answer is great, a new platform usually needs more than just some tweaks. A quickly developed app has very low value for the user.

MEDIA_ERR_DECODE on HTML5 video in iOS UIWebView after many plays

After playing around 20 short video clips (mp4's) in an HTML5 video control in a UIWebView in iOS, subsequent clips are failing with a MEDIA_ERR_DECODE. The thing is, is that I know the videos are fine, because they were previously played, sometimes even during the same session.
Furthermore, if you wait long enough to request a new video clip, it will usually start working again.
I also know it's not the server because I can do the exact same operation on chrome on my desktop computer and it always works.
Based on my troubleshooting, it seems like the bug is in iOS itself.
Does anyone have any ideas for working around this?
Is there any way to get more information about an media decode error like this in iOS? I tried using Safari's development tool to listen to the http requests but I can't let it record longer than a few seconds before it hits an out of memory error and kills the app.
UPDATE: It also works fine when run in the iOS simulator. It seems the problem only occurs on the iPad itself
After a discussion with Apple Support, the problem has been fixed. The problem has to do with the hardware H264 decoder. Basically, I was never removing the videos from the hardware decoder buffer by never releasing the video resources (which I thought javascript would do itself).
So I was setting the source like this:
$(vid).src = "some source file";
$(vid).play();
... some other stuff happens ...
$(vid).remove();
Doing it this way never removed the video from the decoder buffer, which meant that eventually it not be able to decode any more videos.
To fix this, this is how you must remove the video from the DOM:
$(vid).src = "some source file";
$(vid).play();
... some other stuff happens ...
$(vid).remove();
$(vid).src = "";
$(vid).load();
Now I realize that this doesn't make a ton of sense because after .remove() is called, I would have assumed that the control has been removed from the DOM and any garbage collection would do the rest automatically. However, it doesn't work like that. I hope this helps other people.
It is not iOS specific. I can reproduce in Chrome web browser.
NB : If the video has multiple sources, you must reset src attribute for each source.
var sources = $(vid).getElementsByTagName('source');
for (var index = 0; index < sources.length; index++)
{
sources[index].src = "";
}
$(vid).load();
jugg1es answer above is correct, but the problem still exists if you're trying to use HLS video. When I tried to use his solution with jquery-3.1.1.js I hit an error in jquery's load() method. Not using jquery actually worked for me:
document.getElementById(id).src = "";
document.getElementById(id).load();
Thanks jugg1es you saved my project.

Blackberry application works in simulator but not device

I read some of the similar posts on this site that deal with what seems to be the same issue and the responses didn't really seem to clarify things for me.
My application works fine in the simulator. I believe I'm on Bold 9000 with OS 4.6. The app is signed.
My app makes an HTTP call via 3G to fetch an XML result. type is application/xhtml+xml.
In the device, it gives no error. it makes no visual sign of error. I tell the try catch to print the results to the screen and I get nothing.
HttpConnection was taken right out of the demos and works fine in sim.
Since it gives no error, I begin to reflect back on things I recall reading back when the project began. deviceside=true? Something like that?
My request is simply HttpConnection connection = (HttpConnection)Connector.open(url);
where url is just a standard url, no get vars.
Based on the amount of time I see the connection arrows in the corner of the screen, I assume the app is launching the initial communication to my server, then either getting a bad result, or it gets results and the persistent store is not functioning as expected.
I have no idea where to begin with this. Posting code would be ridiculous since it would be basically my whole app.
I guess my question is if anyone knows of any major differences with device versus simulator that could cause something like http connection or persistent store to fail?
A build setting? An OS restriction? Any standard procedure I may have just not known about that everyone should do before beginning device testing?
Thanks
Just providing the URL will not work. You will have to append some info after the URL to determine the transport method your HTTP connection will use. For instance http://example.com;deviceside=true will use DirectTCP (you might also have to supply APN information but that's saved on the device for my phone). http://example.com;interface=wifi will use wi-fi. On OS 5 there's a ConnectionFactory class that makes this a lot easier. Here's a link that goes into more detail.
This was a tough one for me!
As Jonathan said you have to put some parameters in the url to make it work on the device. You shouldn't do it by hand but use the ConnectionFactory instead.
As you may thing this would just make it work but it doesn't!
The real problem is that not the url has been altered because it has ;interface=wifi;deviceside=true in it (in my case). Depending on the webserver accepting your request this could broke the code.
A solution I tried and that works is try to happend a fake parameter like
&foo=true -> &foo=true;deviceside=true
This will result as a standard parameter for the webserver but your device would use it to driver your connection.
On the simulator this work without this extra code because behind it there is a BIS server for you. On the device (as in my case) there isn't because I'm using a development device unregistered and without SIM (just wifi).
Another point is that the HttpConnection class doesn't handle HTTP 302 Redirect and if you get one you have to handle it manually.
It's probably an issue with the APN not being specified. See my answer for this question for details:
video streaming over http in blackberry
I would make this a comment, but I think I don't have enough rep yet for that... So I'll just answer and hope this doesn't get hosed for just pasting in some links.
I've been working on this exact sort of networking issue on our app this past week, and it is indeed tricky as some others have pointed out. Here are two links which really helped us out using HTTP on different devices, especially older devices which do not provide ConnectionFactory.
http://supportforums.blackberry.com/t5/Java-Development/Connecting-your-BlackBerry-http-and-socket-connections-to-the/td-p/206242
The first one has some code examples, including demonstration of querying the system's ServiceBook and CoverageInfo classes to make a decision about what kind of connection will work.

Viewing DirectX application remotely

We're working on an application that displays information through a Direct3D visualisation. A late client request is the ability to view this application via some Remote Desktop solution.
Has anyone done anything similar? What options are available / unavailable? I'm thinking RDC, VNC, Citrix...
Any advice?
I think you can still use all of the normal D3D tools, but you won't be able to render to a surface associated with the screen. You'll have to render to a DIB (or some such) and Blt it with GDI to a normal window HDC. RDC/VNC/Citrix should all work with this technique.
Performance will definitely suffer - but that's going to be the case over remote desktop anyway. In fact, if I were you, I would mock up a VERY simple prototype and demonstrate the performance before committing to it.
Good luck!
I think Windows 7 has D3D remoting stuff - probably requires both client and server to be W7 though.
The build-in remote desktop works. (You don't have to do anything special)
But it is extremely slow, because when in doubt, it just sends the contents of a window as a bitmap.

Resources