mirror of
https://github.com/onionshare/onionshare.git
synced 2025-05-02 06:26:10 -04:00
Removed room from chat
- Uses the global room instead of adding and leaving room for users - Removes the joining event and triggers connection status from server as soon as a connection event is received in server side
This commit is contained in:
parent
62396e66b8
commit
f4ade1ba8d
3 changed files with 19 additions and 27 deletions
|
@ -11,29 +11,23 @@ $(function () {
|
|||
// Store current username received from app context
|
||||
var current_username = $('#username').val();
|
||||
|
||||
// On browser connect, emit a socket event to be added to
|
||||
// room and assigned random username
|
||||
socket.on('connect', function () {
|
||||
socket.emit('joined', {});
|
||||
});
|
||||
|
||||
// Triggered on any status change by any user, such as some
|
||||
// user joined, or changed username, or left, etc.
|
||||
socket.on('status', function (data) {
|
||||
addMessageToRoom(data, current_username, 'status');
|
||||
addMessageToPanel(data, current_username, 'status');
|
||||
console.log(data, current_username);
|
||||
});
|
||||
|
||||
// Triggered when message is received from a user. Even when sent
|
||||
// by self, it get triggered after the server sends back the emit.
|
||||
socket.on('message', function (data) {
|
||||
addMessageToRoom(data, current_username, 'chat');
|
||||
addMessageToPanel(data, current_username, 'chat');
|
||||
console.log(data, current_username);
|
||||
});
|
||||
|
||||
// Triggered when disconnected either by server stop or timeout
|
||||
socket.on('disconnect', function (data) {
|
||||
addMessageToRoom({ 'msg': 'The chat server is disconnected.' }, current_username, 'status');
|
||||
addMessageToPanel({ 'msg': 'The chat server is disconnected.' }, current_username, 'status');
|
||||
})
|
||||
socket.on('connect_error', function (error) {
|
||||
console.log("error");
|
||||
|
@ -66,7 +60,7 @@ $(function () {
|
|||
});
|
||||
});
|
||||
|
||||
var addMessageToRoom = function (data, current_username, messageType) {
|
||||
var addMessageToPanel = function (data, current_username, messageType) {
|
||||
var scrollDiff = getScrollDiffBefore();
|
||||
if (messageType === 'status') {
|
||||
addStatusMessage(data.msg);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue