Advertisement
MeKLiN2

tinychat webcam resolution script in progress

May 9th, 2022
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.86 KB | None | 0 0
  1. // ==UserScript==
  2. // @name meklin
  3. // @version 1.8.50
  4. // @description Modified TinyChat - Best Scripts; prepare to be amazed.
  5. // @author CosmosisT
  6. // @url https://gist.github.com/CosmosisT
  7. // @license Copyright (C) CosmosisT
  8. // @icon https://i.imgur.com/XlkFjOK.png
  9. // @match https://tinychat.com/room/*
  10. // @match https://tinychat.com/*
  11. // @exclude https://tinychat.com/settings/*
  12. // @exclude https://tinychat.com/subscription/*
  13. // @exclude https://tinychat.com/promote/*
  14. // @exclude https://tinychat.com/coins/*
  15. // @exclude https://tinychat.com/gifts*
  16. // @grant none
  17. // @run-at document-start
  18. // jshint esversion: 6
  19. // @namespace https://greasyfork.org/users/395685
  20. // ==/UserScript==
  21.  
  22. (function() {
  23. "use strict";
  24. //DEBUGGER
  25.  
  26. window.TinychatApp.BLL.MediaConnection.prototype.Close = function() {
  27. RTC(this);
  28. };
  29. window.TinychatApp.BLL.ChatRoom.prototype.sendPushForUnreadPrivateMessage = function() {};
  30. if (!CTS.Project.isTouchScreen) {
  31. window.TinychatApp.BLL.ChatRoom.prototype.BroadcastStart = function(a) {
  32. var b = this,
  33. d = this.settings.getSettings();
  34. if (d.video === null) {
  35. return void this.app.MediaSettings(() => {
  36. this.BroadcastStart();
  37. });
  38. }
  39. this.videolist.AddingVideoSelf(this.self_handle);
  40. var e = {};
  41. if (!navigator.mediaDevices || !navigator.mediaDevices.enumerateDevices) {
  42. e.audio = true;
  43. e.video = { width: { min: 960, max: 960 }, height: { min: 720, max: 720 }, frameRate: { min: 30, ideal: 30, max: 60 } };
  44. } else {
  45. navigator.mediaDevices.enumerateDevices().then(g => {
  46. var h = false;
  47. var len = g.length;
  48. for (var c = 0; c < len; c++) {
  49. if (g[c].kind === "videoinput") {
  50. if (e.video === void 0) e.video = {width: {min: 960,max: 960,height: {min: 720,max: 720},frameRate: {min: 30, ideal: 30,max: 60}};
  51. if (h) {
  52. d.video = g[c];
  53. h = false;
  54. this.settings.saveSettings(d);
  55. } else if (d.video === null) {
  56. d.video = g[c];
  57. this.settings.saveSettings(d);
  58. } else if (d.video !== null && typeof d.video == "object" && d.video.deviceId == g[c].deviceId && d.video.deviceId !== a) {
  59. e.video.deviceId = {exact: d.video.deviceId};
  60. } else if (d.video.deviceId === a) {
  61. h = true;
  62. }
  63. }
  64. if (g[c].kind === "audioinput") {
  65. if (e.audio === void 0) e.audio = {};
  66. if (d.audio !== null && typeof d.audio == "object" && d.audio.deviceId == g[c].deviceId) e.audio = {deviceId: {exact: d.audio.deviceId}};
  67. }
  68. }
  69. if (e.video !== null && d.video !== null && d.video.deviceId == b.id__miconly) delete e.video;
  70. let i = navigator.mediaDevices.getSupportedConstraints();
  71. for (let a in i) {
  72. if (i.hasOwnProperty(a) && "echoCancellation" == a && e.audio) e.audio[a] = this.settings.isAcousticEchoCancelation();
  73. }
  74. if (!(e.audio || e.video)) {
  75. b.onMediaFailedCallback(new Error("No media devices to start broadcast."));
  76. } else if ("https:" === location.protocol || this.app.isDebug()) {
  77. debug("BROADCAST", "Initiating Media...");
  78. var m = new window.TinychatApp.BLL.BroadcastProgressEvent(window.TinychatApp.BLL.BroadcastProgressEvent.MEDIA_START);
  79. this.EventBus.broadcast(window.TinychatApp.BLL.BroadcastProgressEvent.ID, m);
  80. b.mediaLastConstraints = e;
  81. navigator.mediaDevices.getUserMedia(e).then(m => {
  82. b.onMediaSuccessCallback(m);
  83. });
  84. }
  85. }).catch(er => {
  86. debug("CAMERA::ERROR", er);
  87. });
  88. }
  89. };
  90. }
  91. window.TinychatApp.BLL.Userlist.prototype.ignore = function(a) {
  92. var b = ((a.isUsername) ? a.username : a.nickname);
  93. if (this.isIgnored(a) || this.ignored.push(b)) {
  94. var c = new window.TinychatApp.BLL.IgnorelistUpdateUserEvent(a);
  95. this.EventBus.broadcast(window.TinychatApp.BLL.IgnorelistUpdateUserEvent.ID, c);
  96. this.app.showToast(b + " ignored successfully till they leave or you refresh!");
  97. if (!a.isUsername) {
  98. CTS.TempIgnoreNickList.push(b.toUpperCase());
  99. } else {
  100. CTS.TempIgnoreUserList.push(b.toUpperCase());
  101. }
  102. }
  103. };
  104. window.TinychatApp.BLL.Userlist.prototype.unignore = function(a) {
  105. var b = ((a.isUsername) ? a.username : a.nickname),
  106. index = this.ignored.indexOf(b);
  107. if (index != -1) this.ignored.splice(index, 1);
  108. if (!a.isUsername) {
  109. index = CTS.TempIgnoreNickList.indexOf(b.toUpperCase());
  110. if (index != -1) CTS.TempIgnoreNickList.splice(index, 1);
  111. } else {
  112. index = CTS.TempIgnoreUserList.indexOf(b.toUpperCase());
  113. if (index != -1) CTS.TempIgnoreUserList.splice(index, 1);
  114. }
  115. var e = new window.TinychatApp.BLL.IgnorelistUpdateUserEvent(a);
  116. this.EventBus.broadcast(window.TinychatApp.BLL.IgnorelistUpdateUserEvent.ID, e);
  117. this.app.showToast(a.username + " unignored");
  118. };
  119. if (CTS.StorageSupport) {
  120. window.TinychatApp.BLL.SettingsFeature.prototype.getSettings = function() {
  121. var A = this._get("tinychat_settings");
  122. try {
  123. A = Object.assign(new window.TinychatApp.DAL.SettingsEntity(), JSON.parse(A));
  124. } catch (E) {}
  125. if (A !== undefined) {
  126. CTS.enableSound = A.enableSound;
  127. if (CTS.enablePMs !== A.enablePMs) {
  128. CTS.enablePMs = A.enablePMs;
  129. PMShow();
  130. }
  131. }
  132. return ((void 0 == A || "object" !== typeof A) && (A = new window.TinychatApp.DAL.SettingsEntity()) || A);
  133. };
  134. }
  135. if (!CTS.Project.isTouchScreen) {
  136. window.TinychatApp.BLL.ChatRoom.prototype.prepareStream = function(a) {
  137. function b() {
  138. if (null == c.mediaStreamCanvas) {
  139. if (CTS.AnimationFrameWorker != undefined) {
  140. CTS.AnimationFrameWorker.terminate();
  141. CTS.AnimationFrameWorker = undefined;
  142. }
  143. CTS.Me.broadcasting = false;
  144. return;
  145. }
  146. d.clearRect(0, 0, c.mediaStreamCanvas.width, c.mediaStreamCanvas.height);
  147. var a = c.mediaStreamVideo.videoHeight,
  148. e = c.mediaStreamVideo.videoWidth;
  149. c.mediaStreamCanvas.width = e;
  150. c.mediaStreamCanvas.height = a;
  151. window.TinychatApp.BLL.VideoFilters.getFilter(CTS.MediaStreamFilter).apply(d, e, a);
  152. d.drawImage(c.mediaStreamVideo, 0, 0, e, a, 0, 0, c.mediaStreamCanvas.width, c.mediaStreamCanvas.height);
  153. }
  154. this.mediaStreamOrigin = a;
  155. this.mediaStreamVideo = document.createElement("video");
  156. this.mediaStreamVideo.srcObject = this.mediaStreamOrigin;
  157. this.mediaStreamVideo.pause();
  158. this.mediaStreamVideo.oncanplay = function() {
  159. CTS.Me.broadcasting = true;
  160. if (CTS.WorkersAllowed) {
  161. if (CTS.AnimationFrameWorker == undefined) {
  162. CTS.AnimationFrameWorker = new Worker(window.URL.createObjectURL(new Blob(["function Counter() {self.postMessage(\"0\");}setInterval(function(){Counter();}, 1e3/" + CTS.FPS + ");"])));
  163. CTS.AnimationFrameWorker.onmessage = function() {
  164. b();
  165. };
  166. }
  167. } else {
  168. requestAnimationFrame(b);
  169. }
  170. };
  171. this.mediaStreamVideo.autoplay = !0;
  172. this.mediaStreamVideo.muted = !0;
  173. this.mediaStreamCanvas = document.createElement("canvas");
  174. var c = this,
  175. d = this.mediaStreamCanvas.getContext("2d");
  176. this.mediaStreamVideo.play();
  177. var e = this.mediaStreamCanvas.captureStream(CTS.FPS);
  178. return (e.addTrack(this.mediaStreamOrigin.getAudioTracks()[0]) || e);
  179.  
  180. {
  181.  
  182. function RTC() {
  183. if (null != arguments[0].rtc) {
  184. let a = arguments[0].rtc;
  185. arguments[0].rtc = null;
  186. MS(arguments[0], a);
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement