ld31-space-diggers/node_modules/browser-sync/node_modules/browser-sync-client/lib/socket.js
Ruben Müller 760c1838ed Add game
2014-12-07 20:57:49 +01:00

40 lines
720 B
JavaScript

"use strict";
/**
* @type {{emit: emit, on: on}}
*/
var BS = window.___browserSync___ || {};
exports.socket = BS.socket || {
emit: function(){},
on: function(){}
};
/**
* @returns {string}
*/
exports.getPath = function () {
return window.location.pathname;
};
/**
* Alias for socket.emit
* @param name
* @param data
*/
exports.emit = function (name, data) {
var socket = exports.socket;
if (socket && socket.emit) {
// send relative path of where the event is sent
data.url = exports.getPath();
socket.emit(name, data);
}
};
/**
* Alias for socket.on
* @param name
* @param func
*/
exports.on = function (name, func) {
exports.socket.on(name, func);
};