Having a direct chat between two people is very easy to configure with the SDK. The key is to ensure that a standard channelId
is set between two pairs of users.
The channelId
is unique and immutable to the channel. We need to make sure the same pair of users always produces the same channelId
. To to this, we will write a simple function that takes in two userId
parameters and returns a string that will be the channelId
. The logic for generating the string should be commutative, meaning that the pair of userId
parameters can be given in any order, it will still return the same hash.
function generateChannelId(userA, userB) {return 'directchat-' + min(userA, userB) + '-' + max(userA, userB);}​const channelId = generateChannelId('alice', 'bob');// channelId will be 'directchat-alice-bob', regardless of if 'alice' is first parameter or 'bob' is first parameter.
This channelId
can then be passed to a join()
or create()
method to fetch the final direct chat channel.
For more details on how to create
EkoChannel
: iOS, Android and Web​
After the EkoChannel
is successfully created, we can send a message to the EkoChannel
by using EkoMessageRepository
For more details on how to send
EkoMessage
: iOS, Android and Web​