SLService instance require your Client model. If you won’t use it, you can simply declare an empty struct for that
struct Client: SLClient {}
let chat = SLService<Client>()
SLClient Protocol
Every function in this protocol is optional. It means SLClient provide default implementation. However, you are allowed to override it by your own. Why do that? To provide additional functionality. For example: data base storage for your message history, handle Data messages, provide recipients for status messages like connected or disconnected. And many more!
Sending message via sendMessage protocol method. Provide SLMessage object which hold recipients parsed from socket message. This can be chat room ids or simple client ids to which message should be delivered.
Recipients are strings defined by you. Thanks to that you can identify your target clients to which message should be delivered. They can be simple other clients id or room id.
SLService
Is very simple in the way it works. First of all what you should know is:
Message sent to clinet looks like:
M;MESSAGE-OWNER-ID;{MESSAGE-RECIPIENT-ID, CAN_BE_CHAT_ROOM_ID, CAN_BE_OTHER_CLIENT_ID};My message content sent to others
First character in this case M is the type of message. Followed by client id responsible for sending this message with recipients placed inside {} and the last part is message content. All parts joined by ;
This message model will be delivered to your client application.
``
Status messages (connected or disconnected) are different, they simply have empty recipient closure {}. If you receive message:
C;MESSAGE-OWNER-ID;{}; Simply all clients related with message owner should be notify.
Beside receiving messages, you will send some as well!
Your message should look like:
M{RECIPIENT_1;RECIPIENT_2;RECIPIENT_3}My message content sent to others
Similar to recived message, first character describe type of message. Followed by recipients places inside {} separated by ; with the last component is the message content.
To open socket conection from client register your WebSocket on:
ws:// + host + /slchat?OWNER-ID
SLChat uses path components to send owner id.
SLChat
SLChat is a simple extension for Kitura-WebSocket. Allows you to integrate chat system with your client.
🔧 Installation
Add the following dependency to your
Package.swift
file:💊 Usage
1 Import
It’s really easy to get started with the SLChat library! First you need to import the library, by adding this to the top of your Swift file:
2 Initialize
The easiest way to setup SLChat is to create object for example in your
main.swift
file. Like this:Perfectly works with Kitura.
3 Configure
SLService
instance require your Client model. If you won’t use it, you can simply declare an empty struct for thatSLClient Protocol
Every function in this protocol is optional. It means
SLClient
provide default implementation. However, you are allowed to override it by your own. Why do that? To provide additional functionality. For example: data base storage for your message history, handleData
messages, provide recipients for status messages like connected or disconnected. And many more!Sending message via
sendMessage
protocol method. ProvideSLMessage
object which hold recipients parsed from socket message. This can be chat room ids or simple client ids to which message should be delivered.Recipients are strings defined by you. Thanks to that you can identify your target clients to which message should be delivered. They can be simple other clients id or room id.
SLService
Is very simple in the way it works. First of all what you should know is: Message sent to clinet looks like:
M;MESSAGE-OWNER-ID;{MESSAGE-RECIPIENT-ID, CAN_BE_CHAT_ROOM_ID, CAN_BE_OTHER_CLIENT_ID};My message content sent to others
First character in this caseM
is the type of message. Followed by client id responsible for sending this message with recipients placed inside{}
and the last part is message content. All parts joined by;
This message model will be delivered to your client application. ``Status messages (connected or disconnected) are different, they simply have empty recipient closure
{}
. If you receive message:C;MESSAGE-OWNER-ID;{};
Simply all clients related with message owner should be notify.Beside receiving messages, you will send some as well! Your message should look like:
M{RECIPIENT_1;RECIPIENT_2;RECIPIENT_3}My message content sent to others
Similar to recived message, first character describe type of message. Followed by recipients places inside{}
separated by;
with the last component is the message content.To open socket conection from client register your WebSocket on:
ws:// + host + /slchat?OWNER-ID
SLChat uses path components to send owner id.⭐ Contributing
Be welcome to contribute to this project! :)
❓ Questions
You can create an issue on GitHub.
📝 License
This project was released under the MIT license.