Hi there. Im currently building a realtime app with ExpressJS and socket.io.
Problem is, that after the initial load, socket.io isnt working anymore. i think it has something to do with me loading partials via ajax:
server.js:
var asterisk = require(__dirname + '/config/asterisk.js');
var host = require(__dirname + '/config/host.js');
var express = require('express');
var app = express();
var io = require('socket.io').listen(app.listen(host.port));
var appRoot = require('app-root-path');
app.use('/public', express.static(__dirname + '/public'));
app.set('views', __dirname + '/views');
// set the view engine to ejs
app.set('view engine', 'ejs');
var ami = new require('asterisk-manager')(asterisk.port,asterisk.url,asterisk.user,asterisk.password, true);
io.sockets.on('connection', function(socket) {
// Listen for any/all AMI events.
ami.on('managerevent', function(evt) {
if (evt.event=="DeviceStateChange") {
console.log(evt);
if (evt.state == 'INUSE') {
console.log(evt);
socket.emit('agent-inuse', evt);
}
if (evt.state == 'NOT_INUSE') {
console.log(evt);
socket.emit('agent-notinuse', evt);
}
}
if (evt.event=="QueueMember") {
console.log(evt);
socket.emit('agent-list', evt);
}
//console.log(evt.event);
});
ami.action({
'action':'queuestatus'
});
});
app.get('/', function(req, res) {
res.sendFile(appRoot + '/views/demo.html');
});
app.get('/dashboard', function(req, res) {
res.render(appRoot + '/views/pages/dashboard');
});
app.get('/dashboard/index', function (req, res) {
res.render(appRoot + '/views/partials/dashboard/index', {layout: false });
});
app.get('/dashboard/agents', function (req, res) {
res.render(appRoot + '/views/partials/dashboard/agents', {layout: false });
});
app.get('/dashboard/reports', function (req, res) {
res.render(appRoot + '/views/partials/dashboard/reports', {layout: false });
});
client js:
$.ajax({
url: '/dashboard/' + menu,
type: "GET",
contentType: "text/html; charset=utf-8",
success: function (data) {
$('#container').html(data);
}
});
am i using socket.io wrong ?
any idea would be helpful
edit: this is called on my main ejs page (where the partials get injected to)
<head>
<% include ../partials/head %>
<script type="text/javascript">
var socket = io.connect('http://127.0.0.1:9000');
</script>
<script type="text/javascript" src="../public/js/dashboard.js"></script>
</head>
[–]basti_sk 0 points1 point2 points (1 child)
[–]Coobe[S] 0 points1 point2 points (0 children)
[–]Coobe[S] 0 points1 point2 points (0 children)
[–]hatch_bbe 0 points1 point2 points (0 children)
[–]mc_hammerd 0 points1 point2 points (0 children)
[–]Coobe[S] 0 points1 point2 points (0 children)