K
K
KnightForce2017-01-22 03:57:23
JavaScript
KnightForce, 2017-01-22 03:57:23

How to use one socket in different js files on the client?

There is a js file in which the following is connected in the closure:

var socket = io("http://localhost/socket"); //путь условный

There is a second js file that is sent only under a certain condition (as it should be), but there I would also like to use the socket library so as not to transfer via ajax, because it is not known how many times to transfer data (from 0 to infinity).
Do not write there again
var socket = io("http://localhost/socket");:)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan, 2017-01-22
@LiguidCool

Well, check if there is a socket , and if it is, send through it.
Declare it globally in general.

R
rPman, 2017-01-23
@rPman

the very moment where you can use global variables or your global functions that give access to variables

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question