Skip to content
Permalink
Browse files

Add Helper Function To Send WS Request To Server

  • Loading branch information...
piavgh committed Feb 12, 2019
1 parent f5b2d5e commit 66eb9c3d5d0cd2750ec388bfaf6ef4f7a139ed7c
Showing with 7 additions and 7 deletions.
  1. +7 −7 utils/socket.js
@@ -1,13 +1,13 @@
const WebSocket = require('ws')

const ws = new WebSocket('ws://localhost:8080/socket')
import { WS_BASE_URL } from '../config'

ws.on('open', function open() {
console.log('Websocket connected')
})
const ws = new WebSocket(WS_BASE_URL)

ws.on('message', function incoming(data) {
console.log(data)
ws.on('open', function open() {
console.log('Connected to Websocket')
})

export default ws
export const sendToServer = (message) => {
ws.send(JSON.stringify(message))
}

0 comments on commit 66eb9c3

Please sign in to comment.
You can’t perform that action at this time.