1
1
<!DOCTYPE html>
2
2
< html lang ="en ">
3
3
< head >
4
- < meta charset ="UTF-8 ">
5
- < title > Simple Chat Application using StompJs</ title >
6
- < link type ="text/css " rel ="stylesheet " href ="../../assets/style.css ">
4
+ < meta charset ="UTF-8 ">
5
+ < title > Simple Chat Application using StompJs</ title >
6
+ < link type ="text/css " rel ="stylesheet " href ="../../assets/style.css ">
7
7
</ head >
8
8
< body >
9
9
< div id ="wrapper ">
10
- < ul >
11
- < li > Open multiple browsers or tabs to chat across those.</ li >
12
- < li > You will need a STOMP broker running. The defaults will work for fresh RabbitMQ on local machine.</ li >
13
- < li > Adjust the < a href ="https://stomp-js.github.io/api-docs/latest/classes/StompConfig.html "> configuration</ a >
14
- as per your STOMP broker.</ li >
15
- < li > A guide at < a href ="https://stomp-js.github.io/guide/stompjs/2018/06/28/using-stompjs-v5.html ">
16
- Using StompJs v5</ a > </ li >
17
- < li >
18
- < a href ="https://stomp-js.github.io/guide/stompjs/rx-stomp/ng2-stompjs/2018/09/10/using-stomp-with-sockjs.html ">
19
- Using STOMP with SockJS</ a > </ li >
20
- < li > For details on API calls see:
21
- < a href ="https://stomp-js.github.io/api-docs/latest/classes/Client.html ">
22
- API Reference</ a > </ li >
23
- < li > The html/css is heavily based on
24
- < a href ="https://code.tutsplus.com/tutorials/how-to-create-a-simple-web-based-chat-application--net-5931 ">
25
- Simple Web-Based Chat Application</ a > </ li >
26
- </ ul >
27
- < div id ="menu ">
28
- < p class ="welcome "> Welcome, < input title ="username " name ="username " id ="username " type ="text " value ="Change Me ">
29
- </ p >
30
- </ div >
31
-
32
- < div id ="chatbox "> </ div >
33
-
34
- < input name ="usermsg " type ="text " id ="usermsg " size ="63 " title ="usermsg "/>
35
- < button name ="submitmsg " id ="submitmsg "> Send</ button >
10
+ < ul >
11
+ < li > Open multiple browsers or tabs to chat across those.</ li >
12
+ < li > You will need a STOMP broker running. The defaults will work for fresh RabbitMQ on local machine.</ li >
13
+ < li > Adjust the < a href ="https://stomp-js.github.io/api-docs/latest/classes/StompConfig.html "> configuration</ a >
14
+ as per your STOMP broker.
15
+ </ li >
16
+ < li > A guide at < a href ="https://stomp-js.github.io/guide/stompjs/2018/06/28/using-stompjs-v5.html ">
17
+ Using StompJs v5</ a > </ li >
18
+ < li > For details on API calls see:
19
+ < a href ="https://stomp-js.github.io/api-docs/latest/classes/Client.html ">
20
+ API Reference</ a > </ li >
21
+ < li > The html/css is heavily based on
22
+ < a href ="https://code.tutsplus.com/tutorials/how-to-create-a-simple-web-based-chat-application--net-5931 ">
23
+ Simple Web-Based Chat Application</ a > </ li >
24
+ </ ul >
25
+ < div id ="menu ">
26
+ < p class ="welcome "> Welcome, < input title ="username " name ="username " id ="username " type ="text " value ="Change Me ">
27
+ </ p >
28
+ </ div >
29
+
30
+ < div id ="chatbox "> </ div >
31
+
32
+ < input name ="usermsg " type ="text " id ="usermsg " size ="63 " title ="usermsg "/>
33
+ < button name ="submitmsg " id ="submitmsg "> Send</ button >
36
34
</ div >
37
35
38
36
<!-- It is used for DOM manipulation, not mandatory to use stompjs -->
39
37
< script src ="
https://cdn.jsdelivr.net/npm/[email protected] /dist/jquery.min.js "
> </ script >
40
38
41
39
<!-- Include from CDN for better performance, alternatively you can locally copy as well -->
42
- < script src ="https://cdn.jsdelivr.net/npm/@stomp/stompjs@5 .0.0/bundles/stomp.umd.min.js "> </ script >
40
+ < script src ="https://cdn.jsdelivr.net/npm/@stomp/stompjs@7 .0.0-beta2 /bundles/stomp.umd.min.js "> </ script >
43
41
44
42
< script type ="application/javascript ">
45
43
$ ( function ( ) {
46
44
let stompClient ;
47
45
48
46
const stompConfig = {
49
- // Typically login, passcode and vhost
47
+ // Typically, login, passcode and vhost
50
48
// Adjust these for your broker
51
49
connectHeaders : {
52
50
login : "guest" ,
70
68
// The return object has a method called `unsubscribe`
71
69
const subscription = stompClient . subscribe ( '/topic/chat' , function ( message ) {
72
70
const payload = JSON . parse ( message . body ) ;
73
- displayIncomingMessage ( payload . user , payload . message ) ;
71
+ displayIncomingMessage ( payload . user , payload . usrMsg ) ;
74
72
} ) ;
75
73
}
76
74
} ;
77
75
78
76
// Create an instance
79
77
stompClient = new StompJs . Client ( stompConfig ) ;
80
78
81
- // You can set additional configuration here
79
+ // You can set additional configuration options here
82
80
83
81
// Attempt to connect
84
82
stompClient . activate ( ) ;
104
102
return false ;
105
103
}
106
104
if ( message . length > 0 ) {
107
- const payLoad = { user : user , message : message } ;
105
+ const payLoad = { user : user , usrMsg : message } ;
108
106
109
107
// You can additionally pass headers
110
108
stompClient . publish ( { destination : '/topic/chat' , body : JSON . stringify ( payLoad ) } ) ;
120
118
} )
121
119
</ script >
122
120
</ body >
123
- </ html >
121
+ </ html >
0 commit comments