Pourya8366
Pourya8366

Reputation: 3684

Use socket.io object in total.js

I'm using socket.io in total.js and want to use the io object in a module.

how can i access the io object in a module? (pass the object or set the global framework object?)

the initialization code:

require("total.js");

ON("load", function() {
    let io = require("socket.io")(this.server);
});

F.http("debug");

Upvotes: 0

Views: 159

Answers (1)

Peter Sirka
Peter Sirka

Reputation: 748

First you need to disable WebSocket in Total.js framework: https://docs.totaljs.com/latest/en.html#api~FrameworkConfiguration~allow_websocket

Initialization code for Socket.io:

ON('ready', function() {
    // "IO" will be a global variable, so you can use it everywhere
    global.IO = require('socket.io')(F.server);
});

Upvotes: 1

Related Questions