var React = require('react');
var Channel = require('./Channel');
var Mui = require('material-ui');
var FloatingActionButton = Mui.FloatingActionButton;
var RightNav = require('./material-ui/right-nav.jsx');
var NUTELLA = require('nutella_lib');
var IdentitySelector = require('../identity-selector/main');
var Player = require('./Player');
var NutellaMixin = require('../NutellaMixin');
var $ = require('jquery');
require('jquery-ui/draggable');
var Main = React.createClass({
mixins: [NutellaMixin],
componentDidMount: function() {
var self = this;
window.nutella = NUTELLA.init(self.props.params.broker, self.props.params.app_id, self.props.params.run_id, 'app', function(connected) {
if(connected) {
// Get current channels catalogue
nutella.net.request('channels/retrieve', 'all', function (response) {
self.handleUpdatedChannelsCatalogue(response);
// If at startup info on id is already in state
if(self.state.rid) {
// Get current assigned channels (mapping)
nutella.net.request('mapping/retrieve', 'all', function (response) {
self.handleActivitySwitch(response);
});
}
// Subscribe for future changes
nutella.net.subscribe('mapping/updated', function (message, from) {
self.handleActivitySwitch(message);
});
nutella.net.subscribe('currentConfig/switched', function (message, from) {
self.handleActivitySwitch(message);
});
nutella.net.subscribe('channels/updated', function (message, from) {
nutella.net.request('mapping/retrieve', 'all', function (response) {
self.handleUpdatedChannelsCatalogue(message, function() {
self.updateChannelsForRid(response, self.state.rid);
});
});
});
// Subscribe to teacher forced logout
nutella.net.subscribe('logout/all', function (message, from) {
self.handleLogout();
});
});
}
});
},
/**
* Manages the modal sidebar right after state change
*/
componentWillReceiveProps: function(nextProps) {
var self = this;
if(!this.state.rid) {
this.refs.rightNav.open();
this.refs.rightNav.setState({
modal: true
});
// Force update menu with resources
nutella.net.request('mapping/retrieve', 'all', function (response) {
self.handleUpdatedMapping(response);
});
} else {
this.refs.rightNav.setState({
modal: false
});
}
},
/**
* Updates current available channels.
* @param message list of channels
* @param rid current identity
*/
updateChannelsForRid: function(message, rid) {
var self = this;
var myChannelsId = [];
var myChannels = [];
message.forEach(function (f) {
for (var i in f.items) {
var item = f.items[i];
if (item.name === rid) {
myChannelsId = item.channels;
break;
}
}
});
for(var i=0; i
{this.state.backgroundMessage}
; } if(this.state.playing === null) { backgroundMessage ={'Select a channel'}
; } var gridHeight = $('.grid').css('height'); var backgroundMessageTabsStyle = { position: 'fixed', left: '0', top: (parseInt(gridHeight) / 2) - 10, width: '100%', fontSize: '2.5vw', textAlign: 'center', color: 'rgba(255,255,255,0.8)', fontWeight: '300' }; var backgroundMessageTabs = null; if(this.state.backgroundMessageTabs) { backgroundMessageTabs ={this.state.backgroundMessageTabs}
; } var canLogout = true; if(!this.state.rid) { canLogout = false; } var touchDivStyle = { width: '80px', height: '60px', position: 'fixed', bottom: 0, right: 0, zIndex: 250 }; var players = []; var ids = this.state.players; ids.forEach(function(id) { var p_id = self.state.playing; var playing = p_id === id; if(self.state.channelsCatalogue[+id]) { var player =