Swift, how to play sound again and again by pressing a button - audio

I'm in way of making my first piano app and I'm in trouble.
How can I play sound again and again when I press a button?
For example, I can play C4 sound when I press the button.
but when I want to play C4 sound again, I have to wait till the sound is completely gone.
I want to play C4 sound as many times as I press the button.
Here is my "view controller.swift"
Thanks in advance.
import UIKit
import AVFoundation
class ViewController: UIViewController {
// make sure to add this sound to your project
var pianoSoundC4 = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("PianoC4", ofType: "m4a")!)
var audioPlayerC4 = AVAudioPlayer()
var pianoSoundCS = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("PianoC#", ofType: "m4a")!)
var audioPlayerCS = AVAudioPlayer()
var pianoSoundD = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("PianoD", ofType: "m4a")!)
var audioPlayerD = AVAudioPlayer()
var pianoSoundDS = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("PianoD#", ofType: "m4a")!)
var audioPlayerDS = AVAudioPlayer()
var pianoSoundE = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("PianoE", ofType: "m4a")!)
var audioPlayerE = AVAudioPlayer()
var pianoSoundF = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("PianoF", ofType: "m4a")!)
var audioPlayerF = AVAudioPlayer()
var pianoSoundFS = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("PianoF#", ofType: "m4a")!)
var audioPlayerFS = AVAudioPlayer()
var pianoSoundG = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("PianoG", ofType: "m4a")!)
var audioPlayerG = AVAudioPlayer()
var pianoSoundGS = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("PianoG#", ofType: "m4a")!)
var audioPlayerGS = AVAudioPlayer()
var pianoSoundA = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("PianoA", ofType: "m4a")!)
var audioPlayerA = AVAudioPlayer()
var pianoSoundAS = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("PianoA#", ofType: "m4a")!)
var audioPlayerAS = AVAudioPlayer()
var pianoSoundB = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("PianoB", ofType: "m4a")!)
var audioPlayerB = AVAudioPlayer()
var pianoSoundC5 = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("PianoC5", ofType: "m4a")!)
var audioPlayerC5 = AVAudioPlayer()
override func viewDidLoad() {
super.viewDidLoad()
audioPlayerC4 = AVAudioPlayer(contentsOfURL: pianoSoundC4, error: nil)
audioPlayerC4.prepareToPlay()
audioPlayerCS = AVAudioPlayer(contentsOfURL: pianoSoundCS, error: nil)
audioPlayerCS.prepareToPlay()
audioPlayerD = AVAudioPlayer(contentsOfURL: pianoSoundD, error: nil)
audioPlayerD.prepareToPlay()
audioPlayerDS = AVAudioPlayer(contentsOfURL: pianoSoundDS, error: nil)
audioPlayerDS.prepareToPlay()
audioPlayerE = AVAudioPlayer(contentsOfURL: pianoSoundE, error: nil)
audioPlayerE.prepareToPlay()
audioPlayerF = AVAudioPlayer(contentsOfURL: pianoSoundF, error: nil)
audioPlayerF.prepareToPlay()
audioPlayerFS = AVAudioPlayer(contentsOfURL: pianoSoundFS, error: nil)
audioPlayerFS.prepareToPlay()
audioPlayerG = AVAudioPlayer(contentsOfURL: pianoSoundG, error: nil)
audioPlayerG.prepareToPlay()
audioPlayerGS = AVAudioPlayer(contentsOfURL: pianoSoundGS, error: nil)
audioPlayerGS.prepareToPlay()
audioPlayerA = AVAudioPlayer(contentsOfURL: pianoSoundA, error: nil)
audioPlayerA.prepareToPlay()
audioPlayerAS = AVAudioPlayer(contentsOfURL: pianoSoundAS, error: nil)
audioPlayerAS.prepareToPlay()
audioPlayerB = AVAudioPlayer(contentsOfURL: pianoSoundB, error: nil)
audioPlayerB.prepareToPlay()
audioPlayerC5 = AVAudioPlayer(contentsOfURL: pianoSoundC5, error: nil)
audioPlayerC5.prepareToPlay()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
#IBAction func C4(sender: UIButton) {
audioPlayerC4.play()
}
#IBAction func CS(sender: UIButton) {
audioPlayerCS.play()
}
#IBAction func D(sender: UIButton) {
audioPlayerD.play()
}
#IBAction func DS(sender: UIButton) {
audioPlayerDS.play()
}
#IBAction func E(sender: UIButton) {
audioPlayerE.play()
}
#IBAction func F(sender: UIButton) {
audioPlayerF.play()
}
#IBAction func FS(sender: UIButton) {
audioPlayerFS.play()
}
#IBAction func G(sender: UIButton) {
audioPlayerG.play()
}
#IBAction func GS(sender: UIButton) {
audioPlayerGS.play()
}
#IBAction func A(sender: UIButton) {
audioPlayerA.play()
}
#IBAction func AS(sender: UIButton) {
audioPlayerAS.play()
}
#IBAction func B(sender: UIButton) {
audioPlayerB.play()
}
#IBAction func C5(sender: UIButton) {
audioPlayerC5.play()
}

