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

tvOS Support #549

Closed
wants to merge 32 commits into from
Closed

tvOS Support #549

wants to merge 32 commits into from

Conversation

darionco
Copy link

@darionco darionco commented Oct 6, 2015

I am opening this just as a reference because my fork has too many unmanaged changes.

974b31e, 5769290, d4d2e5f, ea81316 add tvOS support to ejecta and the methods to forward the remote control input events to JavaScript through the events:

pressstart
pressend
presschange

each remote button press event contains a pressType property that can contain any of the following values:

select
upArrow
downArrow
leftArrow
rightArrow
menu
playPause

I will delete this pull request once the changes have been acknowledged, rejected or accepted by @phoboslab

Dario Segura and others added 28 commits October 16, 2014 21:56
…ons to be able to use "source" type elements to provide a list of source files.
…pportedInterfaceOrientations" instead of "UIInterfaceOrientation"
…pportedInterfaceOrientations" instead of "UIInterfaceOrientation"
# By Dominic Szablewski (19) and Dario Segura (2)
# Via Dominic Szablewski
* 'master' of github.com:phoboslab/Ejecta: (21 commits)
  Embed GL shaders in source; close phoboslab#444
  Cosmetics: clean up Canvas Context creation
  Removed contentScale warning; see phoboslab#441
  Removed obsolete section about architectures in README
  Compile for arm64 as well by default; new fat JSC lib
  Use NSData's base64 encoder for DataURIs
  Added support for gradient & pattern strokes; close phoboslab#455
  Cosmetics
  -[ORIENTATION] Solves crash caused by Info.plist file using the "UISupportedInterfaceOrientations" key instead of "UIInterfaceOrientation"
  Fixed deprecations for GameCenter
  Fixed various deprecated stuff
  Removed deprecated volume property for Videos
  Update SocketRocket lib
  Added .playbackRate property for Audio; close phoboslab#388
  Update Deployment Target to iOS 8 to silence launch screen warning
  Allow 3x retina scaling for iPhone6; fix phoboslab#453
  Use XIB for launch screen; close phoboslab#420
  Make xhr response and responseText enumerable; see phoboslab#448
  Cosmetics
  Properly release WebGL extensions. See phoboslab#442
  ...
* 'master' of github.com:TrompoGames/Ejecta:
  -[ORIENTATION] Solves crash caused by Info.plist file using the "UISupportedInterfaceOrientations" instead of "UIInterfaceOrientation"
# By Dominic Szablewski (8) and Dario Segura (2)
# Via Dario Segura (4) and Dominic Szablewski (2)
* 'master' of github.com:TrompoGames/Ejecta:
  Embed GL shaders in source; close phoboslab#444
  Cosmetics: clean up Canvas Context creation
  Removed contentScale warning; see phoboslab#441
  Removed obsolete section about architectures in README
  Compile for arm64 as well by default; new fat JSC lib
  Use NSData's base64 encoder for DataURIs
  Added support for gradient & pattern strokes; close phoboslab#455
  Cosmetics
  -[ORIENTATION] Solves crash caused by Info.plist file using the "UISupportedInterfaceOrientations" key instead of "UIInterfaceOrientation"
  -[ORIENTATION] Solves crash caused by Info.plist file using the "UISupportedInterfaceOrientations" instead of "UIInterfaceOrientation"

Conflicts:
	Ejecta.xcodeproj/project.pbxproj
	Source/Ejecta/EJCanvas/2D/EJGLProgram2D.h
	Source/Ejecta/EJSharedOpenGLContext.m
# By Dominic Szablewski (14) and finscn (1)
# Via Dominic Szablewski
* 'master' of github.com:phoboslab/Ejecta:
  Fix phoboslab#509 - make sure the final view render buffer is bound when resizing
  Fix phoboslab#514 - crash on failed IAP purchase
  Fix phoboslab#502 for WebGL Screen Canvas
  Fix phoboslab#498 - add 'target' property to touches
  Check if file exits before triggering image onload callback
  Cosmetics
  Resolve special paths for resources; close phoboslab#491
  Fix phoboslab#502 - don't resize context when it doesn't yet have a framebuffer
  Silence warning for EJTexture return type
  Fix phoboslab#400 - cyclic reference of Canvas and CanvasContext
  Fix KeyInput delete; see phoboslab#484
  Cosmetics
  Fix phoboslab#473 - Text Middle Baseline Calculation
  Update SRWebSocket.m
  Attempt to fix black screen on context creation; see phoboslab#462
