 
 RPCClient = require './rpc_client'
 
-IS_FRAMED = window.self isnt window.top
 HANDSHAKE_TIMEOUT_MS = 10 * 1000 # 10 seconds
 
 class PortalGun

        throw new Error 'Method not found'
      return fn.apply null, params

    if IS_FRAMED
      frameError = null
      @validation
      .then =>

    @isParentValidFn ?= -> true
    timeout ?= null
    @isListening = false
    @isFramed = window.self isnt window.top
    @parent = window.parent

    @client = new RPCClient({
      timeout: timeout
      postMessage: (msg, origin) =>
        @parent?.postMessage msg, origin
    })
    # All parents must respond to 'ping' with 'pong'
    @registeredMethods = {
      ping: -> 'pong'
    }

  setParent: (parent) =>
    @parent = parent
    @isFramed = true

  # Binds global message listener
  # Must be called before .call()
