Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

castle-chat-lib

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

castle-chat-lib - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

2

package.json
{
"name": "castle-chat-lib",
"version": "1.2.0",
"version": "1.3.0",
"description": "",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -212,2 +212,13 @@ /** File: core.js

// TODO: jesse. this isn't catching req.xhr.send(req.data) errors yet but i think we'll
// still need to patch into _onIdle to fix those
let oldIdle = _connection._onIdle.bind(_connection);
_connection._onIdle = () => {
try {
oldIdle();
} catch (e) {
throw e;
}
};
// set caps node

@@ -214,0 +225,0 @@ _connection.caps.node = 'https://candy-chat.github.io/candy/';

@@ -343,3 +343,3 @@ /** File: action.js

*/
Message: function(roomJid, msg, type, xhtmlMsg) {
Message: function(roomJid, msg, type, xhtmlMsg, msgid) {
// Trim message

@@ -356,3 +356,3 @@ msg = $.trim(msg);

// muc takes care of the escaping now.
Candy.Core.getConnection().muc.message(roomJid, nick, msg, xhtmlMsg, type);
Candy.Core.getConnection().muc.message(roomJid, nick, msg, xhtmlMsg, type, msgid);
return true;

@@ -359,0 +359,0 @@ },

@@ -49,7 +49,37 @@ import Candy from './candy/candy';

export default class CastleChat {
export const ConnectionStatus = Object.freeze({
DISCONNECTED: 0,
CONNECTING: 1,
// consumer should clear local cache of chat messages
CONNECTED: 2,
});
export class CastleChat {
init(url, userId, token, channels) {
this._url = url;
this._userId = userId;
this._token = token;
this._channels = channels;
if (window) {
window.addEventListener('online', () => {
this._handleConnectionStatusChange(Strophe.Status.CONNECTING);
this.connect();
});
window.addEventListener('offline', () => {
this._handleConnectionStatusChange(Strophe.Status.DISCONNECTED);
});
}
}
connect() {
if (this._chat) {
$(this._chat).off();
this._chat.Core.disconnect();
}
this._chat = new Candy();
this._rooms = {};
this._messagesQueue = [];
this._connectionStatus = ConnectionStatus.DISCONNECTED;

@@ -60,5 +90,5 @@ this._handleMessages = _.debounce(this._handleMessagesUndebounced, MESSAGE_DEBOUNCE_DELAY, {

this._chat.init(url, {
this._chat.init(this._url, {
core: {
autojoin: _.map(channels, (channel) => `${channel}@conference.castle.games`),
autojoin: _.map(this._channels, (channel) => `${channel}@conference.castle.games`),
resource: 'desktop-' + uuidv4(),

@@ -68,7 +98,2 @@ },

this._chat.Core.connect(
`${userId}@castle.games`,
token
);
$(this._chat).on('candy:core.message', (evt, args) => {

@@ -100,2 +125,11 @@ let roomName = args.roomName;

});
$(this._chat).on('candy:core.chat.connection', (evt, args) => {
this._handleConnectionStatusChange(args.status);
});
this._chat.Core.connect(
`${this._userId}@castle.games`,
this._token
);
}

@@ -111,2 +145,22 @@

_handleConnectionStatusChange(status) {
let lastConnectionStatus = this._connectionStatus;
if (status == Strophe.Status.CONNECTED) {
this._connectionStatus = ConnectionStatus.CONNECTED;
}
if (status == Strophe.Status.CONNECTING) {
this._connectionStatus = ConnectionStatus.CONNECTING;
}
if (status == Strophe.Status.DISCONNECTED || status == Strophe.Status.CONNTIMEOUT) {
this._connectionStatus = ConnectionStatus.DISCONNECTED;
}
if (lastConnectionStatus != this._connectionStatus && this._connectionStatusHandler) {
this._connectionStatusHandler(this._connectionStatus);
}
}
_handleMessagesUndebounced() {

@@ -131,9 +185,20 @@ let tempMessageQueue = this._messagesQueue;

setConnectionStatusHandler(handler) {
this._connectionStatusHandler = handler;
}
sendMessage(channel, message) {
this._chat.Core.Action.Jabber.Room.Message(
`${channel}@conference.castle.games`,
message,
'groupchat'
);
try {
this._chat.Core.Action.Jabber.Room.Message(
`${channel}@conference.castle.games`,
message,
'groupchat',
null,
uuidv4()
);
} catch (e) {
console.log('send message error');
console.log(JSON.stringify(e));
}
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc