electron/browser/api/lib/ipc.coffee
Cheng Zhao ef5a4b5fe0 Pass synchronous messages by JSON string.
We are going to use IPC_MESSAGE_HANDLER_DELAY_REPLY to handle
synchronous messages but DictionaryValue is not copyable, so we pass the
JSON string instead.
2013-09-20 22:32:59 +08:00

33 lines
1 KiB
CoffeeScript

EventEmitter = require('events').EventEmitter
send = process.atomBinding('ipc').send
sendWrap = (channel, processId, routingId, args...) ->
BrowserWindow = require 'browser-window'
if processId?.constructor is BrowserWindow
window = processId
processId = window.getProcessId()
routingId = window.getRoutingId()
send channel, processId, routingId, args...
class Ipc extends EventEmitter
constructor: ->
process.on 'ATOM_INTERNAL_MESSAGE', (args...) =>
@emit(args...)
process.on 'ATOM_INTERNAL_MESSAGE_SYNC', (channel, event, args...) =>
returnValue = 'null'
get = -> returnValue
set = (value) -> returnValue = JSON.stringify(value)
Object.defineProperty event, 'returnValue', {get, set}
Object.defineProperty event, 'result', {get, set}
@emit(channel, event, args...)
send: (processId, routingId, args...) ->
@sendChannel(processId, routingId, 'message', args...)
sendChannel: (args...) ->
sendWrap('ATOM_INTERNAL_MESSAGE', args...)
module.exports = new Ipc