         getClientConfig : @getClientConfig
     @rpc
 
-  loadError       : (err)=>
+  loadError: (err)=>
     window.clearTimeout @timeout
     @_ready.reject err
 
-  loadingFailed   : (err) =>
-    @_ready.reject('Remote loading has failed. Please check "orgUrl" and "appId" in your configuration. This may also be about connectivity.')
+  loadingFailed: (err) =>
+    @rpc.destroy()
+    if @retryCount < 10
+      @startRpc()
+    else
+      @_ready.reject(new Error('Remote loading has failed. Please check "orgUrl" and "appId" in your configuration. This may also be about connectivity.'))
 
   onMessage       : (e)->
     if e.error then @_ready.reject(e.error) else logger.log("RPC Message", arguments)

    @promise = new Promise (resolve, reject)=>
      @_ready.resolve = resolve
      @_ready.reject = reject
    domready(@onDomReady)

  onDomReady : ()=>
    @timeout = setTimeout(@loadingFailed, 60000);
    @rpc = new xdm.Rpc
      remote    : @currentConfig.getRemoteUrl()
      container : document.body

    overflow: 'hidden'

class Channel

  constructor : (currentUser, currentConfig)->
    @retryCount = 0
    @currentConfig = currentConfig
    @currentUser = currentUser
    @timeout  = null