You have to stop the sound before you can play it again. A good discussion here:
Swift - Have an audio repeat, but it plays in intervals?

Related

Web Audio - Oscillator AnalyserNode

I'm trying to add AnalyserNode and visualize the output sound to a web audio example that I made but I can't figure out how. I think I am not passing the right source to the analyser (?)
Here for the full code : https://jsfiddle.net/kepin95043/1ub0sjo3/
<script>
var fs = 2000;
var gain = 0.2;
class Sound {
constructor(context) {
this.context = context;
}
init() {
this.oscillator = this.context.createOscillator();
this.oscillator.frequency.value = fs;
this.gainNode = this.context.createGain();
this.oscillator.connect(this.gainNode);
this.gainNode.connect(this.context.destination);
}
play(value) {
this.init();
this.gainNode.gain.setValueAtTime(gain, this.context.currentTime);
this.oscillator.start();
}
stop() {
this.gainNode.gain.exponentialRampToValueAtTime(0.001, this.context.currentTime + 1);
this.oscillator.stop(this.context.currentTime + 1);
}
}
var context = new AudioContext();
var sound = new Sound(context);
sound.init();
var wave = 'sine';
var state = 'paused';
var waveSelectors = document.querySelectorAll('.waveform');
var playBtn = document.querySelector('#play');
var container = document.querySelector('.container');
waveSelectors.forEach(function(button) {
button.addEventListener('click', function() {
cleanClass('active');
wave = button.dataset.wave;
sound.oscillator.type = wave;
button.classList.add('active');
})
})
playBtn.addEventListener('click', function() {
context.resume().then(() => {
console.log('Playback resumed successfully');
});
if (playBtn.text == 'Play') {
sound.play();
sound.oscillator.type = wave;
playBtn.text = 'Pause';
} else {
sound.stop();
playBtn.text = 'Play';
}
})
function cleanClass(rclass) {
waveSelectors.forEach(function(button) {
button.classList.remove(rclass);
})
}
function changeFs(val) {
fs = val;
var output = document.getElementById("fsValue");
output.innerHTML = val;
sound.stop();
sound.play();
console.log(val);
};
function changeGain(val) {
gain = val;
var output = document.getElementById("gainValue");
output.innerHTML = val;
sound.stop();
sound.play();
console.log(val);
};
var masterGain;
masterGain = context.createGain();
masterGain.connect(context.destination);
// analyser
var analyser = context.createAnalyser();
masterGain.connect(analyser);
var waveform = new Float32Array(analyser.frequencyBinCount);
analyser.getFloatTimeDomainData(waveform);
(function updateWaveform() {
requestAnimationFrame(updateWaveform);
analyser.getFloatTimeDomainData(waveform);
}());
var spectrum = new Uint8Array(analyser.frequencyBinCount);
(function updateSpectrum() {
requestAnimationFrame(updateSpectrum);
analyser.getByteFrequencyData(spectrum);
}());
// oscilloscope
var scopeCanvas = document.getElementById('canvas');
scopeCanvas.width = waveform.length;
//scopeCanvas.height = 200;
scopeCanvas.height = scopeCanvas.width * 0.33;
var scopeContext = scopeCanvas.getContext('2d');
(function drawOscilloscope() {
requestAnimationFrame(drawOscilloscope);
scopeContext.clearRect(0, 0, scopeCanvas.width, scopeCanvas.height);
scopeContext.strokeStyle="white"; // Green path
scopeContext.beginPath();
for (var i = 0; i < waveform.length; i++) {
var x = i;
var y = (0.5 + waveform[i] / 2) * scopeCanvas.height;
if (i === 0) {
scopeContext.moveTo(x, y);
} else {
scopeContext.lineTo(x, y);
}
}
scopeContext.stroke();
}());
</script>
Could anyone help me to identify what I'm doing wrong?
Thank in advance!
PS: Open it with Firefox. Does not work on Chromium based browsers for me.
Here is a working example: https://codepen.io/dennisgaebel/pen/YEwLaL
You create a Sound object and also a masterGain that is connected to your AnalyserNode. But I don't see where the sound ever connects to the masterGain. Without that, your analyser node just gets silence.
Here is the full working script code:
var fs = 2000;
var gain = 0.2;
class Sound {
constructor(context) {
this.context = context;
}
init() {
this.oscillator = this.context.createOscillator();
this.oscillator.frequency.value = fs;
this.gainNode = this.context.createGain();
this.oscillator.connect(this.gainNode);
this.gainNode.connect(this.context.destination);
}
play(value) {
this.init();
this.gainNode.gain.setValueAtTime(gain, this.context.currentTime);
this.oscillator.start();
// connect analyser to the gainedSource
this.gainNode.connect(analyser);
// for the non gainedSource
//this.gainNode.connect(analyser);
}
stop() {
this.gainNode.gain.exponentialRampToValueAtTime(0.001, this.context.currentTime + 1);
this.oscillator.stop(this.context.currentTime + 1);
}
}
var context = new AudioContext();
var sound = new Sound(context);
sound.init();
var wave = 'sine';
var state = 'paused';
var waveSelectors = document.querySelectorAll('.waveform');
var playBtn = document.querySelector('#play');
var container = document.querySelector('.container');
waveSelectors.forEach(function(button) {
button.addEventListener('click', function() {
cleanClass('active');
wave = button.dataset.wave;
sound.oscillator.type = wave;
button.classList.add('active');
})
})
playBtn.addEventListener('click', function() {
context.resume().then(() => {
console.log('Playback resumed successfully');
});
if (playBtn.text == 'Play') {
sound.play();
sound.oscillator.type = wave;
playBtn.text = 'Pause';
} else {
sound.stop();
playBtn.text = 'Play';
}
})
function cleanClass(rclass) {
waveSelectors.forEach(function(button) {
button.classList.remove(rclass);
})
}
function changeFs(val) {
fs = val;
var output = document.getElementById("fsValue");
output.innerHTML = val;
sound.stop();
sound.play();
console.log(val);
};
function changeGain(val) {
gain = val;
var output = document.getElementById("gainValue");
output.innerHTML = val;
sound.stop();
sound.play();
console.log(val);
};
// analyser node
var analyser = context.createAnalyser();
var waveform = new Float32Array(analyser.frequencyBinCount);
analyser.getFloatTimeDomainData(waveform);
(function updateWaveform() {
requestAnimationFrame(updateWaveform);
analyser.getFloatTimeDomainData(waveform);
}());
var spectrum = new Uint8Array(analyser.frequencyBinCount);
(function updateSpectrum() {
requestAnimationFrame(updateSpectrum);
analyser.getByteFrequencyData(spectrum);
}());
// oscilloscope
var scopeCanvas = document.getElementById('canvas');
scopeCanvas.width = waveform.length;
scopeCanvas.height = scopeCanvas.width * 0.33;
var scopeContext = scopeCanvas.getContext('2d');
(function drawOscilloscope() {
requestAnimationFrame(drawOscilloscope);
scopeContext.clearRect(0, 0, scopeCanvas.width, scopeCanvas.height);
scopeContext.strokeStyle = "white"; // Green path
scopeContext.beginPath();
for (var i = 0; i < waveform.length; i++) {
var x = i;
var y = (0.5 + waveform[i] / 2) * scopeCanvas.height;
if (i === 0) {
scopeContext.moveTo(x, y);
} else {
scopeContext.lineTo(x, y);
}
}
scopeContext.stroke();
}());

Cannot require a class in NodeJs?

I have two files:
mysqlDAOFactory.js:
var mysql = require('mysql');
var mysqlUserDAO = require('./mysqlUserDAO');
var mysqlSessionDAO = require('./mysqlSessionDAO');
class mysqlDAOFactory {
static createConnection() {
var connection = mysql.createConnection({
host:'localhost',
user:'root',
password:'',
database:'QASys'
});
return connection;
}
static getDbInstance() {
return mysql;
}
getUserDAO() {
return new mysqlUserDAO();
}
getSessionDAO() {
return new mysqlSessionDAO();
}
}
module.exports = mysqlDAOFactory;
mysqlUserDAO.js:
var mysqlDAOFactory = require('./mysqlDAOFactory.js');
var bcrypt = require('bcryptjs');
var preparedStatements = require('./preparedStatements');
class mysqlUserDAO {
constructor() {
this.connection = mysqlDAOFactory.createConnection();
this.mysql = mysqlDAOFactory.getDbInstance();
}
}
module.exports = mysqlUserDAO;
When I run the file test.js:
var mysqlDAOFactory = require('./mysqlDAOFactory.js');
var UserDAO = mysqlDAOFactory.getUserDAO();
the program is not recognize the variable mysqlDAOFactory in the constructor of class in mysqlUserDAO.js although I require this variable before.
Can anyone explain to me why this happened?
results in chrome debugger tool
I have reviewed your cod and you made a mistake of circular dependencies due to that you fail to run a code.
I have temporary comment mysqlSession file because you did not post MySQL session file.
Please see the running example then please review link as well.
https://repl.it/#DipakC/SO-50542396cannot-require-a-class-in-nodejs
test.js:
//var mysqlDAOFactory = require('./mysqlDAOFactory');
const mysqlUserDAO = require("./mysqlUserDAO");
let objMysqlUserDAO = new mysqlUserDAO();
console.log("---- ---- ----");
console.log(objMysqlUserDAO);
console.log("---- ---- ----");
mysqlUserDAO.js
var mysqlDAOFactory = require('./mysqlDAOFactory');
var bcrypt = require('bcryptjs');
class mysqlUserDAO {
constructor() {
this.connection = mysqlDAOFactory.createConnection();
this.mysql = mysqlDAOFactory.getDbInstance();
}
}
module.exports = mysqlUserDAO;
mysqlDAOFactory.js
var mysql = require('mysql');
var mysqlUserDAO = require('./mysqlUserDAO');
//var mysqlSessionDAO = require('./mysqlSessionDAO');
class mysqlDAOFactory {
static createConnection() {
var connection = mysql.createConnection({
host:'localhost',
user:'root',
password:'',
database:'QASys'
});
return connection;
}
static getDbInstance() {
return mysql;
}
static getUserDAO() {
return new mysqlUserDAO();
}
/* getSessionDAO() {
return new mysqlSessionDAO();
} */
}
module.exports = mysqlDAOFactory;

NodeJS Server Not Receiving Socket.emit() from Swift Client

I am trying to put together a very simply multiplayer tic-tac-toe game in swift with a NodeJS backend. When I try and do socket.emit() from my swift client, however, the server does not recognize it.
Client Code:
SocketIOManager:
import UIKit
class SocketIOManager: NSObject {
static let sharedInstance = SocketIOManager()
override init() {
super.init()
}
var socket: SocketIOClient = SocketIOClient(socketURL: NSURL(string: "http://10.0.1.30:2000")! as URL)
func connectToServer(completionHandler: #escaping (_ userList: [[String: AnyObject]]?) -> Void) {
socket.emit("connectUser")
socket.on("userList") { ( dataArray, ack) -> Void in
completionHandler(_: dataArray[0] as? [[String: AnyObject]])
}
}
func establishConnection() {
socket.connect()
}
func closeConnection() {
socket.disconnect()
}
}
Game Scene:
import SpriteKit
class GameScene: SKScene {
let screenSize = UIScreen.main.bounds
var board = SKSpriteNode(imageNamed: "Board.png")
var users = [[String: AnyObject]]()
override func didMove(to view: SKView) {
SocketIOManager.sharedInstance.connectToServer(completionHandler: { (userList) -> Void in
DispatchQueue.main.async(execute: { () -> Void in
if userList != nil {
self.users = userList!
}
})
})
board.size = CGSize(width: screenSize.width * 2/3, height: screenSize.width * 2/3)
board.position = CGPoint(x: screenSize.width/2, y: screenSize.height/2)
self.backgroundColor = UIColor.white
self.addChild(board)
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
}
override func update(_ currentTime: TimeInterval) {
}
}
Server Code:
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var userList = [];
app.get('/', function(req, res){
res.send('<h1>Tic-Tac-Toe Server</h1>');
});
http.listen(2000, function(){
console.log('Listening on *:2000');
});
io.on('connection', function(clientSocket) {
console.log('a user connected');
clientSocket.on('disconnect', function() {
console.log('user disconnected');
});
clientSocket.on('connectUser', function() {
console.log('User with id ' + clientSocket.id + ' connected');
var userInfo = {};
var foundUser = false;
for (var i = 0; i < userList.length; i++) {
if (userList[i]["id"] == clientSocket.id) {
userInfo = userList[i];
foundUser = true;
break;
}
}
if (!foundUser) {
userInfo["id"] = clientSocket.id;
userList.push(userInfo);
}
io.emit("userList", userList);
io.emit("userConnectUpdate", userInfo);
});
});
The message in particular that is not working is the "connectUser" one, but I have tried to create others to test it and none of them work. It appears as if the server never receives them.
Since you are not using a https (http://10.0.1.30:2000), probably you forgot to set Allow Arbitrary Loads to YES in your Info.plist file at your iOS project:
Anyways I've built a basic example that's working:
Server side:
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var port = 5000;
io.on('connection', function(socket) {
socket.on('message', function(data) {
console.log('client sent a message: ' + data);
});
});
http.listen(port, function() {
console.log('server up and running at %s port', port);
});
Client side:
import UIKit
import SocketIO
class ViewController: UIViewController {
let socket = SocketIOClient(socketURL: URL(string: "http://localhost:5000")!)
override func viewDidLoad() {
super.viewDidLoad()
socket.on("connect") { data, ack in
print("socket connected")
self.socket.emit("message", "Hello dear server from iOS.")
}
socket.connect()
}
}
Logs from Server

Wait for async method before segue

I have a button and when I press it I´m calling an Async function:
func check(url : String){
let url = NSURL(string: url)
print("Checking")
dispatch_async(dispatch_get_main_queue(), {
let task = NSURLSession.sharedSession().dataTaskWithURL(url!) {(data, response, error) in
if error == nil {
self.isWorking = true
}
else{
self.isWorking = false
}
}
}
task.resume()
})
}
So when I press my button I do the following:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!){
let web = segue.destinationViewController as! ViewController()
check(url)
dispatch_async(dispatch_get_main_queue(), {
if (isWorking){
// Do stuff
}
})
}
The problem is that isWorking is called before the check method is completed.
How can I make sure that check is completed before I make my check for isWorking?
You could use a "completion handler":
func check(url : String, completion: (isWorking: Bool)->()) {
let url = NSURL(string: url)
print("Checking")
let task = NSURLSession.sharedSession().dataTaskWithURL(url!) {(data, response, error) in
if error == nil {
completion(isWorking: true)
}
else{
completion(isWorking: false)
}
}
task.resume()
}
And you call it like this, with a trailing closure:
check(url) { (isWorking) in
if isWorking {
// do stuff
} else {
// not working
}
}
This will do the job:
import UIKit
class AnyViewController: UIViewController
{
var isWorking = false
func check(url : String)
{
let url = NSURL(string: url)
print("Checking")
let task = NSURLSession.sharedSession().dataTaskWithURL(url!) {(data, response, error) in
if error == nil
{
self.performSegueWithIdentifier("mySegueID", sender: nil)
}
else{
self.isWorking = false
}
}
task.resume()
}
}
You can post a notification to a listener to perform the segue only when the task is complete with NSNotificationCenter.defaultCenter().postNotificationName("name", object: nil):
override func viewDidLoad() {
super.viewDidLoad()
// Register a notification listener
NSNotificationCenter.defaultCenter().addObserver(self, selector: "customSegue:", name:"segue", object: nil)
}
func customSegue(notification: NSNotification){
// Do stuff
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!){
check(url)
}
func check(url : String){
let url = NSURL(string: url)
print("Checking")
dispatch_async(dispatch_get_main_queue(), {
let task = NSURLSession.sharedSession().dataTaskWithURL(url!) {(data, response, error) in
if error == nil {
self.isWorking = true
// Send a notification to the listener to perform stuff
NSNotificationCenter.defaultCenter().postNotificationName("segue", object: nil)
}
else{
self.isWorking = false
}
}
}
task.resume()
})
}
This way the code in customSegue func will only be executed when error == nil

how to go from net module to ws module

here is my current code
'use strict';
var _ = require('underscore'),
util = require('util'),
events = require('events'),
net = require('net'),
colors = require('colors');
// Chatango Socket connection handler, for both Rooms and PM
// Available events: onconnect, data, error, timeout, close, write ( Note: exceptions must be handled! )
function Socket(host, port)
{
this._host = host;
this._port = port || 443;
this._socket = new net.Socket();
this._pingTask = false;
this._connected = false;
this._firstCommand = true;
this._writeLock = false;
this._writeBuffer = [];
this._buffer = '';
this.connect();
}
util.inherits(Socket, events.EventEmitter);
Socket.prototype.connect = function()
{
if(this._socket._connecting) return;
var self = this;
if(this._socket.destroyed){
var reconnecting = true;
console.log('[SOCKET] reconnecting to '+this._host+':'+this._port);
}else{
var reconnecting = false;
console.log('[SOCKET] connecting to '+this._host+':'+this._port);
}
this._writeLock = true;
if(this._socket._events.connect){
this._socket.connect(this._port, this._host);
}else{
this._socket.connect(this._port, this._host, function() {
self._connected = true;
self._writeLock = false;
self._pingTask = setInterval(function() {
if(self._connected) {
self.write(['']);
}
}, 30000);
self.emit('onconnect');
});
}
if(reconnecting) return;
this._socket.on('data', function(data) {
var buffer = data.toString('utf8');
if(buffer.substr(-1) !== '\x00')
{
self._buffer += buffer;
}
else
{
if(self._buffer != '')
{
buffer = self._buffer + buffer;
self._buffer = '';
}
var messages = buffer.split('\x00');
_.each(messages, function(message){
message = message.replace(/(\r|\n)/g, '');
if(message !== '')
self.emit('data', message);
});
}
});
this._socket.on('error', function(exception) {
self.emit('error', exception);
});
this._socket.on('timeout', function(exception) {
self.emit('timeout', exception);
});
this._socket.on('close', function() {
self._connected = false;
self._writeBuffer = [];
self._writeLock = false;
self._buffer = '';
self._firstCommand = true;
clearInterval(self._pingTask);
self.emit('close');
});
}
Socket.prototype.disconnect = function(){
this._socket.destroy();
}
Socket.prototype.setWriteLock = function(bool) {
this._writeLock = _.isBoolean(bool) && bool;
}
Socket.prototype.write = function(data) {
if(this._connected)
{
if(this._firstCommand)
{
var terminator = '\x00';
this._firstCommand = false;
}
else
var terminator = '\r\n\x00';
if(this._writeLock)
this._writeBuffer.push(data);
else
{
_.each(this._writeBuffer, function(value){
this.write(value);
}.bind(this));
if(data)
this.emit('write', data.join(':'));
this._socket.write(data.join(':') + terminator);
}
}
}
exports.Instance = Socket;
as you can see i am using the net module
i want to change to the ws module and do this using websockets https://github.com/einaros/ws
i've read all kinds of examples but none of them give me what i want
the lib im using is
https://github.com/MakuraYami/derplib

Resources