Question: Best practice for CommandCenter -> ReactJS view comms? #1026

Closed
jaygarcia opened this Issue Apr 26, 2015 · 10 comments

Comments

Projects
None yet
4 participants
@jaygarcia
Contributor

jaygarcia commented Apr 26, 2015

I'm currently working on a Chiptunes mode player and am wiring in iOS CommandCenter. CommandCenter is responsible for listening to events from the home screen, bottom drawer, USB command inputs (car audio controllers, etc) and headphone remotes.

The wiring needs to be complete so that I can wire up events such as play, pause, next and previous track.

The current communication is as such:
CommandCenter -> ViewManager -> STOP

I'm having trouble figuring out how to publish events from the view manager to the view (there will only be one "Player" view ever.

Does anyone have any strategies to overcome this? Should I be thinking of app-level events?

Here's the command center hook if anyone's wondering:

    MCModPlayer *player = [MCModPlayer sharedManager];

    /** Remote control management**/
    MPRemoteCommandCenter *commandCenter = [MPRemoteCommandCenter sharedCommandCenter];


    [commandCenter.playCommand addTargetWithHandler:^MPRemoteCommandHandlerStatus(MPRemoteCommandEvent *event) {
        [player resume];

        NSLog(@"playCommand");

//        How does one emit an event to a view from the view controller (View Manager) when the VM doesn't know of a particular view?
//        [self.bridge.eventDispatcher sendInputEventWithName:@"topChange" body:body];

        return MPRemoteCommandHandlerStatusSuccess;
    }];
@nicklockwood

This comment has been minimized.

Show comment
Hide comment
@nicklockwood

nicklockwood Apr 26, 2015

Contributor

Take a look at the implementation for RCTWebView, which solves a similar problem.

Contributor

nicklockwood commented Apr 26, 2015

Take a look at the implementation for RCTWebView, which solves a similar problem.

@nicklockwood

This comment has been minimized.

Show comment
Hide comment
@nicklockwood

nicklockwood Apr 26, 2015

Contributor

Although, if your command center is a singelton, and doesn't have any UI of its own, should it perhaps just be a regular bridge module, rather than a view manager?

Contributor

nicklockwood commented Apr 26, 2015

Although, if your command center is a singelton, and doesn't have any UI of its own, should it perhaps just be a regular bridge module, rather than a view manager?

@nicklockwood

This comment has been minimized.

Show comment
Hide comment
@nicklockwood

nicklockwood Apr 26, 2015

Contributor

It sounds like your problem is more similar to something like RCTReachability, or RCTLocationObserver, where the native module just has methods and sends events, but has no view of its own.

Contributor

nicklockwood commented Apr 26, 2015

It sounds like your problem is more similar to something like RCTReachability, or RCTLocationObserver, where the native module just has methods and sends events, but has no view of its own.

@jaygarcia

This comment has been minimized.

Show comment
Hide comment
@jaygarcia

jaygarcia Apr 26, 2015

Contributor

I started down that route but could not figure out how to inform the Ui of a state change. :-/

Reading through the source, I found that the only way to go from bridge > view is to route events via react tag.

I'm a newb.

JG

@moduscreate

:: sent from my mobile device ::

On Apr 26, 2015, at 09:35, Nick Lockwood notifications@github.com wrote:

Although, if your command center is a singelton, and doesn't have any UI of its own, should it perhaps just be a regular bridge module, rather than a view manager?


Reply to this email directly or view it on GitHub.

Contributor

jaygarcia commented Apr 26, 2015

I started down that route but could not figure out how to inform the Ui of a state change. :-/

Reading through the source, I found that the only way to go from bridge > view is to route events via react tag.

I'm a newb.

JG

@moduscreate

:: sent from my mobile device ::

On Apr 26, 2015, at 09:35, Nick Lockwood notifications@github.com wrote:

Although, if your command center is a singelton, and doesn't have any UI of its own, should it perhaps just be a regular bridge module, rather than a view manager?


Reply to this email directly or view it on GitHub.

@jaygarcia

This comment has been minimized.

Show comment
Hide comment
@jaygarcia

jaygarcia Apr 26, 2015

Contributor

I have not looked at that source. I will after I get home. :)

Many thanks. You guys flipping own for working on the weekends.

JG

@moduscreate

:: sent from my mobile device ::

On Apr 26, 2015, at 09:42, Nick Lockwood notifications@github.com wrote:

It sounds like your problem is more similar to something like RCTReachability, or RCTLocationObserver, where the native module just has methods and sends events, but has no view of its own.


Reply to this email directly or view it on GitHub.

Contributor

jaygarcia commented Apr 26, 2015

I have not looked at that source. I will after I get home. :)

Many thanks. You guys flipping own for working on the weekends.

JG

@moduscreate

:: sent from my mobile device ::

On Apr 26, 2015, at 09:42, Nick Lockwood notifications@github.com wrote:

It sounds like your problem is more similar to something like RCTReachability, or RCTLocationObserver, where the native module just has methods and sends events, but has no view of its own.


Reply to this email directly or view it on GitHub.

@jaygarcia

This comment has been minimized.

Show comment
Hide comment
@jaygarcia

jaygarcia Apr 26, 2015

Contributor

@nicklockwood !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

You effing nailed it dude! Thank you so much.

Contributor

jaygarcia commented Apr 26, 2015

@nicklockwood !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

You effing nailed it dude! Thank you so much.

@jaygarcia jaygarcia closed this Apr 26, 2015

@jaygarcia

This comment has been minimized.

Show comment
Hide comment
@jaygarcia

jaygarcia Apr 26, 2015

Contributor

For those interested, here's the product of this effort:

https://www.youtube.com/watch?v=VaZnJ-_R3rU

Contributor

jaygarcia commented Apr 26, 2015

For those interested, here's the product of this effort:

https://www.youtube.com/watch?v=VaZnJ-_R3rU

@sahrens

This comment has been minimized.

Show comment
Hide comment
@sahrens

sahrens Apr 26, 2015

Contributor

Did you use an event emitter?

On Apr 26, 2015, at 11:35 AM, Jay Garcia notifications@github.com wrote:

For those interested, here's the product of this effort:

https://www.youtube.com/watch?v=VaZnJ-_R3rU


Reply to this email directly or view it on GitHub.

Contributor

sahrens commented Apr 26, 2015

Did you use an event emitter?

On Apr 26, 2015, at 11:35 AM, Jay Garcia notifications@github.com wrote:

For those interested, here's the product of this effort:

https://www.youtube.com/watch?v=VaZnJ-_R3rU


Reply to this email directly or view it on GitHub.

@jaygarcia

This comment has been minimized.

Show comment
Hide comment
@jaygarcia

jaygarcia Apr 28, 2015

Contributor

@sahrens eventDispatcher. It's working like a friggin champ.

 [commandCenter.previousTrackCommand addTargetWithHandler:^MPRemoteCommandHandlerStatus(MPRemoteCommandEvent *event) {
        //TODO: Handle previous track (have no idea what to do here atm);
        NSLog(@"previousTrackCommand");

       [_bridge.eventDispatcher sendDeviceEventWithName:@"commandCenterEvent" body:@{
            @"eventType" : @"previousTrack"
        }];
        return MPRemoteCommandHandlerStatusSuccess;
    }];
Contributor

jaygarcia commented Apr 28, 2015

@sahrens eventDispatcher. It's working like a friggin champ.

 [commandCenter.previousTrackCommand addTargetWithHandler:^MPRemoteCommandHandlerStatus(MPRemoteCommandEvent *event) {
        //TODO: Handle previous track (have no idea what to do here atm);
        NSLog(@"previousTrackCommand");

       [_bridge.eventDispatcher sendDeviceEventWithName:@"commandCenterEvent" body:@{
            @"eventType" : @"previousTrack"
        }];
        return MPRemoteCommandHandlerStatusSuccess;
    }];
@brentvatne

This comment has been minimized.

Show comment
Hide comment
@brentvatne

brentvatne Apr 28, 2015

Collaborator

@jaygarcia - how about publishing a library that exposes this functionality to JS?

Collaborator

brentvatne commented Apr 28, 2015

@jaygarcia - how about publishing a library that exposes this functionality to JS?

@facebook facebook locked as resolved and limited conversation to collaborators May 29, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.