Skip to content

openimsdk/open-im-sdk-dotnet

Repository files navigation

Dotnet SDK for OpenIM 👨‍💻💬

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.

Documentation 📚

Visit https://docs.openim.io/ for detailed documentation and guides.

For the SDK reference, see https://docs.openim.io/sdks/quickstart/unity.

Installation 💻

Add Pacakge

dotnet add package open-im-sdk --version 1.0.2

dotnet pack

dotnet pack open-im-sdk.csproj --configuration Release

Usage 🚀

The following examples demonstrate how to use the SDK.

Importing the SDK and initialize

using OpenIM.IMSDK;
using OpenIM.IMSDK.Listener;

Initialize

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());

Set Listener

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)

Login

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();
}

Logout

// 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.

Examples 🌟

You can find a demo that uses the SDK in the open-im-dotnet-demo repository.

Community 👥

Community Meetings 📆

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 📑.

Who are using OpenIM 👀

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.

License 📄

OpenIM is licensed under the Apache 2.0 license. See LICENSE for the full license text.

About

No description, website, or topics provided.

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages