Sending a Signal
Now that you have connected to the session and have a session object, you can now send a Signal. Signals are arbitrary text or data that are sent in a session which can be sent to a specific client or all connected clients. You can learn more about them in the Vonage Video Signaling developer guide. For this tutorial you will be sending text.
- Create a new class called
SignalMessagewith this code:
This class will be used to show the Signals in the UI.
- Copy the following code and paste it below the existing code in your
MainActivityclass after theonCreatefunction:
This code adds a function that will be called from the UI. session.signal is called to send the text as a Signal. session.signal takes the type of Signal and some data. The type is optional but can be used to differentiate between types of Signals in your app. If the Signal sends successfully, it is added to the array of messages that the UI is using.
- In the
MainActivityclass, update the end of theonCreatefunction to add a listener to theEditTextViewwhich uses thesendMessagefunction:
When the EditTextView emits a done action, the sendMessage function will be called. Now time to update the UI:
- Open the
activity_main.xmllayout file (res > layout). - Open the code view.
- Copy this XML over the existing layout:
- Create a new layout file called
message_single_local.xmlwith this XML:
- Duplicate the
message_single_local.xml, call itmessage_single_remote.xml, and change the gravity tostart. - Add an adapter for the message history
ListView, create a class calledSignalMessageAdapterwith this code:
Adapters are used to populate views in a ListView, this defines a custom one for the Signals. Make sure to import any classes that are needed.
Basic text chat
Follow this tutorial to build basic text chat from scratch using the Vonage Video API. It is the quickest way to build a proof of concept for this functionality on the video platform.