将socket.io实例传递给怪异

时间:2018-06-25 15:27:26

标签: javascript node.js phantomjs casperjs spookyjs

在我的代码中,我有一个socket.io服务器,我需要客户端将信号发送到服务器,而不是开始诡异...开始诡异之后,我需要通过io从服务器到客户端来回发送一些数据,所以我需要诡异的socket.io实例

这是我的代码的简化版本

for

显然这不适用于io实例

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();
    });



}

我收到错误消息

无法将请求序列化为JSON

我如何使它工作?

0 个答案:

没有答案