JSFiddle - React, Tailwind, and code Playground

by Evgeniy Lukovsky

HTML

<div ng-app>
    <div ng-controller="controller">
        <ul>
            <li ng-repeat="responce in responces track by $index">{{responce}}</li>
        </ul>
        <input type="text" ng-model="textToSend"/>
        <input type="button" value="send" ng-click="send()"/>
    </div>
</div>

JavaScript

angular.module('test',[]);

function controller($scope){
    var SECRET = 'OZlOy1MvJ1RtNmVz';
    var ws = new WebSocket('ws://localhost:54321/'); 
    $scope.textToSend='';
    var user_id = 5;
    $scope.responces=[];
    $scope.send = function(){
        ws.send($scope.textToSend);
    };
    ws.onmessage=function(e, flags){
        $scope.responces.push(e.data);
        $scope.$digest();
        console.log(e.data);
    };
    ws.onopen = function(){
        var message = {id:user_id,secret:SECRET};
        //ws.send(JSON.stringify(message));
        //ws.send(user_id);
    };
    
}