index.js
function AtemPacket(msg){
		Packet.call(this);

		this.header.flags = msg[0]>>>3;
		this.header.uid = msg.readUInt16BE(2);
		this.header.fs  = msg.readUInt16BE(4);
		this.header.ls  = msg.readUInt16BE(10);

		if ((this.header.flags & flags.unknown) == flags.unknown) console.log('Unknown Packet flag!');

		if (state === ConnectionState.attempting) {
			if (this.isSync()){
				atem.state = ConnectionState.establishing;
				uid = this.header.uid;
			}
		} else
		if (state === ConnectionState.establishing){
			if (msg.length==12 && !this.isConnect()){
				atem.state = ConnectionState.open;
				clearInterval(syncInterval);
				syncInterval = setInterval(sync, 600);
			}
		}

		if (this.isConnect()) {
			//Do something
		}
		else if ((msg.length == (msg.readUInt16BE(0)&0x7FF) && this.header.uid == uid)){
			const body = msg.slice(12);

			var name, data, cmd, cmdLength, cursor=0;
			while (cursor < body.length-1) {
				cmdLength = body.readUInt16BE(cursor);
				name = body.toString('utf8', cursor+4, cursor+8);
				data = body.slice(cursor+8, cursor+cmdLength);
				cmd = new Command(name, data);
				this.body.commands.push(cmd);
				cursor += cmdLength;

				/**
				 * @event Device#rawCommand
				 * @type {Command}
				 */

				// todo: check foreign sequence number, to prevent the event emitter
				// from emitting the same message twice.
				atem.emit('rawCommand', cmd);
				atem.emit(cmd.name, cmd.data);
			}
		}
		else if (msg.length != (msg.readUInt16BE(0)&0x7FF)) {
			const err = new Error('Message length mismatch');
			self.emit('error', err);
		} else {
			const err2 = new Error('UID mismatch');
			self.emit('error', err2);
		}
	}
function AtemPacket(msg){
		Packet.call(this);

		this.header.flags = msg[0]>>>3;
		this.header.uid = msg.readUInt16BE(2);
		this.header.fs  = msg.readUInt16BE(4);
		this.header.ls  = msg.readUInt16BE(10);

		if ((this.header.flags & flags.unknown) == flags.unknown) console.log('Unknown Packet flag!');

		if (state === ConnectionState.attempting) {
			if (this.isSync()){
				atem.state = ConnectionState.establishing;
				uid = this.header.uid;
			}
		} else
		if (state === ConnectionState.establishing){
			if (msg.length==12 && !this.isConnect()){
				atem.state = ConnectionState.open;
				clearInterval(syncInterval);
				syncInterval = setInterval(sync, 600);
			}
		}

		if (this.isConnect()) {
			//Do something
		}
		else if ((msg.length == (msg.readUInt16BE(0)&0x7FF) && this.header.uid == uid)){
			const body = msg.slice(12);

			var name, data, cmd, cmdLength, cursor=0;
			while (cursor < body.length-1) {
				cmdLength = body.readUInt16BE(cursor);
				name = body.toString('utf8', cursor+4, cursor+8);
				data = body.slice(cursor+8, cursor+cmdLength);
				cmd = new Command(name, data);
				this.body.commands.push(cmd);
				cursor += cmdLength;

				/**
				 * @event Device#rawCommand
				 * @type {Command}
				 */

				// todo: check foreign sequence number, to prevent the event emitter
				// from emitting the same message twice.
				atem.emit('rawCommand', cmd);
				atem.emit(cmd.name, cmd.data);
			}
		}
		else if (msg.length != (msg.readUInt16BE(0)&0x7FF)) {
			const err = new Error('Message length mismatch');
			self.emit('error', err);
		} else {
			const err2 = new Error('UID mismatch');
			self.emit('error', err2);
		}
	}
function AtemPacket ( msg ) { Packet . call ( this ) ; this . header . flags = msg [ 0 ] >>> 3 ; this . header . uid = msg . readUInt16BE ( 2 ) ; this . header . fs = msg . readUInt16BE ( 4 ) ; this . header . ls = msg . readUInt16BE ( 10 ) ; if ( ( this . header . flags & flags . unknown ) == flags . unknown ) console . log ( 'Unknown Packet flag!' ) ; if ( state === ConnectionState . attempting ) { if ( this . isSync ( ) ) { atem . state = ConnectionState . establishing ; uid = this . header . uid ; } } else if ( state === ConnectionState . establishing ) { if ( msg . length == 12 && ! this . isConnect ( ) ) { atem . state = ConnectionState . open ; clearInterval ( syncInterval ) ; syncInterval = setInterval ( sync , 600 ) ; } } if ( this . isConnect ( ) ) { //Do something } else if ( ( msg . length == ( msg . readUInt16BE ( 0 ) & 0x7FF ) && this . header . uid == uid ) ) { const body = msg . slice ( 12 ) ; var name , data , cmd , cmdLength , cursor = 0 ; while ( cursor < body . length - 1 ) { cmdLength = body . readUInt16BE ( cursor ) ; name = body . toString ( 'utf8' , cursor + 4 , cursor + 8 ) ; data = body . slice ( cursor + 8 , cursor + cmdLength ) ; cmd = new Command ( name , data ) ; this . body . commands . push ( cmd ) ; cursor += cmdLength ; /**
				 * @event Device#rawCommand
				 * @type {Command}
				 */ // todo: check foreign sequence number, to prevent the event emitter // from emitting the same message twice. atem . emit ( 'rawCommand' , cmd ) ; atem . emit ( cmd . name , cmd . data ) ; } } else if ( msg . length != ( msg . readUInt16BE ( 0 ) & 0x7FF ) ) { const err = new Error ( 'Message length mismatch' ) ; self . emit ( 'error' , err ) ; } else { const err2 = new Error ( 'UID mismatch' ) ; self . emit ( 'error' , err2 ) ; } }
Parse an ATEM UDP message

@constructor AtemPacket
@augments Packet
@classdesc Used to parse an UDP message from the Atem

@param {Buffer} msg The message to parse
Parse an ATEM UDP message