Instances of the InstantMessagingFlowclass represent an instant message (IM) media flow. The InstantMessagingFlowclass is derived from the MediaFlowbase 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 InstantMessagingFlowclass exposes a LocalComposingStateproperty to represent the local composing state. Setting the LocalComposingStateproperty to Composingcauses 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 LocalComposingStateto Idle. When the user sends the instant message, the platform stops sending typing notifications and automatically sets the value of LocalComposingStateto Idle.
The InstantMessageFlowclass raises a RemoteComposingStateChangedevent 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 LocalComposingStateproperty for an endpoint does not raise the RemoteComposingStateChangedevent on the remote participant. For this reason, and because typing notifications are sent every five seconds, if the RemoteComposingStateChangedevent 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.
Copy Code | |
---|---|
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; |