Skip to content

Instantly share code, notes, and snippets.

@martinstannard
Created August 19, 2014 04:38
Show Gist options
  • Save martinstannard/2c633b92854984b0fcb3 to your computer and use it in GitHub Desktop.
Save martinstannard/2c633b92854984b0fcb3 to your computer and use it in GitHub Desktop.
ember.js phoenix framework channel
# ember-cli
# chat router
`import Ember from 'ember'`
ChatRoute = Ember.Route.extend
setupController: (controller, model)->
@_super(controller, model)
console.log "ChatRoute setupController"
socket = new Phoenix.Socket("ws://localhost:4000/ws")
socket.join("rooms", "lobby", {}, (chan) =>
controller.set('channel', chan)
chan.on('joined', (message) =>
console.log "joined [#{message}]"
)
chan.on('words', (words) =>
console.log "word_list [#{words}]"
controller.set('words', JSON.parse(words))
)
)
`export default ChatRoute`
# chat controller
`import Ember from 'ember'`
ChatController = Ember.Controller.extend
words: []
actions:
getWords: ->
channel = @get('channel')
channel.send('word_list', '')
answer: (word) ->
console.log "answer #{word}"
`export default ChatController`
# add phoenix.js to vendor/phoenix/phoenix.js
# Brocfile.js
/* global require, module */
var EmberApp = require('ember-cli/lib/broccoli/ember-app');
var app = new EmberApp();
// Use `app.import` to add additional libraries to the generated
// output files.
//
// If you need to use different assets in different
// environments, specify an object as the first parameter. That
// object's keys should be the environment name and the values
// should be the asset to use in that environment.
//
// If the library that you are including contains AMD or ES6
// modules that you would like to import into your application
// please specify an object with the list of modules as keys
// along with the exports of each module as its value.
app.import('vendor/phoenix/phoenix.js')
//app.import('vendor/semantic/build/packaged/css/semantic.min.css');
//app.import('vendor/semantic/build/packaged/javascript/semantic.min.js');
module.exports = app.toTree();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment