public function onMessage(ConnectionInterface $from, $msg) {
    $data = json_decode($msg, true);
    if (!$data['action']
        || !in_array(
            $data['action'],
            ['authenticate', 'subscribe', 'unsubscribe', 'publish']
        )) {
      return;
    }
    switch ($data['action']) {
      case 'authenticate':
        $this->handleAuthentication($from, $data);
        break;
      case 'subscribe':
      case 'unsubscribe':
        $this->handleSubscription($from, $data);
        break;
      case 'publish':
        $this->handlePublish($from, $msg, $data);
        break;
    }
  }