# By Dominic Szablewski (3) and Michael Cornell (1)
# Via Dominic Szablewski
* 'master' of github.com:phoboslab/Ejecta:
  Return empty string when we have no response headers; fix phoboslab#533
  Allow sending array buffers for XMLHttpRequest; close phoboslab#531
  support EJJavascriptViews placed inside of XIBs of other view controllers
  Assume local files requested with XHR are UTF8; close phoboslab#523
@phoboslab
Copy link
Owner

Great work! I'll go through this in the coming days and merge what I think is appropriate.

Can you explain your changes to EJBindingAudio.m? What's the use case for appendChild etc.?

I think the UIPress stuff would be better of in its own event, rather than piggybacking on the touch events.

Also, I don't think the changes for requestAnimationFrame are necessary. setTimeout already uses the DisplayLink internally and will always execute on the next frame if you set a timeout less than 18ms.

@darionco
Copy link
Author

darionco commented Oct 9, 2015

Awesome.

The audio changes were made because web browsers support different sources for a single sound, this allows the browser to select the best source to play at run time based on compatibility, for example:

var sound = doc.createElement("audio");

var sourceCaf = doc.createElement("source");
sourceCaf.src = "resources/audio/blip.caf";
sourceCaf.type = "audio/x-caf";
sound.appendChild(sourceCaf);

var sourceWav = doc.createElement("source");
sourceWav.src = "resources/audio/blip.wav";
sourceWav.type = "audio/wav";
sound.appendChild(sourceWav);

The most obvious use case for this is .caf files. Safari running on OSX supports playing .caf files natively but all the other browsers (and even Safari running on any operating system other than OSX) don't; Apple recommends the .caf format for SFX on iOS devices which is in conflict with browser support. Instead of having to change the source code to run on ejecta, the code above can be used to support all the platforms seamlessly. I understand that a simple if (window.ejecta) or similar could be used but even some audio libraries prefer using appendChild, like Buzz.js.

The UIPress stuff would definitely be better off in its own event, I am piggybacking on the touch events simply because I needed a solution ASAP and the specification is not final so I would hate to do all the work for it to be thrown away once the specification is complete. For that same reason I used a bunch of #if !TARGET_OS_TV. I know that things like sharing and game center are not complete in tvOS yet, so things that needed to be removed now might be available in the next iteration.

Please ignore the changes to requestAnimationFrame. As I said before, my fork has way too many unmanaged changes that don't necessarily make sense for everyone. The reason why I implemented requestAnimationFrame in it's own is because I needed it to not use the same mechanism as setTimeout for synchronization reasons, but I am doing a bunch of non-standard stuff on the objective-c side anyway. We had this conversation in #440 in which I was confused about the current implementation and we figured that the gains for most people would not be worth it.

As you can probably figure from my commits and PRs, I usually create branches for my pull requests but this time the changes got out of hand in my master branch and had to do this. I apologize :/

@darionco
Copy link
Author

darionco commented Oct 9, 2015

Also, I am going to leave this here. I modified Colloquy's CQJavaScriptBridge to work on iOS, even using the built in JSC, take a look at the gist here:
https://gist.github.com/darionco/6d01f20d1c589944b484

Add it to your project and use it as follows:

#import "CQJavaScriptBridge.h"
...

/* get the js view */
EJJavaScriptView *jsView = (EJJavaScriptView*)self.view;
...

/* global Objective-C bridged classes */
[CQJavaScriptBridge addConstructorsInContext:jsView.jsGlobalContext forClassesArray:@[[[GKAchievement class] class], [MyCustomClass class]]];

At this point you can instantiate and use GKAchievement and MyCustomClass within JavaScript as follows:

/* this calls - (instancetype)initWithIdentifier:(nullable NSString *)identifier; */
var achievement = new GKAchievement("com.mygame.achievement");
/* this calls + (void)reportAchievements:(NSArray<GKAchievement *> *)achievements withCompletionHandler:(void(^ __nullable)(NSError * __nullable error))completionHandler; */
/* please note that blocks are not supported by the bridge */
GKAchiemevent.reportAchievements([achievement], null);

/* custom classes work exactly the same */
var customClass = new MyCustomClass();

This class can be improved and if misused, very dangerous. So beware.

@phoboslab
Copy link
Owner

So, I just downloaded the XCode 7.1 Beta and tried to compile for tvOS, but can't because I don't have a provisioning profile. Do I really need a real tvOS device to check if compiling works?

@darionco
Copy link
Author

hmm. not sure. But you should be able to compile and test on the simulator.

@darionco
Copy link
Author

I am working on getting JavaScriptCore for tvOS, which is not a problem now but will be in the future... I am also going to test if the built in JSC can be used instead of having tu bundle our own version every time.

@phoboslab
Copy link
Owner

