App-SlideServer
view release on metacpan or search on metacpan
share/public/slides.js view on Meta::CPAN
this.ws.onmessage= function(event) { self._handle_ws_event(JSON.parse(event.data)) }
this.ws.onopen= function(event) { self._handle_connect(event, url, mode) }
this.ws.onclose= function(event) { self._handle_disconnect(event) }
},
enableLead: function(enable, ev) {
if (enable) {
if (this.roles.lead) {
this.leading= true;
this.enableFollow(false);
}
} else {
this.leading= false;
}
this.root.find('.status-actions .lead input').prop('checked', enable);
this._update_status();
},
enableFollow: function(enable, ev) {
if (enable) {
this.following= true;
this.enableLead(false);
this.goToLeaderSlide();
} else {
this.following= false;
}
this.root.find('.status-actions .follow input').prop('checked', enable);
this._update_status();
},
enableNavigate: function(enable, ev) {
if (enable) {
this._build_nav_ui();
this.nav_ui.show();
} else {
if (this.nav_ui)
this.nav_ui.hide();
}
this.root.find('.status-actions .navigate input').prop('checked', enable);
},
enableNotes: function(enable, ev) {
if (enable) {
this._build_presenternotes_ui();
this.presenternotes_ui.show();
} else {
if (this._presenternotes_ui)
this.presenternotes_ui.hide();
}
// re-render current slide
this.showNotes= !!enable;
this._show_slide(this.cur_slide, this.getSlide(this.cur_slide).cur_step);
},
_set_conn_note: function(content, duration) {
var self= this;
if (this._conn_note) {
var prev= this._conn_note
delete this._conn_note
prev.fadeOut(500, function(){ prev.remove() })
}
var next= $(content);
this.root.find('.slides-notify').append(next);
this._conn_note= next;
if (duration)
window.setTimeout(function(){
if (self._conn_note == next) this._conn_note= null
next.fadeOut(500, function(){ next.remove() });
}, duration);
this._update_status();
},
_update_status: function() {
var status= this.root.find('.status');
status.empty();
if (this.ws) {
var server= ''+this.ws.url;
server= server.replace(/^wss?:\/\/([^:\/]+).*/, '$1');
if (this.ws.readyState == 0)
status.append('<li class="connecting">Connecting to <span class="host">'+escape_html(server)+'</span></li>');
else if (this.ws.readyState == 1)
status.append('<li class="connected">Connected to <span class="host">'+escape_html(server)+'</span></li>');
else
status.append('<li class="disconnected">Not connected</li>');
}
if (this.following)
status.append('<li class="follow">Following presenter</li>');
else if (this.leading)
status.append('<li class="broadcast">Broadcasting</li>');
if (this.cur_slide && this.slides && this.slides.length)
status.append('<li class="pos">Slide <b>'+this.cur_slide+'</b> of <b>'+this.slides.length+'</b></li>');
},
_handle_connect: function(event, url, mode) {
this.root.find('.reconnect-btn').hide()
this._set_conn_note('<p>Connected</p>', 1500)
if (this.config.mode == 'obs')
this.enableFollow(true);
},
_handle_disconnect: function(event) {
this.root.find('.reconnect-btn').show()
this._set_conn_note('<p>Lost connection</p>')
delete this.ws;
},
_handle_ws_event: function(event) {
//console.log('ws event: ', event);
if (event.state) {
this.sharedState= event.state;
if (this.following)
this.goToLeaderSlide();
}
if (event.roles) {
this.roles= {};
for (var i=0; i < event.roles.length; i++)
this.roles[event.roles[i]]= 1;
if (this.roles.lead) {
this.enableFollow(false);
this.root.find('.status-actions .follow').show();
this.root.find('.status-actions .lead').show();
this.root.find('.status-actions .notes').show();
} else {
// initial state for non-lead is to follow
this.enableFollow(true);
}
if (this.roles.navigate || this.roles.lead) {
this.root.find('.status-actions .navigate').show();
}
}
( run in 1.131 second using v1.01-cache-2.11-cpan-39bf76dae61 )