1

in my code i have a socket.io server and i need clients to send signal to server and than start spooky ... after starting spooky i need to send back and forth some data from server to client via io so i need socket.io instance inside spooky

here is simplified version of my code

var http = require('http');
var socket  = require('socket.io');
const express = require('express');
app = express();

try {
    var Spooky = require('spooky');
} catch (e) {
    var Spooky = require('../lib/spooky');
}



var server = http.createServer(app).listen(1300);
 var io  = socket.listen(server);

io.on('connection' , function(socket){

    socket.on('start_spooky' , function (data) {
        io.emit('push_msg' , {text : 'starting spooky ....  '  });
        run_spooky(io);
    })

});



function run_spooky(io){

    var spooky = new Spooky({
        child: {
            transport: 'http'
        },
        casper: {
            logLevel: 'debug',
            verbose: true
        }
    }, function (err) {
        if (err) {
            e = new Error('Failed to initialize SpookyJS');
            e.details = err;
            throw e;
        }
        spooky.start( 'http://localhost');

        spooky.then([{
            io: io
        }, function () {
            io.emit('push_msg' , {text : 'web page is loaded ...  ' });
        }]);

        spooky.run();
    });



}

apparently this wont work with io instance

    spooky.then([{
        io: io
    }, function () {
        io.emit('push_msg' , {text : 'web page is loaded ...  ' });
    }]);

and i get error

Could not serialize request to JSON

how can i get this to work ?

hretic
  • 999
  • 9
  • 36
  • 78

0 Answers0