1 |
|
2 |
|
3 |
|
4 |
|
5 | utils = require "./utils"
|
6 | utils.extend global, utils
|
7 |
|
8 | module.exports = (sock = config.sock) ->
|
9 |
|
10 |
|
11 |
|
12 | chromix:
|
13 | (path, request, extra_arguments...) ->
|
14 | extend request, {path}
|
15 | request.args ?= []
|
16 | callbacks = []
|
17 |
|
18 |
|
19 |
|
20 | for arg in extra_arguments
|
21 | (if typeof(arg) == "function" then callbacks else request.args).push arg
|
22 |
|
23 | client = require("net").connect sock, ->
|
24 | client.write JSON.stringify request
|
25 |
|
26 | client.on "data", (data) ->
|
27 | response = JSON.parse data.toString "utf8"
|
28 | if response.error
|
29 | console.error "error: #{response.error}"
|
30 | process.exit 1
|
31 | callback response.response... for callback in callbacks
|
32 | client.destroy()
|