Hi,
How can we specify user and password?
There are two options here: You can get a session by using the login api (browser only):
$.ajax({
type: "POST"
url: '/login'
data: {
username: "user",
password: "password"
}
}).done( (result)->
setTimeout( ( ->
io.connect()
), 1)
)
This has the advantage that you have a session for future ajax-requests.
Or you can simply supply the username or passward in the url:
u = encodeURIComponent(username)
p = encodeURIComponent(password)
socket = io("
http://#{host}:#{port}/?username=#{u}&password=#{p}", {
reconnection: yes
reconnectionDelay: 1000
reconnectionDelayMax: 3000
timeout: 20000
forceNew: yes
})
Could this be run as a node script? Where does the “io” object come from? I assume var io = require(‘socket.io’) but I am not seeing any output from this script.
Yes. See just here for more details: https://github.com/pimatic/pimatic-peer/blob/daca96148a61b7f9ca94e93e206fa1e41b2c6485/peer.coffee#L27-L38
(Also, there’s a typo, a holdout from coffeescript where it mentions attrEvent)
Thanks for the notice. If you like you can help and directly edit the docs here: https://github.com/pimatic/pimatic-guide/blob/master/api/index.html.md
Can you recommend a clear explanation of the difference between websocket and socket.io?
socket.io uses websocket in modern browsers and has a fallback to ajax polling for browsers not supporting websockets. It also has some advanced features like topic subscriptions and detecting disconnects by regular pings. For more details, see for example: http://stackoverflow.com/questions/10112178/differences-between-socket-io-and-websockets
Sorry for the CoffeeScript sources. I hope this helps anyway