Skip to content

OpenIM SDK of Unity,to develop IM of game quickly(Developing)

License

Notifications You must be signed in to change notification settings

openimsdk/open-im-sdk-unity

Repository files navigation

Unity Client 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 💻

Adding Unity Package

  1. Add SDK package via git url
https://github.com/openimsdk/open-im-sdk-unity.git

Usage 🚀

The following examples demonstrate how to use the SDK.

Importing the SDK and initialize

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

Initialize

var config = new IMConfig()
{
    PlatformID = (int)PlatformID.WindowsPlatformID,
    ApiAddr = apiAddr,
    WsAddr = wsAddr,
    DataDir = Path.Combine(Application.persistentDataPath, "OpenIM"),
    LogLevel = (int)LogLevel.Debug,
    IsLogStandardOutput = true,
    LogFilePath = Path.Combine(Application.persistentDataPath, "OpenIM/Logs"),
    IsExternalExtensions = false,
};
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-unity-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

OpenIM SDK of Unity,to develop IM of game quickly(Developing)

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages