Use this SDK to add instant messaging capabilities to your Unity Game. By connecting to a self-hosted OpenIM server, you can quickly integrate instant messaging capabilities into your app with just a few lines of code.
The underlying SDK core is implemented in openim-sdk-cpp.
Visit https://docs.openim.io/ for detailed documentation and guides.
For the SDK reference, see https://docs.openim.io/sdks/quickstart/unity.
dotnet add package open-im-sdk --version 1.0.2
dotnet pack open-im-sdk.csproj --configuration Release
The following examples demonstrate how to use the SDK.
using OpenIM.IMSDK;
using OpenIM.IMSDK.Listener;
var config = new IMConfig()
{
PlatformID = (int)PlatformID,
ApiAddr = Config.APIAddr,
WsAddr = Config.WsAddr,
DataDir = Path.Combine(AppContext.BaseDirectory, Config.DataDir),
LogLevel = Config.LogLevel,
IsLogStandardOutput = Config.IsLogStandardOutput,
LogFilePath = Path.Combine(AppContext.BaseDirectory, Config.LogFilePath),
IsExternalExtensions = Config.IsExternalExtensions,
};
var suc = IMSDK.InitSDK(config, new ConnListener());
Note1: You need to set up the listeners first and then log in.
IMSDK.SetConversationListener(IConversationListener l);
IMSDK.SetGroupListener(IGroupListener l);
IMSDK.SetFriendShipListener(IFriendShipListener l);
IMSDK.SetFriendShipListener(IFriendShipListener l);
IMSDK.SetAdvancedMsgListener(IAdvancedMsgListener l);
IMSDK.SetUserListener(IUserListener l);
IMSDK.SetBatchMsgListener(IBatchMsgListener l)
var status = IMSDK.GetLoginStatus();
if (status == LoginStatus.Empty || status == LoginStatus.Logout)
{
IMSDK.Login(userId, token, (suc, err, errMsg) =>
{
if (suc)
{
Debug.Log("Login UserId:" + IMSDK.GetLoginUserId());
GetData();
}
else
{
{
Debug.Log("Login Failed :" + errMsg);
}
}
});
}
else if (status == LoginStatus.Logged)
{
Debug.Log("Login UserId:" + IMSDK.GetLoginUserId());
GetData();
}
// Log out the currently logged in user
IMSDK.Logout((suc,err,errMsg)=>{
})
// exit sdk
IMSDK.UnInitSDK();
To log into the IM server, you need to create an account and obtain a user ID and token. Refer to the access token documentation for details.
You can find a demo that uses the SDK in the open-im-dotnet-demo repository.
We want anyone to get involved in our community and contributing code, we offer gifts and rewards, and we welcome you to join us every Thursday night.
Our conference is in the OpenIM Slack 🎯, then you can search the Open-IM-Server pipeline to join
We take notes of each biweekly meeting in GitHub discussions, Our historical meeting notes, as well as replays of the meetings are available at Google Docs 📑.
Check out our user case studies page for a list of the project users. Don't hesitate to leave a 📝comment and share your use case.
OpenIM is licensed under the Apache 2.0 license. See LICENSE for the full license text.