Using an InstantMessaging Flow

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Instances of the InstantMessagingFlow class represent an instant message (IM) media flow. The InstantMessagingFlow class is derived from the MediaFlow base class and provides methods to send and receive IM messages, delivery notifications, and typing notifications.

Typing Notifications

A typing notification indicates whether a participant is actively composing a message. A typing notification is an INFO message that sent to the remote endpoint when the local participant is typing.

The InstantMessagingFlow class exposes a LocalComposingState property to represent the local composing state. Setting the LocalComposingState property to Composing causes the platform to automatically send typing notifications to the remote participant every five seconds. The platform stops sending typing notifications if the application explicitly sets the value of LocalComposingState to Idle. When the user sends the instant message, the platform stops sending typing notifications and automatically sets the value of LocalComposingState to Idle.

The InstantMessageFlow class raises a RemoteComposingStateChanged event to represent the composing state of the remote participant in an IM conversation. The event is raised only when the remote participant sends a typing notification; setting the LocalComposingState property for an endpoint does not raise the RemoteComposingStateChanged event on the remote participant. For this reason, and because typing notifications are sent every five seconds, if the RemoteComposingStateChanged event is not raised within six seconds, the application should assume that the remote participant is idle.

Creating and Manipulating an IM Media Flow

The following code demonstrates creating an IM media flow, sending IM messages on the flow, and sending typing notifications.

imCall.InstantMessagingFlowConfigurationRequested += IMCall_InstantMessagingFlowConfigurationRequested; // Must be done before Establish is called.

private void IMCall_InstantMessagingFlowConfigurationRequested (object sender, InstantMessagingFlowConfigurationRequestedEventArgs e)
{
  InstantMessagingFlow imFlow = e.Flow;
  imFlow.StateChanged += IMFlow_StateChanged;
  imFlow.RemoteComposingStateChanged += IMFlow_RemoteComposingStateChanged;
}

private void IMCall_ RemoteComposingStateChanged (object sender, ComposingStateChangedEventArgs e)
{
  // e.Participant indicates the remote participant.
  // e.ComposingState indicates the composing state of this remote participant.
}

private void IMCall_StateChanged(object sender, StateChangedEventArgs<MediaFlowState> e)
{
  // Idle, Active, Terminated are the states. 
  // If Active, the flow is ready to send and receive media.
}

// Send a message on the flow.
myFlow.BeginSendMessage(“hi”, IMFlow_SendMessageCompleted, myFlow);

// Sending a typing notification.
myFlow.LocalComposingState = ComposingState.Composing;

// Setting the composing state to Idle cancels the autmomatic sending of typing notifications.
// Sending the instant message also cancel the automatic sending of typing notifications.
myFlow.LocalComposingState = ComposingState.Idle;