If I create a basic javascript websocket sample it works fine on PhantomJS, although the same sample in Scala.js does not. It establishes the connection but before netty has a chance to answer the connection closes. At first I thought that phantomJS exits and the connection closes, but it behaves the same if I sleep it for a while... (btw for those who would want to build the PhantomJS fork 2.0 branch it is necessary to chmod -R 775 ./* for it to build successfully...)
var ws = new WebSocket("ws://localhost:8182/gremlin");
ws.onopen = function() {
console.log("On connection open");
ws.send("Message to send");
};
ws.onmessage = function (evt) {
console.log("On message");
var received_msg = evt.data;
phantom.exit()
};
ws.onclose = function() {
console.log("Closing socket");
};
ws.onerror = function(err) {
console.log("Some error has occurred : " + err);
};
import org.scalajs.dom
import scala.scalajs.js.{Date, JSApp}
import org.scalajs.dom.{CloseEvent, ErrorEvent, Event, MessageEvent}
object ExampleJS extends JSApp {
def main(): Unit = {
val ws = new dom.WebSocket("ws://localhost:8182/gremlin")
ws.onopen = (x: Event) => {
println("On connection open")
ws.send("Message to send")
}
ws.onmessage = (x: MessageEvent) => {
println("On message")
println(x.data.toString)
}
ws.onclose = (x: CloseEvent) =>
println("Closing socket")
ws.onerror = (x: ErrorEvent) =>
println("Some error has occurred : " + x)
sleep(2000)
}
def sleep(ms: Long) {
val start = new Date().getTime()
for (i <- 1 until 10000000) {
if ((new Date().getTime() - start) > ms){
return
}
}
}
}