Skip to content

Conversation

@nqthqn
Copy link
Member

@nqthqn nqthqn commented Oct 2, 2018

No description provided.

I tested the JavaScript code in the Chrome debugging console.

Next: encoder/decoder for the messages sent back and forth.
@billstclair
Copy link
Collaborator

billstclair commented Oct 2, 2018

I hope this helps. Would you like me to write some Elm code to talk to it? That will probably be in the form of a Message type, with converters back and forth to the wire form: { tag: String, { key: String, message: String } }. But it could just keep everything close to the wire, and use if/then/else on the tag instead of case on a Message.

@nqthqn
Copy link
Member Author

nqthqn commented Oct 2, 2018

@billstclair this is a great contribution. we need to support votes for a question choice. I'm thinking the data shape might be something like:

type alias Model =
    { path : String
    , questions : SelectList Question
    }

type alias Question = 
    { text : String
    , choices : Array (String, VoteCount)
    , correct : List ChoiceIndex
    }

type alias VoteCount = Int
type alias ChoiceIndex = Int

Although it's not perfect — you could have a ChoiceIndex that is out of range (invalid state).

SelectList from https://package.elm-lang.org/packages/rtfeldman/selectlist/latest/SelectList

@billstclair
Copy link
Collaborator

billstclair commented Oct 2, 2018

You can get rid of the invalid state fairly easily:

type alias Question =
    { text : String
    , choices : Array (String, IsCorrect, VoteCount)
    }

type alias IsCorrect = Bool

But my question was about the low-level interface to the WebSocket ports. That will support strings out and strings in. It will need another layer that supports whatever protocol is required by FireBase. Maybe that whole thing belongs in a separate file.

@billstclair
Copy link
Collaborator

Well, that's what I get for not looking at Firebase docs before writing WebSocket code. We're going to want to program against the Firebase API, and it will do the WebSocket stuff for us. Duh. Looking at that now. Please don't merge this branch. It's going to change a lot.

@nqthqn
Copy link
Member Author

nqthqn commented Oct 3, 2018

Allow me to think out loud here.

type alias Model =
    { questionsGroupSlug : String
    , questions : SelectList Question
    }

type alias Question =
    { text : String
    , choices : Array Choice
    }

type alias Choice = 
    { text: String
    , correct: Bool
    , votes: Int
    }

So a browser would connect to /:questionsGroupSlug and figure out what question the presenter was displaying via a WebSocket ("hey! i joined the poll, whats the current question?")

They can then select a choice, and the application would go into a read only state (unless they refresh? not sure how to prevent duplicate voting) and they would see the screen update with everyones votes coming in.

When a response comes in (a choice index), we look at the currently selected question in the SelectList and increment the votes in the Choice at that array index.

When the presenter choses to advance the slide (from /admin, let's say) a message goes out to all connected clients and they advance their slide.

That's what I've got so far. I'm going to start on this data model and UI tonight.

@billstclair
Copy link
Collaborator

I had to drive an hour from home to give my daughter a ride to her community college class. I'm in the library there for another 2.5 hours, then 1.5 hour drive back home. I'm going to do my paid work, so nothing on this until the afternoon, or early evening. I still don't know how you plan to use Firebase to provide storage for this. Maybe you don't either, except that it should be possible.

@nqthqn
Copy link
Member Author

nqthqn commented Oct 3, 2018

Maybe you don't either, except that it should be possible.

Yep

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