swizi-chat-sdk v2.0.3
Swizi chat SDK
This SDK allows to use Swizi Chat in your application. With this SDK you can connect to Chat Server with a end user, retrieve channels and other users, receive an send messages. This SDK is based on socket.io and is fully integrated with Swizi. It is possible to use it to chat with mobile apps generated with Swizi or with other software using this SDK.
Summary
Breaking change
Since v1.2, ChatProxy is no more used. If no server is provided the default server used is https://api.chat.swizi.io
onDebug callback is no more used. To catch debug event, use on('debug', cb)
Message Type is now of two type : TEXT or MEDIA. MEDIA can be
Installation
npm i swizi-chat-sdk
or
yarn add swizi-chat-sdk
Note that a ReactJS is also available. See https://www.npmjs.com/package/react-swizi-chat
Usage
To use the SDK you need to things :
- An API key to connect to chat server. This API key is provided with your Swizi Subscription.
- The chat user identification
The user identification can be included in a token provided by Swizi (for exemple if your are in a Swizi mobile App) or it can be an ID provided by the Chat Service API.
The sequence to connect to a server is :
- Create the ChatClient with server informations,
- Configure the ChatClient with user informations and set the callback to get events,
- Connect to server.
When the client is connected and authentified, events are sent to the callback and it is possible to send new messages with the postMessage method. See Events section to know all possible events.
Below a basic usage of ChatClient :
import ChatClient from 'SwiziChatClient'
let client = new ChatClient('https://api.chat.swizi.io')
client.configure('your user id', 'your api key')
client.on(ChatClient.EventType.AUTHENTIFIED, () => console.log("Ok I'm connected and authentified !"))
client.on(ChatClient.EventType.DEBUG, msg => console.debug(msg))
client.connect()
Events
Events are sent to callbacks when something happens on a channel. The callback function must contains two parameters : event and data.
Below are the events :
Event | Explanation | |
---|---|---|
ChatClient.EventType.CONFIGURED | Chat client configuration is done | empty |
ChatClient.EventType.CONNECTED | Chat client is connected to server | empty |
ChatClient.EventType.FAILED | Connexion to chat server failed | Error code |
ChatClient.EventType.AUTHENTIFIED | User is allowed by server and can start to chat | empty |
ChatClient.EventType.UNAUTHORIZED | User is not allowed to use this chat server with this API Key | |
ChatClient.EventType.LOADED | All rooms are loaded | empty |
ChatClient.EventType.DISCONNECTED | Chat client is no more connected | empty |
ChatClient.EventType.ROOM_UPDATED | Answer to a "Update room" is arrived | empty |
ChatClient.EventType.NEW_MESSAGE | A new message is arrived | roomId |
ChatClient.EventType.USER_INFO_UPDATED | Answer to 'User Info' request is arrived | User infos |
ChatClient.EventType.USER_ANSWERING_STATUS_CHANGED | A user has sent a message to notify he is starting or ending writing a message | |
ChatClient.EventType.USER_LIST_RECEIVED | Answer to "askForUsers" request is arrived | Users list |
ChatClient.EventType.NEW_ROOM_AVAILABLE | A new room has been created for this user | Room information |
ChatClient.EventType.USER_LIST_IN_PROGRESS | askForUsers request is running | |
ChatClient.EventType.USER_LIST_FAILED | askForUsers request failed | |
ChatClient.EventType.REQUESTED_ROOM_CREATED | Requested new room was created | |
ChatClient.EventType.DEBUG | Debug message is available | |
ChatClient.EventType.LIKE_CHANGED | A like counter changed on a message |
API
API Documentation is available here : https://ms-desk.swizi.io/doc/Chat_Client_SDK_for_JS/
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago