diff --git a/lib/ClientConnection.js b/lib/ClientConnection.js index 82810db..c4005e3 100644 --- a/lib/ClientConnection.js +++ b/lib/ClientConnection.js @@ -12,7 +12,7 @@ const OutgoingStreamBridge = require("./OutgoingStreamBridge.js") /** * @typedef {Object} ClientConnectionEvents * @property {(self: ClientConnection) => void} connected - * @property {(self: ClientConnection) => void} disconnected + * @property {(self: ClientConnection, errorCode: Number) => void} disconnected * @property {(self: ClientConnection) => void} stopped * @property {(self: ClientConnection, name: string, cmd: any[]) => void} cmd */ @@ -66,27 +66,30 @@ class ClientConnection extends Emitter this.emit("cmd", this, name, cmd); } }; - - this.ondisconnected = () => + + this.ondisconnected = (/** @type {Number} */errorCode) => { //Check if already stopped if (this.stopped) //Do nothing return; - + //Emit event - this.emit("disconnected", this); + this.emit("disconnected", this, errorCode); //Stop us this.stop(); }; } + /** + * @returns {Number} + */ connect( /** @type {string} */ server, /** @type {number} */ port, /** @type {string} */ app) { - this.connection.Connect(server, port, app); + return this.connection.Connect(server, port, app); } @@ -96,6 +99,7 @@ class ClientConnection extends Emitter const [,streamId] = await new Promise((resolve,reject) => this.connection.CreateStream({resolve,reject})); //Send publish cmd for stream this.connection.Publish(streamId, name); + //Create new outgoingstream const outgoingStream = new OutgoingStreamBridge(streamId, this.connection); diff --git a/lib/ErrorCode.js b/lib/ErrorCode.js new file mode 100644 index 0000000..f699af7 --- /dev/null +++ b/lib/ErrorCode.js @@ -0,0 +1,15 @@ + +const RtmpClientConnectionErrorCode = Object.freeze({ + NoError: 0, + Generic : 1, + FailedToResolveURL : 2, + GetSockOptError : 3, + FailedToConnectSocket : 4, + ConnectCommandFailed : 5, + FailedToParseData : 6, + PeerClosed : 7, + ReadError : 8, + PollError : 9 + }); + +module.exports = RtmpClientConnectionErrorCode; diff --git a/lib/RTMPServer.js b/lib/RTMPServer.js index 43e574e..ddaa7f4 100644 --- a/lib/RTMPServer.js +++ b/lib/RTMPServer.js @@ -10,6 +10,7 @@ const ClientConnection = require("./ClientConnection.js"); const RTMPServer = {}; RTMPServer.NetStream = require("./Status.js").NetStream; RTMPServer.NetConnection = require("./Status.js").NetConnection; +RTMPServer.NetConnectionErrorCode = require("./ErrorCode.js"); //INitialize Stuff Native.RTMPServerModule.Initialize(); diff --git a/src/RTMPClientConnectionImpl.i b/src/RTMPClientConnectionImpl.i index d0b9680..b4fc867 100644 --- a/src/RTMPClientConnectionImpl.i +++ b/src/RTMPClientConnectionImpl.i @@ -14,9 +14,9 @@ public: persistent = std::make_shared>(object); } - void Connect(const char* server,int port, const char* app) + RTMPClientConnection::ErrorCode Connect(const char* server,int port, const char* app) { - RTMPClientConnection::Connect(server, port, app, this); + return RTMPClientConnection::Connect(server, port, app, this); } void CreateStream(v8::Local promise) @@ -36,6 +36,7 @@ public: RTMPClientConnection::SendCommand(id, L"publish", nullptr, new AMFString(parser.GetWChar())); } + void onConnected(RTMPClientConnection* conn) override { Log("-RTMPClientConnectionImpl::onConnected()\n"); @@ -48,7 +49,7 @@ public: }); } - void onDisconnected(RTMPClientConnection* conn) override + void onDisconnected(RTMPClientConnection* conn, ErrorCode code) override { Log("-RTMPClientConnectionImpl::onDisconnected()\n"); @@ -56,7 +57,10 @@ public: RTMPServerModule::Async([=,cloned=persistent](){ Nan::HandleScope scope; //Call object method with arguments - MakeCallback(cloned, "ondisconnected"); + v8::Local argv[1]; + argv[0] = Nan::New(static_cast(code)); + + MakeCallback(cloned, "ondisconnected", 1, argv); }); } @@ -126,13 +130,33 @@ private: %} +%nodefaultctor RTMPClientConnection; +class RTMPClientConnection +{ +public: + enum class ErrorCode + { + NoError = 0, + Generic = 1, + FailedToResolveURL = 2, + GetSockOptError = 3, + FailedToConnectSocket = 4, + ConnectCommandFailed = 5, + FailedToParseData = 6, + PeerClosed = 7, + ReadError = 8, + PollError = 9 + }; +}; + + %nodefaultctor RTMPClientConnectionImpl; class RTMPClientConnectionImpl : public RTMPMediaStreamListener { public: RTMPClientConnectionImpl(v8::Local object); - void Connect(const char* server,int port, const char* app); + RTMPClientConnection::ErrorCode Connect(const char* server,int port, const char* app); void CreateStream(v8::Local object); void Publish(DWORD streamId,v8::Local url); void DeleteStream(DWORD streamId, v8::Local object); diff --git a/src/rtmp-server.d.ts b/src/rtmp-server.d.ts index 75c47fc..f02c307 100644 --- a/src/rtmp-server.d.ts +++ b/src/rtmp-server.d.ts @@ -424,7 +424,7 @@ export class RTMPClientConnectionImpl extends RTMPMediaStreamListener { constructor(object: any); - Connect(server: string, port: number, app: string): void; + Connect(server: string, port: number, app: string): number; CreateStream(object: any): void; diff --git a/src/rtmp-server_wrap.cxx b/src/rtmp-server_wrap.cxx index 5c3d65d..5923fbe 100644 --- a/src/rtmp-server_wrap.cxx +++ b/src/rtmp-server_wrap.cxx @@ -1351,39 +1351,40 @@ fail: ; #define SWIGTYPE_p_OutgoingStreamBridgeShared swig_types[10] #define SWIGTYPE_p_Properties swig_types[11] #define SWIGTYPE_p_RTMPApplicationImpl swig_types[12] -#define SWIGTYPE_p_RTMPClientConnectionImpl swig_types[13] -#define SWIGTYPE_p_RTMPMediaStreamListener swig_types[14] -#define SWIGTYPE_p_RTMPNetConnection swig_types[15] -#define SWIGTYPE_p_RTMPNetConnectionImpl swig_types[16] -#define SWIGTYPE_p_RTMPNetConnectionImplShared swig_types[17] -#define SWIGTYPE_p_RTMPNetConnectionShared swig_types[18] -#define SWIGTYPE_p_RTMPNetStream swig_types[19] -#define SWIGTYPE_p_RTMPNetStreamImpl swig_types[20] -#define SWIGTYPE_p_RTMPNetStreamImplShared swig_types[21] -#define SWIGTYPE_p_RTMPNetStreamShared swig_types[22] -#define SWIGTYPE_p_RTMPServerFacade swig_types[23] -#define SWIGTYPE_p_RTMPServerModule swig_types[24] -#define SWIGTYPE_p_RTPIncomingMediaStream swig_types[25] -#define SWIGTYPE_p_RTPIncomingMediaStreamShared swig_types[26] -#define SWIGTYPE_p_RTPReceiver swig_types[27] -#define SWIGTYPE_p_RTPReceiverShared swig_types[28] -#define SWIGTYPE_p_TimeService swig_types[29] -#define SWIGTYPE_p_VideoOrientation swig_types[30] -#define SWIGTYPE_p_char swig_types[31] -#define SWIGTYPE_p_int swig_types[32] -#define SWIGTYPE_p_long_long swig_types[33] -#define SWIGTYPE_p_short swig_types[34] -#define SWIGTYPE_p_signed_char swig_types[35] -#define SWIGTYPE_p_std__string swig_types[36] -#define SWIGTYPE_p_std__vectorT_Properties_t swig_types[37] -#define SWIGTYPE_p_unsigned_char swig_types[38] -#define SWIGTYPE_p_unsigned_int swig_types[39] -#define SWIGTYPE_p_unsigned_long_long swig_types[40] -#define SWIGTYPE_p_unsigned_short swig_types[41] -#define SWIGTYPE_p_v8__LocalT_v8__Object_t swig_types[42] -#define SWIGTYPE_p_void swig_types[43] -static swig_type_info *swig_types[45]; -static swig_module_info swig_module = {swig_types, 44, 0, 0, 0, 0}; +#define SWIGTYPE_p_RTMPClientConnection swig_types[13] +#define SWIGTYPE_p_RTMPClientConnectionImpl swig_types[14] +#define SWIGTYPE_p_RTMPMediaStreamListener swig_types[15] +#define SWIGTYPE_p_RTMPNetConnection swig_types[16] +#define SWIGTYPE_p_RTMPNetConnectionImpl swig_types[17] +#define SWIGTYPE_p_RTMPNetConnectionImplShared swig_types[18] +#define SWIGTYPE_p_RTMPNetConnectionShared swig_types[19] +#define SWIGTYPE_p_RTMPNetStream swig_types[20] +#define SWIGTYPE_p_RTMPNetStreamImpl swig_types[21] +#define SWIGTYPE_p_RTMPNetStreamImplShared swig_types[22] +#define SWIGTYPE_p_RTMPNetStreamShared swig_types[23] +#define SWIGTYPE_p_RTMPServerFacade swig_types[24] +#define SWIGTYPE_p_RTMPServerModule swig_types[25] +#define SWIGTYPE_p_RTPIncomingMediaStream swig_types[26] +#define SWIGTYPE_p_RTPIncomingMediaStreamShared swig_types[27] +#define SWIGTYPE_p_RTPReceiver swig_types[28] +#define SWIGTYPE_p_RTPReceiverShared swig_types[29] +#define SWIGTYPE_p_TimeService swig_types[30] +#define SWIGTYPE_p_VideoOrientation swig_types[31] +#define SWIGTYPE_p_char swig_types[32] +#define SWIGTYPE_p_int swig_types[33] +#define SWIGTYPE_p_long_long swig_types[34] +#define SWIGTYPE_p_short swig_types[35] +#define SWIGTYPE_p_signed_char swig_types[36] +#define SWIGTYPE_p_std__string swig_types[37] +#define SWIGTYPE_p_std__vectorT_Properties_t swig_types[38] +#define SWIGTYPE_p_unsigned_char swig_types[39] +#define SWIGTYPE_p_unsigned_int swig_types[40] +#define SWIGTYPE_p_unsigned_long_long swig_types[41] +#define SWIGTYPE_p_unsigned_short swig_types[42] +#define SWIGTYPE_p_v8__LocalT_v8__Object_t swig_types[43] +#define SWIGTYPE_p_void swig_types[44] +static swig_type_info *swig_types[46]; +static swig_module_info swig_module = {swig_types, 45, 0, 0, 0, 0}; #define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name) #define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name) @@ -3525,9 +3526,9 @@ class RTMPClientConnectionImpl : persistent = std::make_shared>(object); } - void Connect(const char* server,int port, const char* app) + RTMPClientConnection::ErrorCode Connect(const char* server,int port, const char* app) { - RTMPClientConnection::Connect(server, port, app, this); + return RTMPClientConnection::Connect(server, port, app, this); } void CreateStream(v8::Local promise) @@ -3547,6 +3548,7 @@ class RTMPClientConnectionImpl : RTMPClientConnection::SendCommand(id, L"publish", nullptr, new AMFString(parser.GetWChar())); } + void onConnected(RTMPClientConnection* conn) override { Log("-RTMPClientConnectionImpl::onConnected()\n"); @@ -3559,7 +3561,7 @@ class RTMPClientConnectionImpl : }); } - void onDisconnected(RTMPClientConnection* conn) override + void onDisconnected(RTMPClientConnection* conn, ErrorCode code) override { Log("-RTMPClientConnectionImpl::onDisconnected()\n"); @@ -3567,7 +3569,10 @@ class RTMPClientConnectionImpl : RTMPServerModule::Async([=,cloned=persistent](){ Nan::HandleScope scope; //Call object method with arguments - MakeCallback(cloned, "ondisconnected"); + v8::Local argv[1]; + argv[0] = Nan::New(static_cast(code)); + + MakeCallback(cloned, "ondisconnected", 1, argv); }); } @@ -3670,6 +3675,7 @@ SWIGV8_ClientData _exports_RTMPNetConnectionImpl_clientData; SWIGV8_ClientData _exports_RTMPNetConnectionImplShared_clientData; SWIGV8_ClientData _exports_RTMPApplicationImpl_clientData; SWIGV8_ClientData _exports_RTMPServerFacade_clientData; +SWIGV8_ClientData _exports_RTMPClientConnection_clientData; SWIGV8_ClientData _exports_RTMPClientConnectionImpl_clientData; @@ -9726,6 +9732,176 @@ static void _wrap_delete_RTMPServerFacade(const v8::WeakCallbackInfo property, const SwigV8PropertyCallbackInfo &info) { + SWIGV8_HANDLESCOPE(); + + SWIGV8_VALUE jsresult; + + jsresult = SWIG_From_int(static_cast< int >(RTMPClientConnection::ErrorCode::NoError)); + + SWIGV8_RETURN_INFO(jsresult, info); + + goto fail; +fail: + SWIGV8_RETURN_INFO(SWIGV8_UNDEFINED(), info); +} + + +static SwigV8ReturnValue _wrap_RTMPClientConnection_ErrorCode_Generic(v8::Local property, const SwigV8PropertyCallbackInfo &info) { + SWIGV8_HANDLESCOPE(); + + SWIGV8_VALUE jsresult; + + jsresult = SWIG_From_int(static_cast< int >(RTMPClientConnection::ErrorCode::Generic)); + + SWIGV8_RETURN_INFO(jsresult, info); + + goto fail; +fail: + SWIGV8_RETURN_INFO(SWIGV8_UNDEFINED(), info); +} + + +static SwigV8ReturnValue _wrap_RTMPClientConnection_ErrorCode_FailedToResolveURL(v8::Local property, const SwigV8PropertyCallbackInfo &info) { + SWIGV8_HANDLESCOPE(); + + SWIGV8_VALUE jsresult; + + jsresult = SWIG_From_int(static_cast< int >(RTMPClientConnection::ErrorCode::FailedToResolveURL)); + + SWIGV8_RETURN_INFO(jsresult, info); + + goto fail; +fail: + SWIGV8_RETURN_INFO(SWIGV8_UNDEFINED(), info); +} + + +static SwigV8ReturnValue _wrap_RTMPClientConnection_ErrorCode_GetSockOptError(v8::Local property, const SwigV8PropertyCallbackInfo &info) { + SWIGV8_HANDLESCOPE(); + + SWIGV8_VALUE jsresult; + + jsresult = SWIG_From_int(static_cast< int >(RTMPClientConnection::ErrorCode::GetSockOptError)); + + SWIGV8_RETURN_INFO(jsresult, info); + + goto fail; +fail: + SWIGV8_RETURN_INFO(SWIGV8_UNDEFINED(), info); +} + + +static SwigV8ReturnValue _wrap_RTMPClientConnection_ErrorCode_FailedToConnectSocket(v8::Local property, const SwigV8PropertyCallbackInfo &info) { + SWIGV8_HANDLESCOPE(); + + SWIGV8_VALUE jsresult; + + jsresult = SWIG_From_int(static_cast< int >(RTMPClientConnection::ErrorCode::FailedToConnectSocket)); + + SWIGV8_RETURN_INFO(jsresult, info); + + goto fail; +fail: + SWIGV8_RETURN_INFO(SWIGV8_UNDEFINED(), info); +} + + +static SwigV8ReturnValue _wrap_RTMPClientConnection_ErrorCode_ConnectCommandFailed(v8::Local property, const SwigV8PropertyCallbackInfo &info) { + SWIGV8_HANDLESCOPE(); + + SWIGV8_VALUE jsresult; + + jsresult = SWIG_From_int(static_cast< int >(RTMPClientConnection::ErrorCode::ConnectCommandFailed)); + + SWIGV8_RETURN_INFO(jsresult, info); + + goto fail; +fail: + SWIGV8_RETURN_INFO(SWIGV8_UNDEFINED(), info); +} + + +static SwigV8ReturnValue _wrap_RTMPClientConnection_ErrorCode_FailedToParseData(v8::Local property, const SwigV8PropertyCallbackInfo &info) { + SWIGV8_HANDLESCOPE(); + + SWIGV8_VALUE jsresult; + + jsresult = SWIG_From_int(static_cast< int >(RTMPClientConnection::ErrorCode::FailedToParseData)); + + SWIGV8_RETURN_INFO(jsresult, info); + + goto fail; +fail: + SWIGV8_RETURN_INFO(SWIGV8_UNDEFINED(), info); +} + + +static SwigV8ReturnValue _wrap_RTMPClientConnection_ErrorCode_PeerClosed(v8::Local property, const SwigV8PropertyCallbackInfo &info) { + SWIGV8_HANDLESCOPE(); + + SWIGV8_VALUE jsresult; + + jsresult = SWIG_From_int(static_cast< int >(RTMPClientConnection::ErrorCode::PeerClosed)); + + SWIGV8_RETURN_INFO(jsresult, info); + + goto fail; +fail: + SWIGV8_RETURN_INFO(SWIGV8_UNDEFINED(), info); +} + + +static SwigV8ReturnValue _wrap_RTMPClientConnection_ErrorCode_ReadError(v8::Local property, const SwigV8PropertyCallbackInfo &info) { + SWIGV8_HANDLESCOPE(); + + SWIGV8_VALUE jsresult; + + jsresult = SWIG_From_int(static_cast< int >(RTMPClientConnection::ErrorCode::ReadError)); + + SWIGV8_RETURN_INFO(jsresult, info); + + goto fail; +fail: + SWIGV8_RETURN_INFO(SWIGV8_UNDEFINED(), info); +} + + +static SwigV8ReturnValue _wrap_RTMPClientConnection_ErrorCode_PollError(v8::Local property, const SwigV8PropertyCallbackInfo &info) { + SWIGV8_HANDLESCOPE(); + + SWIGV8_VALUE jsresult; + + jsresult = SWIG_From_int(static_cast< int >(RTMPClientConnection::ErrorCode::PollError)); + + SWIGV8_RETURN_INFO(jsresult, info); + + goto fail; +fail: + SWIGV8_RETURN_INFO(SWIGV8_UNDEFINED(), info); +} + + +static void _wrap_delete_RTMPClientConnection(const v8::WeakCallbackInfo &data) { + SWIGV8_Proxy *proxy = data.GetParameter(); + + if(proxy->swigCMemOwn && proxy->swigCObject) { + RTMPClientConnection * arg1 = (RTMPClientConnection *)proxy->swigCObject; + delete arg1; + } + delete proxy; +} + + +static SwigV8ReturnValue _wrap_new_veto_RTMPClientConnection(const SwigV8Arguments &args) { + SWIGV8_HANDLESCOPE(); + + SWIG_exception(SWIG_ERROR, "Class RTMPClientConnection can not be instantiated"); +fail: + SWIGV8_RETURN(SWIGV8_UNDEFINED()); +} + + static SwigV8ReturnValue _wrap_new_RTMPClientConnectionImpl(const SwigV8Arguments &args) { SWIGV8_HANDLESCOPE(); @@ -9768,6 +9944,7 @@ static SwigV8ReturnValue _wrap_RTMPClientConnectionImpl_Connect(const SwigV8Argu int res4 ; char *buf4 = 0 ; int alloc4 = 0 ; + RTMPClientConnection::ErrorCode result; if(args.Length() != 3) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for _wrap_RTMPClientConnectionImpl_Connect."); @@ -9791,8 +9968,8 @@ static SwigV8ReturnValue _wrap_RTMPClientConnectionImpl_Connect(const SwigV8Argu SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "RTMPClientConnectionImpl_Connect" "', argument " "4"" of type '" "char const *""'"); } arg4 = reinterpret_cast< char * >(buf4); - (arg1)->Connect((char const *)arg2,arg3,(char const *)arg4); - jsresult = SWIGV8_UNDEFINED(); + result = (RTMPClientConnection::ErrorCode)(arg1)->Connect((char const *)arg2,arg3,(char const *)arg4); + jsresult = SWIG_From_int(static_cast< int >(result)); if (alloc2 == SWIG_NEWOBJ) delete[] buf2; @@ -10050,6 +10227,7 @@ static swig_type_info _swigt__p_OutgoingStreamBridge = {"_p_OutgoingStreamBridge static swig_type_info _swigt__p_OutgoingStreamBridgeShared = {"_p_OutgoingStreamBridgeShared", "p_OutgoingStreamBridgeShared|OutgoingStreamBridgeShared *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_Properties = {"_p_Properties", "Properties *|p_Properties", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_RTMPApplicationImpl = {"_p_RTMPApplicationImpl", "RTMPApplicationImpl *|p_RTMPApplicationImpl", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_RTMPClientConnection = {"_p_RTMPClientConnection", "p_RTMPClientConnection", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_RTMPClientConnectionImpl = {"_p_RTMPClientConnectionImpl", "RTMPClientConnectionImpl *|p_RTMPClientConnectionImpl", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_RTMPMediaStreamListener = {"_p_RTMPMediaStreamListener", "p_RTMPMediaStreamListener|RTMPMediaStreamListener *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_RTMPNetConnection = {"_p_RTMPNetConnection", "RTMPNetConnection *|p_RTMPNetConnection", 0, 0, (void*)0, 0}; @@ -10096,6 +10274,7 @@ static swig_type_info *swig_type_initial[] = { &_swigt__p_OutgoingStreamBridgeShared, &_swigt__p_Properties, &_swigt__p_RTMPApplicationImpl, + &_swigt__p_RTMPClientConnection, &_swigt__p_RTMPClientConnectionImpl, &_swigt__p_RTMPMediaStreamListener, &_swigt__p_RTMPNetConnection, @@ -10142,6 +10321,7 @@ static swig_cast_info _swigc__p_OutgoingStreamBridge[] = { {&_swigt__p_Outgoing static swig_cast_info _swigc__p_OutgoingStreamBridgeShared[] = { {&_swigt__p_OutgoingStreamBridgeShared, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_Properties[] = { {&_swigt__p_Properties, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_RTMPApplicationImpl[] = { {&_swigt__p_RTMPApplicationImpl, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_RTMPClientConnection[] = { {&_swigt__p_RTMPClientConnection, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_RTMPClientConnectionImpl[] = { {&_swigt__p_RTMPClientConnectionImpl, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_RTMPMediaStreamListener[] = { {&_swigt__p_RTMPClientConnectionImpl, _p_RTMPClientConnectionImplTo_p_RTMPMediaStreamListener, 0, 0}, {&_swigt__p_RTMPMediaStreamListener, 0, 0, 0}, {&_swigt__p_IncomingStreamBridge, _p_IncomingStreamBridgeTo_p_RTMPMediaStreamListener, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_RTMPNetConnection[] = { {&_swigt__p_RTMPNetConnectionImpl, _p_RTMPNetConnectionImplTo_p_RTMPNetConnection, 0, 0}, {&_swigt__p_RTMPNetConnection, 0, 0, 0},{0, 0, 0, 0}}; @@ -10188,6 +10368,7 @@ static swig_cast_info *swig_cast_initial[] = { _swigc__p_OutgoingStreamBridgeShared, _swigc__p_Properties, _swigc__p_RTMPApplicationImpl, + _swigc__p_RTMPClientConnection, _swigc__p_RTMPClientConnectionImpl, _swigc__p_RTMPMediaStreamListener, _swigc__p_RTMPNetConnection, @@ -10741,6 +10922,13 @@ _exports_RTMPServerFacade_clientData.dtor = _wrap_delete_RTMPServerFacade; if (SWIGTYPE_p_RTMPServerFacade->clientdata == 0) { SWIGTYPE_p_RTMPServerFacade->clientdata = &_exports_RTMPServerFacade_clientData; } +/* Name: _exports_RTMPClientConnection, Type: p_RTMPClientConnection, Dtor: _wrap_delete_RTMPClientConnection */ +SWIGV8_FUNCTION_TEMPLATE _exports_RTMPClientConnection_class = SWIGV8_CreateClassTemplate("_exports_RTMPClientConnection"); +SWIGV8_SET_CLASS_TEMPL(_exports_RTMPClientConnection_clientData.class_templ, _exports_RTMPClientConnection_class); +_exports_RTMPClientConnection_clientData.dtor = _wrap_delete_RTMPClientConnection; +if (SWIGTYPE_p_RTMPClientConnection->clientdata == 0) { + SWIGTYPE_p_RTMPClientConnection->clientdata = &_exports_RTMPClientConnection_clientData; +} /* Name: _exports_RTMPClientConnectionImpl, Type: p_RTMPClientConnectionImpl, Dtor: _wrap_delete_RTMPClientConnectionImpl */ SWIGV8_FUNCTION_TEMPLATE _exports_RTMPClientConnectionImpl_class = SWIGV8_CreateClassTemplate("_exports_RTMPClientConnectionImpl"); SWIGV8_SET_CLASS_TEMPL(_exports_RTMPClientConnectionImpl_clientData.class_templ, _exports_RTMPClientConnectionImpl_class); @@ -11257,6 +11445,16 @@ v8::Local _exports_RTMPServerFacade_obj = _exports_RTMPServerFacade_ #else v8::Local _exports_RTMPServerFacade_obj = _exports_RTMPServerFacade_class_0->GetFunction(context).ToLocalChecked(); #endif +/* Class: RTMPClientConnection (_exports_RTMPClientConnection) */ +SWIGV8_FUNCTION_TEMPLATE _exports_RTMPClientConnection_class_0 = SWIGV8_CreateClassTemplate("RTMPClientConnection"); +_exports_RTMPClientConnection_class_0->SetCallHandler(_wrap_new_veto_RTMPClientConnection); +_exports_RTMPClientConnection_class_0->Inherit(_exports_RTMPClientConnection_class); +#if (SWIG_V8_VERSION < 0x0704) +_exports_RTMPClientConnection_class_0->SetHiddenPrototype(true); +v8::Local _exports_RTMPClientConnection_obj = _exports_RTMPClientConnection_class_0->GetFunction(); +#else +v8::Local _exports_RTMPClientConnection_obj = _exports_RTMPClientConnection_class_0->GetFunction(context).ToLocalChecked(); +#endif /* Class: RTMPClientConnectionImpl (_exports_RTMPClientConnectionImpl) */ SWIGV8_FUNCTION_TEMPLATE _exports_RTMPClientConnectionImpl_class_0 = SWIGV8_CreateClassTemplate("RTMPClientConnectionImpl"); _exports_RTMPClientConnectionImpl_class_0->SetCallHandler(_wrap_new_RTMPClientConnectionImpl); @@ -11279,6 +11477,16 @@ SWIGV8_AddStaticFunction(_exports_RTMPServerModule_obj, "EnableWarning", _wrap_R SWIGV8_AddStaticFunction(_exports_RTMPServerModule_obj, "EnableLog", _wrap_RTMPServerModule_EnableLog, context); SWIGV8_AddStaticFunction(_exports_RTMPServerModule_obj, "EnableDebug", _wrap_RTMPServerModule_EnableDebug, context); SWIGV8_AddStaticFunction(_exports_RTMPServerModule_obj, "EnableUltraDebug", _wrap_RTMPServerModule_EnableUltraDebug, context); +SWIGV8_AddStaticVariable(_exports_RTMPClientConnection_obj, "ErrorCode_NoError", _wrap_RTMPClientConnection_ErrorCode_NoError, JS_veto_set_variable, context); +SWIGV8_AddStaticVariable(_exports_RTMPClientConnection_obj, "ErrorCode_Generic", _wrap_RTMPClientConnection_ErrorCode_Generic, JS_veto_set_variable, context); +SWIGV8_AddStaticVariable(_exports_RTMPClientConnection_obj, "ErrorCode_FailedToResolveURL", _wrap_RTMPClientConnection_ErrorCode_FailedToResolveURL, JS_veto_set_variable, context); +SWIGV8_AddStaticVariable(_exports_RTMPClientConnection_obj, "ErrorCode_GetSockOptError", _wrap_RTMPClientConnection_ErrorCode_GetSockOptError, JS_veto_set_variable, context); +SWIGV8_AddStaticVariable(_exports_RTMPClientConnection_obj, "ErrorCode_FailedToConnectSocket", _wrap_RTMPClientConnection_ErrorCode_FailedToConnectSocket, JS_veto_set_variable, context); +SWIGV8_AddStaticVariable(_exports_RTMPClientConnection_obj, "ErrorCode_ConnectCommandFailed", _wrap_RTMPClientConnection_ErrorCode_ConnectCommandFailed, JS_veto_set_variable, context); +SWIGV8_AddStaticVariable(_exports_RTMPClientConnection_obj, "ErrorCode_FailedToParseData", _wrap_RTMPClientConnection_ErrorCode_FailedToParseData, JS_veto_set_variable, context); +SWIGV8_AddStaticVariable(_exports_RTMPClientConnection_obj, "ErrorCode_PeerClosed", _wrap_RTMPClientConnection_ErrorCode_PeerClosed, JS_veto_set_variable, context); +SWIGV8_AddStaticVariable(_exports_RTMPClientConnection_obj, "ErrorCode_ReadError", _wrap_RTMPClientConnection_ErrorCode_ReadError, JS_veto_set_variable, context); +SWIGV8_AddStaticVariable(_exports_RTMPClientConnection_obj, "ErrorCode_PollError", _wrap_RTMPClientConnection_ErrorCode_PollError, JS_veto_set_variable, context); /* register classes */ @@ -11312,6 +11520,7 @@ SWIGV8_MAYBE_CHECK(exports_obj->Set(context, SWIGV8_SYMBOL_NEW("RTMPNetConnectio SWIGV8_MAYBE_CHECK(exports_obj->Set(context, SWIGV8_SYMBOL_NEW("RTMPNetConnectionImplShared"), _exports_RTMPNetConnectionImplShared_obj)); SWIGV8_MAYBE_CHECK(exports_obj->Set(context, SWIGV8_SYMBOL_NEW("RTMPApplicationImpl"), _exports_RTMPApplicationImpl_obj)); SWIGV8_MAYBE_CHECK(exports_obj->Set(context, SWIGV8_SYMBOL_NEW("RTMPServerFacade"), _exports_RTMPServerFacade_obj)); +SWIGV8_MAYBE_CHECK(exports_obj->Set(context, SWIGV8_SYMBOL_NEW("RTMPClientConnection"), _exports_RTMPClientConnection_obj)); SWIGV8_MAYBE_CHECK(exports_obj->Set(context, SWIGV8_SYMBOL_NEW("RTMPClientConnectionImpl"), _exports_RTMPClientConnectionImpl_obj)); diff --git a/tests/client.js b/tests/client.js index 5006e28..623af65 100644 --- a/tests/client.js +++ b/tests/client.js @@ -94,8 +94,8 @@ tap.test("Server", async function (suite) //Check we have stats test.ok(connection.getStats()); - connection.on("disconnected",()=>{ - test.pass("client disconnected"); + connection.on("disconnected",(conn, errorCode)=>{ + test.equal(errorCode, RTMPServer.NetConnectionErrorCode.NoError); }); //Stop @@ -111,21 +111,71 @@ tap.test("Server", async function (suite) test.end(); }); - await suite.test("failed", async function (test) + await suite.test("incorrectport", async function (test) { //Create client connection const connection = RTMPServer.createClientConnection(); - connection.on("disconnected",()=>{ - test.pass("client disconnected"); + connection.on("disconnected", (conn, errorCode)=>{ + test.equal(errorCode, RTMPServer.NetConnectionErrorCode.GetSockOptError); }); + //Connect. Note the connect wouldn't fail immediately. + let errorCode = connection.connect("127.0.0.1", 1937, "test"); + test.equal(errorCode, RTMPServer.NetConnectionErrorCode.NoError); + + //Wait 1 seconds + await sleep(1000); + }); + + await suite.test("invalidurl", async function (test) + { + //Create client connection + const connection = RTMPServer.createClientConnection(); + //Connect - connection.connect("127.0.0.1", 1937, "test"); + let errorCode = connection.connect("invalid.url", 1937, "test"); + test.equal(errorCode, RTMPServer.NetConnectionErrorCode.FailedToResolveURL); + }); + + await suite.test("peerclosed", async function (test) + { + test.plan(2); + + //Create server and app + const app = RTMPServer.createApplication(); + const rtmp = RTMPServer.createServer(); + + app.on("connect", (client) => + { + // Close the connection + client.reject(); + }); + + //Start rtmp server + rtmp.addApplication("test", app); + rtmp.start(1936); + + //Create client connection + const connection = RTMPServer.createClientConnection(); + + //Connect + let errorCode = connection.connect("127.0.0.1", 1936, "test"); + test.equal(errorCode, RTMPServer.NetConnectionErrorCode.NoError); + + connection.on("disconnected", (conn, errorCode)=>{ + test.equal(errorCode, RTMPServer.NetConnectionErrorCode.PeerClosed); + }); //Wait 1 seconds await sleep(1000); + + //Stop server + rtmp.stop(); + + test.end(); }); + suite.end(); }).then(() =>