{"action":"created","issue":{"url":"https://api.github.com/repos/meetecho/janus-gateway/issues/1229","repository_url":"https://api.github.com/repos/meetecho/janus-gateway","labels_url":"https://api.github.com/repos/meetecho/janus-gateway/issues/1229/labels{/name}","comments_url":"https://api.github.com/repos/meetecho/janus-gateway/issues/1229/comments","events_url":"https://api.github.com/repos/meetecho/janus-gateway/issues/1229/events","html_url":"https://github.com/meetecho/janus-gateway/issues/1229","id":321573696,"number":1229,"title":"Extend dependencies in Janus.init","user":{"login":"phsultan","id":4329537,"avatar_url":"https://avatars2.githubusercontent.com/u/4329537?v=4","gravatar_id":"","url":"https://api.github.com/users/phsultan","html_url":"https://github.com/phsultan","followers_url":"https://api.github.com/users/phsultan/followers","following_url":"https://api.github.com/users/phsultan/following{/other_user}","gists_url":"https://api.github.com/users/phsultan/gists{/gist_id}","starred_url":"https://api.github.com/users/phsultan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phsultan/subscriptions","organizations_url":"https://api.github.com/users/phsultan/orgs","repos_url":"https://api.github.com/users/phsultan/repos","events_url":"https://api.github.com/users/phsultan/events{/privacy}","received_events_url":"https://api.github.com/users/phsultan/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2018-05-09T13:37:14Z","updated_at":"2018-05-18T12:03:58Z","closed_at":null,"author_association":"NONE","body":"Hi !\r\n\r\nI'm initializing Janus with a specific version of `adapter.js` the following way:\r\n```\r\nJanus.init({\r\n    dependencies: {\r\n      webRTCAdapter: MyWebRTCAdaper\r\n    },\r\n    debug: \"all\",\r\n    callback: function() {console.log('ok');}\r\n})\r\n```\r\n\r\nDoing so will not create the following objects in Janus:\r\n```\r\n    Janus.isArray = usedDependencies.isArray;\r\n    Janus.httpAPICall = usedDependencies.httpAPICall;\r\n    Janus.checkJanusExtension = usedDependencies.checkJanusExtension;\r\n    Janus.newWebSocket = usedDependencies.newWebSocket;\r\n```\r\n\r\nAnd leads to an error when creating a new Janus instance. To reproduce the error, the code below can be used:\r\n```\r\nJanus.init({\r\n\tdebug: \"all\",\r\n\tdependencies: {\r\n\t\twebRTCAdapter: {} // Empty object used for testing, the same error is thrown with a valid adapter.js instance\r\n\t},\r\n\tcallback: function() {\r\n\t\tconsole.log('Janus init ok');\r\n\t\tvar serverWsURL = 'wss://a-valid-secured-websocket-server-name:8989';\r\n\t\tvar janusInstance = new Janus({\r\n\t\t\tserver: serverWsURL,\r\n\t\t\tsuccess: function() {\r\n\t\t\t\tconsole.log('Instance created');\r\n\t\t\t},\r\n\t\t\terror: function(error) {\r\n\t\t\t\tJanus.error(error);\r\n\t\t\t},\r\n\t\t\tdestroyed: function() {\r\n\t\t\t\tconsole.log('Instance destroyed');\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\nError thrown: `TypeError: Janus.isArray is not a function`.\r\n\r\nAs a workaround, I can build the `dependencies` object with all the necessary objects, but instead I modified `Janus.js` in order to accept to extend the dependencies using the `deps` argument in `useDefaultDependencies()`. The diff is simple, although I can make a PR if needed:\r\n```\r\ndiff --git a/src/Janus.js b/src/Janus.js\r\nindex ccf4635..4c33ccc 100644\r\n--- a/src/Janus.js\r\n+++ b/src/Janus.js\r\n@@ -33,7 +33,7 @@ Janus.useDefaultDependencies = function (deps) {\r\n                newWebSocket: function(server, proto) { return new socketCls(server, proto); },\r\n                isArray: function(arr) { return Array.isArray(arr); },\r\n                checkJanusExtension: function() { return document.querySelector('#janus-extension-installed') !== null; },\r\n-               webRTCAdapter: (deps && deps.adapter) || adapter,\r\n+               webRTCAdapter: (deps && deps.webRTCAdapter) || adapter,\r\n                httpAPICall: function(url, options) {\r\n                        var fetchOptions = {\r\n                                method: options.verb,\r\n@@ -102,7 +102,7 @@ Janus.useOldDependencies = function (deps) {\r\n                newWebSocket: function(server, proto) { return new socketCls(server, proto); },\r\n                isArray: function(arr) { return jq.isArray(arr); },\r\n                checkJanusExtension: function() { return jq('#janus-extension-installed').length > 0; },\r\n-               webRTCAdapter: (deps && deps.adapter) || adapter,\r\n+               webRTCAdapter: (deps && deps.webRTCAdapter) || adapter,\r\n                httpAPICall: function(url, options) {\r\n                        var payload = options.body !== undefined ? {\r\n                                contentType: 'application/json',\r\n@@ -189,7 +189,8 @@ Janus.init = function(options) {\r\n                }\r\n                Janus.log(\"Initializing library\");\r\n \r\n-               var usedDependencies = options.dependencies || Janus.useDefaultDependencies();\r\n+               var usedDependencies = Janus.useDefaultDependencies(options.dependencies);\r\n+\r\n                Janus.isArray = usedDependencies.isArray;\r\n                Janus.webRTCAdapter = usedDependencies.webRTCAdapter;\r\n                Janus.httpAPICall = usedDependencies.httpAPICall;\r\n```\r\n\r\nI'm not sure why the `deps` argument is not used in `useDefaultDependencies`,  and maybe that function should be renamed if this change is accepted.\r\n\r\nThanks for the work that's being done on Janus !"},"comment":{"url":"https://api.github.com/repos/meetecho/janus-gateway/issues/comments/390185855","html_url":"https://github.com/meetecho/janus-gateway/issues/1229#issuecomment-390185855","issue_url":"https://api.github.com/repos/meetecho/janus-gateway/issues/1229","id":390185855,"user":{"login":"lminiero","id":3684796,"avatar_url":"https://avatars1.githubusercontent.com/u/3684796?v=4","gravatar_id":"","url":"https://api.github.com/users/lminiero","html_url":"https://github.com/lminiero","followers_url":"https://api.github.com/users/lminiero/followers","following_url":"https://api.github.com/users/lminiero/following{/other_user}","gists_url":"https://api.github.com/users/lminiero/gists{/gist_id}","starred_url":"https://api.github.com/users/lminiero/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lminiero/subscriptions","organizations_url":"https://api.github.com/users/lminiero/orgs","repos_url":"https://api.github.com/users/lminiero/repos","events_url":"https://api.github.com/users/lminiero/events{/privacy}","received_events_url":"https://api.github.com/users/lminiero/received_events","type":"User","site_admin":false},"created_at":"2018-05-18T12:03:58Z","updated_at":"2018-05-18T12:03:58Z","author_association":"MEMBER","body":"Makes a lot of sense, thanks for the clarification and sorry for my abysmal JavaScript ignorance :smile: \r\nI'll integrate your patch in the code later today :+1: "}}
{"actor":{"display_login":"lminiero"}}