Skip to content

Commit

Permalink
socket io - do not reconnect if not necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
David Zilbrug authored and David Zilbrug committed Jul 11, 2017
1 parent 7343ab8 commit d027cc0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
6 changes: 6 additions & 0 deletions src/js/components/team.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ team = (function() {
var _nextPersonAttr;

return {
getCurrentTeamId: function() {
if(!_teamJson) {
return null;
}
return _teamJson._id;
},
initialize: function(teamData) {
$('body').ploading({action: 'show'});
$.ajax({
Expand Down
21 changes: 13 additions & 8 deletions src/js/components/teampicker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
teampicker = (function() {
var _selectpicker;
var _teamsArray = [];
var _socket;
const _socket = io();
_socket.on('connect_failed', function() {
alert('Socket connection issue.');
});
_socket.on('error', function() {
alert('Socket issue.');
});


function createTeamAddRequest(name, callback) {
Expand Down Expand Up @@ -133,24 +139,23 @@ teampicker = (function() {
_selectpicker.appendTo('#select-div');
_selectpicker.selectpicker('refresh');

_socket = io();

loadSelectOptions(function() {
$('body').ploading({action: 'destroy'});

$('#select-div .selectpicker').change(function() {
var id = $(this).children(":selected").attr('id');
var selectedTeamId = _teamsArray[id]._id;
if(id) {
if(team.getCurrentTeamId() != selectedTeamId) {
_socket.emit('join room', selectedTeamId);
initializeSocket(_socket);
}
team.initialize(_teamsArray[id]);
_socket.disconnect();
_socket = io();
_socket.emit('join room', _teamsArray[id]._id);
initializeSocket(_socket);
}
});

$('#select-div').click(function(){
$('.bs-searchbox>input').attr('placeholder', 'Search through your existing teams or type a new team name')
$('.bs-searchbox>input').attr('placeholder', 'Search through your existing teams or type a new team name');
$('.bs-searchbox>input').off('input', handleSearch).on('input', handleSearch);
});

Expand Down

0 comments on commit d027cc0

Please sign in to comment.