Skip to content
This repository has been archived by the owner on Jul 3, 2021. It is now read-only.

Commit

Permalink
Switch to using Array.isArray due to util.isArray being deprecated. F…
Browse files Browse the repository at this point in the history
…ix null/undefined messages crashing sendChat
  • Loading branch information
thedark1337 committed Aug 25, 2015
1 parent 3a26d81 commit 83a2889
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
6 changes: 2 additions & 4 deletions lib/bufferObject.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

var util = require('util');

function BufferObject(data, getUpdate, maxAge) {
if (typeof getUpdate !== 'function') {
throw new Error('BufferObject requires an update function');
Expand Down Expand Up @@ -43,7 +41,7 @@ function BufferObject(data, getUpdate, maxAge) {
// Be sure the data is loaded
this.get();

if (util.isArray(this.data)) {
if (Array.isArray(this.data)) {
this.data.push(data);
}
},
Expand All @@ -62,7 +60,7 @@ function BufferObject(data, getUpdate, maxAge) {
// Be sure the data is loaded
this.get();

if (util.isArray(this.data) && index < this.data.length) {
if (Array.isArray(this.data) && index < this.data.length) {
this.data.splice(index, 1);
}
}
Expand Down
11 changes: 7 additions & 4 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ function receivedChatMessage(messageData) {
messageData.isFrom = function(ids, success, failure) {
if (typeof ids === 'string')
ids = [ids];
if (ids == null || !util.isArray(ids)) {
if (ids == null || !Array.isArray(ids)) {
if (typeof failure === 'function') {
failure();
}
Expand Down Expand Up @@ -1424,6 +1424,9 @@ PlugAPI.prototype.leaveBooth = function(callback) {
* @param {int} [timeout] If set, auto deletes the message after x seconds. (Needs to have modChat permission)
*/
PlugAPI.prototype.sendChat = function(msg, timeout) {
if (msg == null) {
return;
}
if (msg.length > 235 && this.multiLine) {
var lines = msg.replace(/.{235}\S*\s+/g, '$&¤').split(/\s+¤/);
for (var i = 0; i < lines.length; i++) {
Expand Down Expand Up @@ -1666,7 +1669,7 @@ PlugAPI.prototype.getLoggerSettings = function() {
PlugAPI.prototype.setLogger = function(newLogger) {
var requiredMethods = ['info', 'warn', 'warning', 'error'];

if (newLogger && typeof newLogger === 'object' && !util.isArray(newLogger)) {
if (newLogger && typeof newLogger === 'object' && !Array.isArray(newLogger)) {
for (var i in requiredMethods) {
if (!requiredMethods.hasOwnProperty(i)) continue;
if (typeof newLogger[requiredMethods[i]] !== 'function')
Expand Down Expand Up @@ -2000,7 +2003,7 @@ PlugAPI.prototype.getPlaylistMedias = function(pid, callback) {
* @returns {Boolean} If the REST request got queued
*/
PlugAPI.prototype.playlistMoveMedia = function(pid, mid, beforeMid, callback) {
if (!room.getRoomMeta().slug || !pid || !mid || (!util.isArray(mid) || (util.isArray(mid) && mid.length > 0)) || !beforeMid) return false;
if (!room.getRoomMeta().slug || !pid || !mid || (!Array.isArray(mid) || (Array.isArray(mid) && mid.length > 0)) || !beforeMid) return false;

this.getPlaylist(pid, function(playlist) {
if (playlist == null) {
Expand All @@ -2010,7 +2013,7 @@ PlugAPI.prototype.playlistMoveMedia = function(pid, mid, beforeMid, callback) {
return;
}

if (!util.isArray(mid))
if (!Array.isArray(mid))
mid = [mid];

queueREST('PUT', endpoints.PLAYLIST + '/' + pid + '/media/move', {
Expand Down

0 comments on commit 83a2889

Please sign in to comment.