         throw new Error 'Method not found'
       return fn.apply null, params
 
-    if IS_FRAMED
+    if @isFramed
       frameError = null
       @validation
       .then =>


RPCClient = require './rpc_client'

IS_FRAMED = window.self isnt window.top
HANDSHAKE_TIMEOUT_MS = 10 * 1000 # 10 seconds

class PortalGun

    @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()
