<commit_before>package controller

import org.scalajs.dom
import org.scalajs.dom.{CloseEvent, ErrorEvent, Event, MessageEvent, WebSocket, console}
import shared.CodeEditorMessage
import shared.CodeEditorMessage._
import upickle.default._

case class WebSocketConnection(uri: String = "ws://127.0.0.1:9000/codeeditor/socket", controller: CodeEditorController, metaModelUuid: String, dslType: String) {

  /** Set up WebSocket connection */
  val ws = new dom.WebSocket(uri + "/" + metaModelUuid + "/" + dslType)
  ws.onmessage = (msg: MessageEvent) => onMessage(msg)
  ws.onopen = (e: Event) => onOpen(e)
  ws.onerror = (e: ErrorEvent) => console.error(s"Websocket Error! ${e.message}")
  ws.onclose = (e: CloseEvent) => console.log(s"Closed WS for Reason: ${e.reason}")

  def onOpen(e: Event) = {
    console.log("Opened Websocket: ", e.`type`)
  }

  def onMessage(msg: MessageEvent) = {
    read[CodeEditorMessage](msg.data.toString) match {
      case msg: TextOperation => controller.operationFromRemote(msg)
      case msg: DocLoaded => controller.docLoadedMessage(msg)
      case msg: DocNotFound => controller.docNotFoundMessage(msg)
      case _ =>
    }
  }

  def sendMessage(msg: CodeEditorMessage) = ws.readyState match {
    case WebSocket.OPEN =>
      ws.send(write(msg))
    case _ =>
      console.error("Could not send Message because WebSocket is not in ready state!", ws)
  }<commit_msg>Change<commit_after>package controller

import java.net.InetAddress

import org.scalajs.dom
import org.scalajs.dom.{CloseEvent, ErrorEvent, Event, MessageEvent, WebSocket, console}
import shared.CodeEditorMessage
import shared.CodeEditorMessage._
import upickle.default._

case class WebSocketConnection(uri: String = "ws://127.0.0.1:9000/codeeditor/socket", controller: CodeEditorController, metaModelUuid: String, dslType: String) {

  /** Set up WebSocket connection */
  val localhost = InetAddress.getLocalHost
  val localIpAddress = localhost.getHostAddress
  val uri_new = "ws://"+localIpAddress+":9000/codeeditor/socket"
  val ws = new dom.WebSocket(uri_new + "/" + metaModelUuid + "/" + dslType)
  ws.onmessage = (msg: MessageEvent) => onMessage(msg)
  ws.onopen = (e: Event) => onOpen(e)
  ws.onerror = (e: ErrorEvent) => console.error(s"Websocket Error! ${e.message}")
  ws.onclose = (e: CloseEvent) => console.log(s"Closed WS for Reason: ${e.reason}")

  def onOpen(e: Event) = {
    console.log("Opened Websocket: ", e.`type`)
  }

  def onMessage(msg: MessageEvent) = {
    read[CodeEditorMessage](msg.data.toString) match {
      case msg: TextOperation => controller.operationFromRemote(msg)
      case msg: DocLoaded => controller.docLoadedMessage(msg)
      case msg: DocNotFound => controller.docNotFoundMessage(msg)
      case _ =>
    }
  }

  def sendMessage(msg: CodeEditorMessage) = ws.readyState match {
    case WebSocket.OPEN =>
      ws.send(write(msg))
    case _ =>
      console.error("Could not send Message because WebSocket is not in ready state!", ws)
  }
{'fraction_non_alphanumeric': 0.13108739159439625, 'fraction_numerical': 0.008005336891260841, 'mean_word_length': 4.26140350877193, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7389125', 'n_tokens_mistral': 987, 'n_tokens_neox': 949, 'n_words': 221}