import { EventEmitter } from "events" ; import { Observable } from "rx" ; import { makeBundle , makeMessage } from "../osc/utils" ; import { deltaTimeTag , OSCTimeType , MsgType } from "@supercollider/osc" ; import { Disposable } from "rx" ; /**
 * Owned by the Server, this is an object that you call .msg or .bundle on
 * to send OSC.
 *
 * The Server subscribes to this and does the actual sending.
 * You may also subscribe to this for debugging, logging or entertainment purposes.
 */ export default class SendOSC extends EventEmitter { msg ( message ) { this . emit ( "msg" , makeMessage ( message ) ) ; } param { null | Number | Array | Date } time param { Array } packets bundle ( time , packets ) { if ( typeof time === "number" && time < 10000 ) { time = deltaTimeTag ( time ) ; } this . emit ( "bundle" , makeBundle ( time , packets ) ) ; } example param { Number } delta param { Date } now deltaTimeTag ( delta , now ? ) { return deltaTimeTag ( delta , now ) ; } returns { Rx . Disposable } subscribe ( onNext , onError ? , onComplete ? ) { const msgs = Observable . fromEvent ( this , "msg" , msg => { return { type : "msg" , payload : msg , } ; } ) ; const bundles = Observable . fromEvent ( this , "bundle" , bundle => { return { type : "bundle" , payload : bundle , } ; } ) ; const combo = msgs . merge ( bundles ) ; return combo . subscribe ( onNext , onError , onComplete ) ; } }