Table of Contents
Just a second...

diffusion-wrapper.js

The Diffusion™ wrapper is a script which addresses a weakness in the Flash® and Silverlight® VMs – when running inside a web browser there is no provision for the execution of callback code when the user closes either the containing tab or the entire browser window.

Consequently there is no opportunity for the Diffusion client to inform the server that the client is willingly closing the connection, instead the connection is severed. This can result in various server warnings (dependent on the transport mechanism, that is DPT or HTTP) as well as maintaining the server-side reference to the client if any reconnection timeout is specified.

The JavaScript® environment in the hosting browser provides browser closing callbacks, and these are employed by DiffusionWrapper.js. By supplying the setClientDetails function with client and server info after a connection has been established within the Flash or Silverlight API, DiffusionWrapper attaches a JavaScript function to the onbeforeunload event that is triggered when a browser window or tab closes. This notifies Diffusion that the client is deliberately closing.

diffusion-wrapper.js can be found in clients/flex and clients/silverlight directories from a default installation.

Figure 1. Diffusion wrapper
Inside a browser is a diffusion-wrapper.js file and an embedded Silverlight or Flex application. Both communicate with the Diffusion server.

The preceding diagram shows diffusion-wrapper.js in use. When the user closes the containing browser tab or window, the following events occur:
  1. The user closes the browser. This engages a JavaScript callback that calls diffusion-wrapper.js.
  2. diffusion-wrapper.js runs and sends a closure request to the Diffusion server.
  3. The Flash or Silverlight client dies. It has no chance to run cleanup code.