Skip to content
Snippets Groups Projects
Select Git revision
  • master
1 result

app.coffee

Blame
  • app.coffee 1.24 KiB
    #requirejs = require "requirejs"
    
    SallyClient = require('./sally_client').SallyClient
    gui = require('nw.gui');
    
    stomp_args =
      port : 61613,
      host: 'localhost',
      login: 'karaf',
      passcode: 'karaf',
    #  debug: true,
    
    uniqueId = (length=8) ->
      id = ""
      id += Math.random().toString(36).substr(2) while id.length < length
      id.substr 0, length
    
    wind = {}
    sally = null
    
    handler = (body, msg, sendBack) =>
      if body.CloseTheoWindow?
        wndID = body.CloseTheoWindow.id
        wind[wndID].close()
    
      if body.OpenTheoWindowRequest?
        winID = uniqueId();
        newWin = createNewWindow(body.OpenTheoWindowRequest)
        wind[winID] = newWin
        sendBack(
        	"OpenTheoWindowResponse" :
        		"$" : { "xmlns" : "http://kwarc.info/sally/comm/theo" },
        		"id" : winID
        )
    
    
    createNewWindow = (body) ->
    	ops = {
    		position: 'center',
    		x : parseInt(body.posx[0]),
    		y : parseInt(body.posy[0]),
    		width: parseInt(body.width[0]),
    		height: parseInt(body.height[0]),
    	}
    	new_win = gui.Window.open(body.url[0], ops);
    	new_win.setAlwaysOnTop(true);
    
    	return new_win
    
    #requirejs ["sally_client"], (SallyClient) ->
    sally = new SallyClient stomp_args, handler
    sally.connect ["theo"], (body, msg)->
      console.log("connected ");
    
    
    #process.on 'SIGINT', () ->
    #  client.disconnect()