new Client()
Client class is the main application class, it's the core of the library that makes all works together. A Client represent a user connection to curse servers, it handles the main events that occurs at run time and expose them to a third party application. The Client class extends the EventEmitter class.
Properties:
Name | Type | Description |
---|---|---|
servers |
Map | Regroup all the servers fetched when the client starts. This map is filled only when using the client.run method. The keys are the servers IDs and the values are instances of the Server class. |
channels |
Map | Regroup all the channels fetched from all the servers when the client starts. This map is filled only when using the client.run method. The keys are the channels IDs and the values are instances of the Channel class. |
conversations |
Map | Regroup all the conversations that the client encounters during its run time. The keys are the conversations IDs and the values are instances of the Conversation class. |
users |
Map | Regroup all the users that the client encounters during its run time. The keys are the users IDs and the values are instances of the User class. |
clientID |
number | Curse ID of the connected client. This is very helpful for example to check the ID of the for notificationMessages and ignore self sended messages. |
username |
string | Curse username of the connected client. |
Methods
close()
Closes the Client by ending the notifier connection and returning the run function.
getUser(userID) → {User}
Get a User object from its ID.
Parameters:
Name | Type | Description |
---|---|---|
userID |
number | ID of the curse user |
Returns:
Corresponding User object
- Type
- User
Example
var myUser = client.getUser(myUserID);
login(login, password, callback)
Connects the client to the curse API endpoints. This function will not get any server information ready, and will neither start the notifier from the notification module making impossible to receive and send new messages. For general use the Client.run function.
Parameters:
Name | Type | Description |
---|---|---|
login |
string | Your Curse login name |
password |
string | Your Curse login password |
callback |
function | Facultative arg, callback: (errors) => {}. This function can take an argument errors that is null or undefined when function ends correctly. |
redeemInvitation(inviteCode, callback)
Join a server using a specified invite code.
Parameters:
Name | Type | Description |
---|---|---|
inviteCode |
string | Invitation code |
callback |
function | Function callback |
Example
client.redeemInvitation(myInvitationCode, function(errors){
if(errors === null){
//Code when server have succesfully been joined
}
});
run(login, password)
All-in-one function that makes the client to work seemlessly. The Client class will emit the ready event when the client is connected and ready.
Parameters:
Name | Type | Description |
---|---|---|
login |
string | Your Curse login name |
password |
string | Your Curse login password |
Example
var client = new cursejs.Client;
//Internal use of the client
client.on('ready', function(){
//My own code...
});
//Start the client after defining the events handler
client.run('login', 'password');
sendMessage(conversation, content, callback)
Send a message in a conversation.
Parameters:
Name | Type | Description |
---|---|---|
conversation |
Conversation | Conversation |
content |
string | Message content |
callback |
function | Facultative arg, callback: (errors) => {}. This function can take an argument errors that is null or undefined when function ends correctly. |
Events
message_deleted
The event message_deleted is triggered everytime the client receive a deleted message, the callback gives a messageNotification as first and only argument.
Parameters:
Name | Type | Description |
---|---|---|
message |
MessageNotification | Message deleted |
message_edited
The event message_edited is triggered everytime the client receive an edited message, the callback gives a messageNotification as first and only argument.
Parameters:
Name | Type | Description |
---|---|---|
message |
MessageNotification | Message edited |
message_liked
The event message_liked is triggered everytime the client receive a like, the callback gives a messageNotification as first and only argument.
Parameters:
Name | Type | Description |
---|---|---|
message |
MessageNotification | Message liked |
message_received
The event message_received is triggered everytime the client receive a message, the callback gives a messageNotification as first and only argument.
Parameters:
Name | Type | Description |
---|---|---|
message |
MessageNotification | Message received |
ready
The event ready is triggered when all the servers informations have been loaded and the notification module is ready. This event isn't triggered when the notifier drops and reconnect.
server_change
The event server_change is triggered when a server information is changed inside the server, it can be a channel name, a reorganization of the channels, a role modified.. The library doesn't inform yet which information have been modified, but handle the modification internally.
Parameters:
Name | Type | Description |
---|---|---|
server |
Server | Server changed |