# Presentation: 199620

## Writing Shared Applications

## Shared Applications

- Goal : Enable collaborative work
- Requirements
- Coherence (identical state across application peers)
- Secure storage of application state
- Secure communication of state changes among users
- Details
- Shared application clients are associated to sessions using mimetypes
- Shared application clients are launched by the venue client
- API provided for developers to implement shared applications

## Shared Application internals

- Application is represented in Venue as an Application Object
- Application Object includes (limited) storage and event channel

- Data

- Venue

- App

- Event
- Channel

## Shared Application internals

- Shared Application client communicates with Application Object via SOAP
- Shared Application’s EventClient communicates with Venue EventChannel (and thereby with application peers) via TCP

- Data

- Venue

- App

- Event
- Channel

- Event
- Client

- Shared
- App
- Client

## Application Object interface

- Startup
- Join() : (publicId,privateId)Registers the caller as an application peer; returns privateId, which is required for subsequent calls to Application Object
- GetDataChannel(privateId) : (channelId, location)Get data channel location and channel; necessary to connect to channel to receive events
- Operation
- SetData(privateId, key, value)Create an entry in the application data storage with specified key and value
- GetData(privateId, key) : valueRetrieve the value with specified key from the application data storage
- Termination
- Leave(privateId)Unregisters the peer

## EventClient interface

- Startup
- EventClient(privateId, eventServiceLoc, channelId)Create an event client connected to the specified channel
- RegisterCallback(userDefinedEventType, callback)Register a callback for the specified event type
- Operation
- Send(oEvent)Send an event to application peers (Event class defined in toolkit)

## Typical application startup

- Data

- Venue

- App

- Event
- Channel

- Venue Client

- Shared App
- Client

- Application
- Object URL

- Startup calls

- VenueClient executes the shared application, passing it the URL of the application object in the venue
- Shared App client communicates with Application Object to synch with shared application state

## Shared App – Startup Calls

- Data

- Venue

- App

- Event
- Channel

- Venue Client

- Shared App
- Client

- Application
- Object URL

- Startup calls

- Call ApplicationObject.Join Register as an application peer
- Call ApplicationObject.GetDataChannelGet info for connecting to event channel
- Call EventClient constructorCreate event client to send/receive events
- Call EventClient.RegisterCallbackRegister callbacks for particular event types
- Call ApplicationObject.GetDataRetrieve current application state to sync with existing peers

## Shared App Operation

- When changed, application state is:
- Stored in the application object data storage
- Distributed to application peers

- Data

- Venue

- App

- Event
- Channel

## Shared App – Operational Calls

- Data

- Venue

- App

- Event
- Channel

- When a shared app client changes the application state:
- Call ApplicationObject.SetDataStore the change to application state in the application object
- Call EventClient.SendDistribute the event to application peers

## Example Shared Applications

## Generic Shared Application

- A simple example:  Editing a shared text buffer
- State: text
- State changes: updates to text
- (How simple? 140 lines of code)
- Intended as a boilerplate for shared apps

## Shared Text Buffer

- When Send button is pressed, text is:
- Stored in the application object data storage via SetData(privateId,“data”,text)
- Distributed to application peers via eventClient.Send(...)

- Data

- Venue

- App

- Event
- Channel

## Shared Text Buffer

- When a peer joins the application, it reads the application state (via GetData() ) from the application object to synch with existing peers

- Data

- Venue

- App

- Event
- Channel

## Shared Web Browser

- Application task: Web browsing
- Goal: All users see the same page
- Application state: webpage URL
- Lines of code for example:  285
- Currently unsupported example code; needs update for 2.1
- Code in CVS

## Shared Browser

- When one peer browses to a new URL, the URL is:
- stored in the application data storage
- distributed to application peers

- Data

- Venue

- App

- Event
- Channel

## Shared Presentation

- Application task: *coordinated display of presentation material*
- Anyone in the venue can participate in a Shared Presentation
- There is only one Master who can send valid events
- Usually the speaker (but not always)
- Application state
- A *presentation* (set of slides / images / pages)
- Current *slide number* within the presentation
- Current *step number* within a slide
- A *presenter* who has control of progress through the presentation

## Control Interface

- The Control Interface is a substitute for the actual controls on the Viewer
- It provides basic functionality for:
- Taking control
- Next
- Previous
- Go To Slide #
- Load presentation
- Quit

**Notes:**
Open Code in Editor on Other Screen!

## Design

- Three primary components:
- Viewer (COM-connection to Powerpoint)
- EventClient
- User Interface
- EventClient and UI put messages in queue, and they get sent to the viewer.

## Shared Presentation

- Still, the interactions are the same.  When one peer causes a change to the state, it is:
- stored in the application data storage
- distributed to application peers

- Data

- Venue

- App

- Event
- Channel

- master
- slidesUrl
- slideNumber
- stepNumber

## Shared Presentation Work to Do

- Enable the Shared Presentation to retrieve presentations from the Virtual Venue
- Create a Linux Presentation Viewer