Well, XCode says I need a provisioning profile for a tvOS device - which I can only create if I have a UDID for it, I believe. Send me yours, maybe? :)

Regarding JSC: Ejecta still can't use the built-in version because it has no API to read/write TypedArrays. See https://bugs.webkit.org/show_bug.cgi?id=120112

@williammalone
Copy link

I am able to run on the tvOS Simulator without a provisioning profile by changing the Team to None under General project settings.

@phoboslab
Copy link
Owner

Thanks @williammalone, this works!

However, I still can't compile:
target 'Ejecta' has bitcode disabled (ENABLE_BITCODE = NO), but it is required for the 'appletvos' platform

So, this means we would either need to compile JavaScriptCore with bitcode enabled (which I would guess is a nightmare) or use the JSC version provided by the OS and lose the Typed Array API, which would make WebGL and some Canvas2D stuff unbearably slow :/

Thoughts?

@darionco
Copy link
Author

I have compiled JSC with bitcode enabled and added iOS 9 compatibility. See PR
phoboslab/JavaScriptCore-iOS#30

I can upload the compiled version somewhere if you wish (since it takes about 30 min to compile)

Also, this same PR has the bitcode flag enabled for Ejecta.

@phoboslab
Copy link
Owner

Oh, wow! I'm sorry I missed that. I'll have a look – probably merge it into my repo tomorrow.

Thank you!

@homma-ge
Copy link

Great work! Thank you.

@phoboslab
Copy link
Owner

@darionco I merged your JSC pr (phoboslab/JavaScriptCore-iOS#30)

I'm almost able to compile this now for tvOS (added a bunch of #ifdefs similar to this PR), but the linker still complains: ld: in ../Ejecta/Source/lib/JavaScriptCore.framework/JavaScriptCore(JSObjectRef.o), building for tvOS, but linking in object file built for iOS, for architecture arm64

Any ideas?

@darionco
Copy link
Author

Yeah I get a lot of those, but they are warnings that state that they will become errors in the future... maybe the future is now? :)

I am using Xcode Version 7.1 beta (7B75), is yours different?

@phoboslab
Copy link
Owner

Well, it's an error for me. Version 7.1 beta 3 (7B85) :/

@darionco
Copy link
Author

The solution for this is to create a tvOS target in JSC and compile it for it. I can take a look at this later on today if you want.

@williammalone
Copy link

I am experiencing the same error. Version 7.1 Beta 3 (7B85).

@darionco
Copy link
Author

Ok I have added tvOS support to JSC in PR phoboslab/JavaScriptCore-iOS#31

Tested with the newest Xcode and AppleTV firmware. Let me know if it works for you.

phoboslab added a commit that referenced this pull request Oct 14, 2015
@phoboslab
Copy link
Owner

So, the above commit includes a separate JSC Framework, compiled for tvOS, adds a new build target for tvOS devices and omits building some APIs (e.g. devicemotion) that are not available on tvOS. Compilation for tvOS works now!

I'm leaving this issue open, since the input events for the AppleTV remote are not yet included. I'll use this PR as a guide.

Thanks again @darionco!

Dario Segura added 2 commits October 14, 2015 20:47
Conflicts:
	Source/Ejecta/EJBindingEjectaCore.m
	Source/Ejecta/EJCanvas/EAGLView.m
	Source/Ejecta/EJUtils/EJBindingAdBanner.h
	Source/Ejecta/EJUtils/EJBindingAdBanner.m
	Source/Ejecta/EJUtils/EJBindingDeviceMotion.h
	Source/Ejecta/EJUtils/EJBindingDeviceMotion.m
	Source/Ejecta/EJUtils/EJBindingGameCenter.m
	Source/Ejecta/EJUtils/EJBindingImagePicker.h
	Source/Ejecta/EJUtils/EJBindingImagePicker.m
@darionco
Copy link
Author

I am closing this pull request as this is my main dev branch and will get cluttered with unnecessary commits fast. I will, however, open another pull request once I am happy with the tvOS input changes.

@darionco darionco closed this Oct 20, 2015
@williammalone
Copy link

I am experiencing an with error with the new tvOS JSC Framework when trying to archive in Xcode:

ld: bitcode bundle could not be generated because '.../Source/lib/tvos/JavaScriptCore.framework/JavaScriptCore(JSObjectRef.o)' was built without full bitcode. All object files and libraries for bitcode must be generated from Xcode Archive or Install build for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

It works great both on the Apple TV Simulator and on the Apple TV. Anyone else experiencing this error when archiving?

@phoboslab
Copy link
Owner

Fixed in 4d44b74

ejecta-tvos

:)

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.

4 participants