@@ -745,6 +745,27 @@ async function showSettingsModal() {
745745 modelsGroup . appendChild ( deleteModelButton ) ;
746746 modelsGroup . appendChild ( loadingModels ) ;
747747
748+ // turn server creds group
749+ const turnServerCredsGroup = document . createElement ( "div" ) ;
750+ turnServerCredsGroup . className = "cs-input-group" ;
751+
752+ const turnServerCredsLabel = document . createElement ( "label" ) ;
753+ turnServerCredsLabel . textContent = "TURN Creds:" ;
754+ turnServerCredsLabel . className = "cs-label" ;
755+
756+ const setButton = document . createElement ( "button" ) ;
757+ setButton . textContent = "Set" ;
758+ setButton . className = "cs-button" ;
759+
760+ const turnServerCredsLoading = document . createElement ( "span" ) ;
761+ turnServerCredsLoading . id = "comfystream-loading-turn-server-creds-spinner" ;
762+ turnServerCredsLoading . className = "loader" ;
763+ turnServerCredsLoading . style . display = "none" ; // Initially hidden
764+
765+ turnServerCredsGroup . appendChild ( turnServerCredsLabel ) ;
766+ turnServerCredsGroup . appendChild ( setButton ) ;
767+ turnServerCredsGroup . appendChild ( turnServerCredsLoading ) ;
768+
748769 // Configurations section
749770 const configsSection = document . createElement ( "div" ) ;
750771 configsSection . className = "cs-section" ;
@@ -831,6 +852,7 @@ async function showSettingsModal() {
831852 form . appendChild ( portGroup ) ;
832853 form . appendChild ( nodesGroup ) ;
833854 form . appendChild ( modelsGroup ) ;
855+ form . appendChild ( turnServerCredsGroup ) ;
834856 form . appendChild ( configsSection ) ;
835857
836858 modalContent . appendChild ( closeButton ) ;
@@ -885,6 +907,27 @@ async function showSettingsModal() {
885907 app . ui . dialog . show ( 'Error' , `Failed to manage models: ${ error . message } ` ) ;
886908 }
887909 }
910+ async function manageTurnServerCredentials ( action ) {
911+ //show the spinner to provide feedback
912+ const loadingSpinner = document . getElementById ( "comfystream-loading-turn-server-creds-spinner" ) ;
913+ loadingSpinner . style . display = "inline-block" ;
914+
915+ try {
916+ if ( action === "set" ) {
917+ await showSetTurnServerCredsModal ( ) ;
918+ } else if ( action === "clear" ) {
919+ await showClearTurnServerCredsModal ( ) ;
920+ }
921+ // Hide the spinner after action
922+ loadingSpinner . style . display = "none" ;
923+ } catch ( error ) {
924+ console . error ( "[ComfyStream] Error managing TURN server credentials:" , error ) ;
925+ app . ui . dialog . show ( 'Error' , `Failed to manage TURN server credentials: ${ error . message } ` ) ;
926+ }
927+
928+ // Hide the spinner after action
929+ loadingSpinner . style . display = "none" ;
930+ }
888931 // Add event listeners for nodes management buttons
889932 installNodeButton . addEventListener ( "click" , ( ) => {
890933 manageNodes ( "install" ) ;
@@ -905,6 +948,9 @@ async function showSettingsModal() {
905948 deleteModelButton . addEventListener ( "click" , ( ) => {
906949 manageModels ( "delete" ) ;
907950 } ) ;
951+ setButton . addEventListener ( "click" , async ( ) => {
952+ await showSetTurnServerCredsModal ( ) ;
953+ } ) ;
908954 // Update configurations list
909955 async function updateConfigsList ( ) {
910956 configsList . innerHTML = "" ;
@@ -1077,6 +1123,225 @@ async function showSettingsModal() {
10771123 hostInput . focus ( ) ;
10781124}
10791125
1126+ async function showSetTurnServerCredsModal ( ) {
1127+ // Check if modal already exists and remove it
1128+ const existingModal = document . getElementById ( "comfystream-settings-set-turn-creds-modal" ) ;
1129+ if ( existingModal ) {
1130+ existingModal . remove ( ) ;
1131+ }
1132+
1133+ // Create nodes mgmt modal container
1134+ const modal = document . createElement ( "div" ) ;
1135+ modal . id = "comfystream-settings-set-turn-creds-modal" ;
1136+ modal . className = "comfystream-settings-modal" ;
1137+
1138+ // Create close button
1139+ const closeButton = document . createElement ( "button" ) ;
1140+ closeButton . textContent = "×" ;
1141+ closeButton . className = "cs-close-button" ;
1142+ closeButton . onclick = ( ) => {
1143+ modal . remove ( ) ;
1144+ } ;
1145+
1146+ // Create modal content
1147+ const modalContent = document . createElement ( "div" ) ;
1148+ modalContent . className = "cs-modal-content" ;
1149+
1150+ // Create title
1151+ const title = document . createElement ( "h3" ) ;
1152+ title . textContent = "Set TURN Server Credentials" ;
1153+ title . className = "cs-title" ;
1154+
1155+ // Create settings form
1156+ const form = document . createElement ( "div" ) ;
1157+
1158+ // account type
1159+ const accountTypeGroup = document . createElement ( "div" ) ;
1160+ accountTypeGroup . className = "cs-input-group" ;
1161+
1162+ const accountTypeLabel = document . createElement ( "label" ) ;
1163+ accountTypeLabel . textContent = "Account Type:" ;
1164+ accountTypeLabel . className = "cs-label" ;
1165+
1166+ const accountTypeSelect = document . createElement ( "select" ) ;
1167+ const accountItem = document . createElement ( "option" ) ;
1168+ accountItem . value = "twilio" ;
1169+ accountItem . textContent = "Twilio" ;
1170+ accountTypeSelect . appendChild ( accountItem ) ;
1171+ accountTypeSelect . id = "comfystream-selected-turn-server-account-type" ;
1172+
1173+ const accountTypeHelpIcon = document . createElement ( "span" ) ;
1174+ accountTypeHelpIcon . innerHTML = "🛈" ; // Unicode for a help icon (ℹ️)
1175+ accountTypeHelpIcon . style . cursor = "pointer" ;
1176+ accountTypeHelpIcon . style . marginLeft = "5px" ;
1177+ accountTypeHelpIcon . title = "Click for help" ;
1178+
1179+ const accountTypeHelp = document . createElement ( "div" ) ;
1180+ accountTypeHelp . textContent = "Specify the account type to use" ;
1181+ accountTypeHelp . className = "cs-help-text" ;
1182+ accountTypeHelp . style . display = "none" ;
1183+
1184+ accountTypeHelpIcon . addEventListener ( "click" , ( ) => {
1185+ if ( accountTypeHelp . style . display == "none" ) {
1186+ accountTypeHelp . style . display = "block" ;
1187+ } else {
1188+ accountTypeHelp . style . display = "none" ;
1189+ }
1190+ } ) ;
1191+
1192+ accountTypeGroup . appendChild ( accountTypeLabel ) ;
1193+ accountTypeGroup . appendChild ( accountTypeSelect ) ;
1194+ accountTypeGroup . appendChild ( accountTypeHelpIcon ) ;
1195+
1196+ // account id
1197+ const accountIdGroup = document . createElement ( "div" ) ;
1198+ accountIdGroup . className = "cs-input-group" ;
1199+
1200+ const accountIdLabel = document . createElement ( "label" ) ;
1201+ accountIdLabel . textContent = "Account ID:" ;
1202+ accountIdLabel . className = "cs-label" ;
1203+
1204+ const accountIdInput = document . createElement ( "input" ) ;
1205+ accountIdInput . id = "turn-server-creds-account-id" ;
1206+ accountIdInput . className = "cs-input" ;
1207+
1208+
1209+ const accountIdHelpIcon = document . createElement ( "span" ) ;
1210+ accountIdHelpIcon . innerHTML = "🛈" ; // Unicode for a help icon (ℹ️)
1211+ accountIdHelpIcon . style . cursor = "pointer" ;
1212+ accountIdHelpIcon . style . marginLeft = "5px" ;
1213+ accountIdHelpIcon . title = "Click for help" ;
1214+
1215+ const accountIdHelp = document . createElement ( "div" ) ;
1216+ accountIdHelp . textContent = "Specify the account id for Twilio TURN server credentials" ;
1217+ accountIdHelp . className = "cs-help-text" ;
1218+ accountIdHelp . style . display = "none" ;
1219+
1220+ accountIdHelpIcon . addEventListener ( "click" , ( ) => {
1221+ if ( accountIdHelp . style . display == "none" ) {
1222+ accountIdHelp . style . display = "block" ;
1223+ } else {
1224+ accountIdHelp . style . display = "none" ;
1225+ }
1226+ } ) ;
1227+
1228+ accountIdGroup . appendChild ( accountIdLabel ) ;
1229+ accountIdGroup . appendChild ( accountIdInput ) ;
1230+ accountIdGroup . appendChild ( accountIdHelpIcon ) ;
1231+
1232+ // auth token
1233+ const accountAuthTokenGroup = document . createElement ( "div" ) ;
1234+ accountAuthTokenGroup . className = "cs-input-group" ;
1235+
1236+ const accountAuthTokenLabel = document . createElement ( "label" ) ;
1237+ accountAuthTokenLabel . textContent = "Auth Token:" ;
1238+ accountAuthTokenLabel . className = "cs-label" ;
1239+
1240+ const accountAuthTokenInput = document . createElement ( "input" ) ;
1241+ accountAuthTokenInput . id = "turn-server-creds-auth-token" ;
1242+ accountAuthTokenInput . className = "cs-input" ;
1243+
1244+ const accountAuthTokenHelpIcon = document . createElement ( "span" ) ;
1245+ accountAuthTokenHelpIcon . innerHTML = "🛈" ; // Unicode for a help icon (ℹ️)
1246+ accountAuthTokenHelpIcon . style . cursor = "pointer" ;
1247+ accountAuthTokenHelpIcon . style . marginLeft = "5px" ;
1248+ accountAuthTokenHelpIcon . title = "Click for help" ;
1249+ accountAuthTokenHelpIcon . style . position = "relative" ;
1250+
1251+ const accountAuthTokenHelp = document . createElement ( "div" ) ;
1252+ accountAuthTokenHelp . textContent = "Specify the auth token provided by Twilio for TURN server credentials" ;
1253+ accountAuthTokenHelp . className = "cs-help-text" ;
1254+ accountAuthTokenHelp . style . display = "none" ;
1255+
1256+ accountAuthTokenHelpIcon . addEventListener ( "click" , ( ) => {
1257+ if ( accountAuthTokenHelp . style . display == "none" ) {
1258+ accountAuthTokenHelp . style . display = "block" ;
1259+ } else {
1260+ accountAuthTokenHelp . style . display = "none" ;
1261+ }
1262+ } ) ;
1263+
1264+ accountAuthTokenGroup . appendChild ( accountAuthTokenLabel ) ;
1265+ accountAuthTokenGroup . appendChild ( accountAuthTokenInput ) ;
1266+ accountAuthTokenGroup . appendChild ( accountAuthTokenHelpIcon ) ;
1267+
1268+ // Footer with buttons
1269+ const footer = document . createElement ( "div" ) ;
1270+ footer . className = "cs-footer" ;
1271+
1272+ const msgTxt = document . createElement ( "div" ) ;
1273+ msgTxt . id = "comfystream-manage-turn-server-creds-msg-txt" ;
1274+ msgTxt . style . fontSize = "0.75em" ;
1275+ msgTxt . style . fontStyle = "italic" ;
1276+ msgTxt . style . overflowWrap = "break-word" ;
1277+
1278+ const cancelButton = document . createElement ( "button" ) ;
1279+ cancelButton . textContent = "Cancel" ;
1280+ cancelButton . className = "cs-button" ;
1281+ cancelButton . onclick = ( ) => {
1282+ modal . remove ( ) ;
1283+ } ;
1284+ const clearButton = document . createElement ( "button" ) ;
1285+ clearButton . textContent = "Clear" ;
1286+ clearButton . className = "cs-button" ;
1287+ clearButton . onclick = ( ) => {
1288+ const accountType = accountTypeSelect . options [ accountTypeSelect . selectedIndex ] . value ;
1289+ msgTxt . textContent = setTurnSeverCreds ( accountType , "" , "" ) ;
1290+ } ;
1291+
1292+ const setButton = document . createElement ( "button" ) ;
1293+ setButton . textContent = "Set" ;
1294+ setButton . className = "cs-button primary" ;
1295+ setButton . onclick = async ( ) => {
1296+ const accountId = accountIdInput . value ;
1297+ const authToken = accountAuthTokenInput . value ;
1298+ const accountType = accountTypeSelect . options [ accountTypeSelect . selectedIndex ] . value ;
1299+ msgTxt . textContent = setTurnSeverCreds ( accountType , accountId , authToken ) ;
1300+ } ;
1301+
1302+ footer . appendChild ( msgTxt ) ;
1303+ footer . appendChild ( cancelButton ) ;
1304+ footer . appendChild ( setButton ) ;
1305+
1306+ // Assemble the modal
1307+ form . appendChild ( accountTypeGroup ) ;
1308+ form . appendChild ( accountTypeHelp ) ;
1309+ form . appendChild ( accountIdGroup ) ;
1310+ form . appendChild ( accountIdHelp ) ;
1311+ form . appendChild ( accountAuthTokenGroup ) ;
1312+ form . appendChild ( accountAuthTokenHelp ) ;
1313+
1314+ modalContent . appendChild ( closeButton ) ;
1315+ modalContent . appendChild ( title ) ;
1316+ modalContent . appendChild ( form ) ;
1317+ modalContent . appendChild ( footer ) ;
1318+
1319+ modal . appendChild ( modalContent ) ;
1320+
1321+ // Add to document
1322+ document . body . appendChild ( modal ) ;
1323+ }
1324+
1325+ async function setTurnSeverCreds ( accountType , accountId , authToken ) {
1326+ try {
1327+ const payload = {
1328+ type : accountType ,
1329+ account_id : accountId ,
1330+ auth_token : authToken
1331+ }
1332+
1333+ await settingsManager . manageComfystream (
1334+ "turn/server" ,
1335+ "set/account" ,
1336+ [ payload ]
1337+ ) ;
1338+ return "TURN server credentials updated successfully" ;
1339+ } catch ( error ) {
1340+ console . error ( "[ComfyStream] Error adding model:" , error ) ;
1341+ msgTxt . textContent = error ;
1342+ }
1343+ }
1344+
10801345async function showAddModelsModal ( ) {
10811346 // Check if modal already exists and remove it
10821347 const existingModal = document . getElementById ( "comfystream-settings-add-model-modal" ) ;
@@ -1253,7 +1518,7 @@ async function showAddModelsModal() {
12531518 "add" ,
12541519 [ payload ]
12551520 ) ;
1256- msgTxt . textContent = "Model added successfully! " ;
1521+ msgTxt . textContent = "Model added successfully" ;
12571522 } catch ( error ) {
12581523 console . error ( "[ComfyStream] Error adding model:" , error ) ;
12591524 msgTxt . textContent = error ;
@@ -1965,7 +2230,7 @@ async function showInstallNodesModal() {
19652230 document . body . appendChild ( modal ) ;
19662231}
19672232// Export for use in other modules
1968- export { settingsManager , showSettingsModal , showInstallNodesModal , showUpdateNodesModal , showDeleteNodesModal , showToggleNodesModal , showAddModelsModal , showDeleteModelsModal } ;
2233+ export { settingsManager , showSettingsModal , showInstallNodesModal , showUpdateNodesModal , showDeleteNodesModal , showToggleNodesModal , showAddModelsModal , showDeleteModelsModal , showSetTurnServerCredsModal } ;
19692234
19702235// Also keep the global for backward compatibility
19712236window . comfyStreamSettings = {
@@ -1976,5 +2241,6 @@ window.comfyStreamSettings = {
19762241 showDeleteNodesModal,
19772242 showToggleNodesModal,
19782243 showAddModelsModal,
1979- showDeleteModelsModal
2244+ showDeleteModelsModal,
2245+ showSetTurnServerCredsModal
19802246} ;
0 commit comments