1

I'm trying to use ImpactJS, a JS framework. I want to add socket.io functions. As soon as I add socket.io there is an error

Uncaught ReferenceError: sock is not defined jquery-1.7.1.min.js:4

My class where I use soket.io :here (end of the file)

My index.html : here

I don't understand why I can't use both. Thx for your help.

damien marchand
  • 864
  • 1
  • 13
  • 30

2 Answers2

0

Index line 35

var sock = io.connect('http://localhost:3000');

Class line 134

sock.emit('update', this.padmap, this.id);

sock is not in the window scope so this will not work. Change var sock to window.sock and sock.emit to window.sock.emit.

However using global variables are frowned upon. If you're using global variables you're doing something wrong.

micah
  • 7,596
  • 10
  • 49
  • 90
  • I understant but after changes I have other error messages : Uncaught SyntaxError: Unexpected token . localhost/:35 Uncaught TypeError: Cannot read property 'emit' of undefined Player.js:52 My new files : Player.js : [link](http://pastebin.com/UMkakdKW) index.html : [link](http://pastebin.com/uDCrbvhM) – damien marchand Aug 07 '14 at 12:36
  • window.sock isn't defined. figure out why window.sock isn't defined. Also don't use window like I said. You should not use global variables. – micah Aug 08 '14 at 22:34
0

I find the problem. Socket is loaded in index.html and not in Player.js.

Map editor can't load socket. To solve this problem in Player.js :

if (typeof sock != 'undefined')
sock.emit('update', this.padmap, this.id);
damien marchand
  • 864
  • 1
  • 13
  • 30