10 examples of 'chatjs' in JavaScript

Every line of 'chatjs' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
15function sendChat(){
16 let chatHistory = document.getElementById("chat_history_panel");
17 let chatInput = document.getElementById("chat_input");
18 chatHistory.innerHTML = chatHistory.innerHTML
19 + '<br>'
20 + '<span class="my_chat">'
21 + playerPrefix + chatInput.value
22 + '</span>';
23 sendChat2Server(chatInput.value);
24 chatInput.value = "";
25 //TODO send to server
26}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

126function initChat() {
127 var chat;
128
129 if(rtc.dataChannelSupport) {
130 console.log('initializing data channel chat');
131 chat = dataChannelChat;
132 } else {
133 console.log('initializing websocket chat');
134 chat = websocketChat;
135 }
136
137 var input = document.getElementById("chatinput");
138 var toggleHideShow = document.getElementById("hideShowMessages");
139 var room = window.location.hash.slice(1);
140 var color = "#" + ((1 << 24) * Math.random() | 0).toString(16);
141
142 toggleHideShow.addEventListener('click', function() {
143 var element = document.getElementById("messages");
144
145 if(element.style.display === "block") {
146 element.style.display = "none";
147 }
148 else {
149 element.style.display = "block";
150 }
151
152 });
153
154 input.addEventListener('keydown', function(event) {
155 var key = event.which || event.keyCode;
156 if(key === 13) {
157 chat.send(JSON.stringify({
158 "eventName": "chat_msg",
159 "data": {
160 "messages": input.value,
161 "room": room,
162 "color": color
163 }
164 }));
165 addToChat(input.value);
166 input.value = "";
167 }
168 }, false);
169 rtc.on(chat.event, function() {
170 var data = chat.recv.apply(this, arguments);
171 console.log(data.color);
172 addToChat(data.messages, data.color.toString(16));
173 });
174}
86_onChatLine(message, type, recipients) {
87 if (!message) return // BW calls these methods even if no message was typed
88
89 if (this._exclusive) {
90 this._exclusive._addLine(message)
91 return
92 }
93
94 let convertedType
95 switch (type) {
96 case 2: convertedType = 'all'; break
97 case 3: convertedType = 'allies'; break
98 case 4: convertedType = 'player'; break
99 default: convertedType = 'unknown'
100 }
101
102 const command = message.split(' ', 1)[0]
103 const handled = this.emit(command, message, convertedType, recipients)
104
105 if (!handled) {
106 // we didn't handle it, so send it back to BW so it goes through to other users
107 this.bw.bindings.sendMultiplayerChatMessage(message, type, recipients)
108 }
109}
80function addToChat(msg, color) {
81 var messages = document.getElementById('messages');
82 msg = sanitize(msg);
83 if (color) {
84 msg = '<span style="color: ' + color + '; padding-left: 15px">' + msg + '</span>';
85 } else {
86 msg = '<strong style="padding-left: 15px">' + msg + '</strong>';
87 }
88 messages.innerHTML = messages.innerHTML + msg + '<br>';
89 messages.scrollTop = 10000;
90}
6function Chat(client)
7{
8 this.client = client;
9 this.currentMessage = new Message();
10 this.messages = [];
11 this.room = null;
12 this.$scope = null;
13 this.feed = null;
14
15 this.talk = this.talk.bind(this);
16 this.onTalk = this.onTalk.bind(this);
17 this.scrollDown = this.scrollDown.bind(this);
18
19 this.attachEvents();
20}
55_onChat (data) {
56 if(data.command) {
57 let parts = data.text.substr(1).split(' ');
58
59 let command = parts[0];
60 let params = parts.slice(1);
61
62 if (!this.app.players.list.hasOwnProperty(data.login)) {
63 return;
64 }
65
66 // Admin command?
67 if (command === 'admin' && params.length >= 1) {
68 if (this.commands.hasOwnProperty('admin__' + params[0])) {
69 return this._handleAdmin(this.app.players.list[data.login], this.commands['admin__' + params[0]], params.slice(1), data);
70 }
71 }
72
73 // Non-admin command (could still have level btw).
74 if (this.commands.hasOwnProperty(command)) {
75 return this._handle(this.app.players.list[data.login], this.commands[command], params, data);
76 }
77
78 // If not yet returned, show error.
79 this.app.server.send().chat('Error, command doesn\'t exist!', {destination: data.login}).exec();
80 }
81}
11chatMessage({ sender, message, channel }: ChatMessage) {
12 console.log(`${channelNames[channel]}: ${sender}: ${message}`);
13}
267function ChatLive_loadChatRequest(chat_number) {
268 ChatLive_socket[chat_number] = new ReconnectingWebSocket('wss://irc-ws.chat.twitch.tv', 'irc', {
269 reconnectInterval: 3000
270 });
271
272 ChatLive_socket[chat_number].onopen = function() {
273 ChatLive_socket[chat_number].send('PASS blah\r\n');
274 ChatLive_socket[chat_number].send('NICK justinfan12345\r\n');
275 ChatLive_socket[chat_number].send('CAP REQ :twitch.tv/commands twitch.tv/tags\r\n');
276 ChatLive_socket[chat_number].send('JOIN #' + ChatLive_selectedChannel[chat_number] + '\r\n');
277 };
278
279 ChatLive_socket[chat_number].onmessage = function(data) {
280
281 var message = window.parseIRC(data.data.trim());
282
283 if (!message.command) return;
284
285 switch (message.command) {
286 case "PING":
287 ChatLive_socket[chat_number].send('PONG ' + message.params[0]);
288 break;
289 case "JOIN":
290 ChatLive_loaded[chat_number] = true;
291 var div = '&nbsp;<span class="message">' + STR_BR + STR_LOADING_CHAT +
292 (!chat_number ? Main_values.Play_selectedChannelDisplayname : PlayExtra_selectedChannelDisplayname) + ' ' + STR_LIVE + '</span>';
293
294 if (Play_ChatDelayPosition) {
295 var stringSec = STR_SECOND;
296 if (Play_controls[Play_controlsChatDelay].defaultValue > 1) stringSec = STR_SECONDS;
297
298 div += '&nbsp;<span class="message">' + STR_BR + STR_BR + STR_CHAT_DELAY + ' ' +
299 Play_controls[Play_controlsChatDelay].values[Play_controls[Play_controlsChatDelay].defaultValue] +
300 stringSec + '</span>';
301 }
302
303 ChatLive_LineAdd(div, chat_number);
304 break;
305 case "PRIVMSG":
306 ChatLive_loadChatSuccess(message, chat_number);
307 break;
308 default:
309 break;
310 }
311 };
312
313 ChatLive_CheckId[chat_number] = window.setTimeout(function() {
314 ChatLive_Check(chat_number);
315 }, 5000);
316}
318function ChatLive_Check(chat_number) {
319 if (!ChatLive_loaded[chat_number]) {
320 ChatLive_socket[chat_number].close(1000);
321 ChatLive_loadChat(chat_number);
322 }
323}
33getChat() {
34 return null;
35}

Related snippets