Skip to content

Instantly share code, notes, and snippets.

@paullj
Created February 10, 2019 23:50
Show Gist options
  • Save paullj/a79b8d63502665c2af476a532ee8e369 to your computer and use it in GitHub Desktop.
Save paullj/a79b8d63502665c2af476a532ee8e369 to your computer and use it in GitHub Desktop.
import socket from './../socket'; // Doesnt work.
// This works though
// import io from 'socket.io-client'
// const socket = io();
//...
function startPath(point) {
//...
}
function continuePath(point) {
//...
}
function endPath(point) {
//...
}
socket.on('startPath', (data) => {
startPath(data);
});
socket.on('continuePath', (data) => {
continuePath(data)
});
socket.on('endPath', (data) => {
endPath(data);
});
//...
io.on('connection', function (socket) {
socket.on('startPath', function(data) {
socket.broadcast.emit('startPath', data);
});
socket.on('continuePath', function(data) {
socket.broadcast.emit('continuePath', data);
});
socket.on('endPath', function(data) {
socket.broadcast.emit('endPath', data);
});
});
import Vue from 'vue';
import VueSocketIO from 'vue-socket.io';
import * as io from 'socket.io-client';
export const SocketInstance = io('http://localhost:3000');
Vue.use(new VueSocketIO({
connection: SocketInstance
}));
export default SocketInstance;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment