Skip to content
Open

Dev #664

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/SnapDrop.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 35 additions & 35 deletions client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,34 +57,34 @@
<!-- Peers -->
<x-peers class="center"></x-peers>
<x-no-peers>
<h2>Open Snapdrop on other devices to send files</h2>
<h2>在其他设备上打开Snapdrop以发送文件</h2>
</x-no-peers>
<x-instructions desktop="Click to send files or right click to send a message" mobile="Tap to send files or long tap to send a message"></x-instructions>
<x-instructions desktop="点击发送文件或右键发送消息" mobile="轻触发送文件或长按发送消息"></x-instructions>
<!-- Footer -->
<footer class="column">
<svg class="icon logo">
<use xlink:href="#wifi-tethering" />
</svg>
<div id="displayName" placeholder="The easiest way to transfer data across devices"></div>
<div class="font-body2">You can be discovered by everyone on this network</div>
<div id="displayName" placeholder="在设备间传输文件的最简单方法"></div>
<div class="font-body2">您可以被此网络上的每个人发现</div>
</footer>
<!-- Receive Dialog -->
<x-dialog id="receiveDialog">
<x-background class="full center">
<x-paper shadow="2">
<h3>File Received</h3>
<div class="font-subheading" id="fileName">Filename</div>
<h3>文件已接收</h3>
<div class="font-subheading" id="fileName">文件名</div>
<div class="font-body2" id="fileSize"></div>
<div class='preview' style="visibility: hidden;">
<img id='img-preview' src="">
</div>
<div class="row">
<label for="autoDownload" class="grow">Ask to save each file before downloading</label>
<label for="autoDownload" class="grow">全选所有</label>
<input type="checkbox" id="autoDownload" checked="">
</div>
<div class="row-reverse">
<a class="button" close id="download" title="Download File" autofocus>Save</a>
<button class="button" close>Ignore</button>
<a class="button" close id="download" title="Download File" autofocus>保存</a>
<button class="button" close>忽视</button>
</div>
</x-paper>
</x-background>
Expand All @@ -94,11 +94,11 @@ <h3>File Received</h3>
<form action="#">
<x-background class="full center">
<x-paper shadow="2">
<h3>Send a Message</h3>
<div id="textInput" class="textarea" role="textbox" placeholder="Send a message" autocomplete="off" autofocus contenteditable></div>
<h3>发送信息</h3>
<div id="textInput" class="textarea" role="textbox" placeholder="发送消息" autocomplete="off" autofocus contenteditable></div>
<div class="row-reverse">
<button class="button" type="submit" close>Send</button>
<a class="button" close>Cancel</a>
<button class="button" type="submit" close>发送</button>
<a class="button" close>取消</a>
</div>
</x-paper>
</x-background>
Expand All @@ -108,18 +108,18 @@ <h3>Send a Message</h3>
<x-dialog id="receiveTextDialog">
<x-background class="full center">
<x-paper shadow="2">
<h3>Message Received</h3>
<h3>已收到消息</h3>
<div class="font-subheading" id="text"></div>
<div class="row-reverse">
<button class="button" id="copy" close autofocus>Copy</button>
<button class="button" close>Close</button>
<button class="button" id="copy" close autofocus>复制</button>
<button class="button" close>关闭</button>
</div>
</x-paper>
</x-background>
</x-dialog>
<!-- Toast -->
<div class="toast-container full center">
<x-toast class="row" shadow="1" id="toast">File Transfer Completed</x-toast>
<x-toast class="row" shadow="1" id="toast">文件传输完成!</x-toast>
</div>
<!-- About Page -->
<x-about id="about" class="full center column">
Expand All @@ -135,28 +135,28 @@ <h3>Message Received</h3>
<use xlink:href="#wifi-tethering" />
</svg>
<h1>Snapdrop</h1>
<div class="font-subheading">The easiest way to transfer files across devices</div>
<div class="font-subheading">在设备间传输文件的最简单方法</div>
<div class="row">
<a class="icon-button" target="_blank" href="https://github.com/RobinLinus/snapdrop" title="Snapdrop on Github" rel="noreferrer">
<svg class="icon">
<use xlink:href="#github" />
</svg>
</a>
<a class="icon-button" target="_blank" href="https://www.paypal.com/donate?hosted_button_id=FTP9DXUR7LA7Q" title="Help cover the server costs!" rel="noreferrer">
<svg class="icon">
<use xlink:href="#monetarization" />
</svg>
</a>
<a class="icon-button" target="_blank" href="https://twitter.com/intent/tweet?text=https://snapdrop.net%20by%20@robin_linus%20&" title="Tweet about Snapdrop" rel="noreferrer">
<svg class="icon">
<use xlink:href="#twitter" />
</svg>
</a>
<a class="icon-button" target="_blank" href="https://github.com/RobinLinus/snapdrop/blob/master/docs/faq.md" title="Frequently asked questions" rel="noreferrer">
<svg class="icon">
<use xlink:href="#help-outline" />
</svg>
</a>
<!--<a class="icon-button" target="_blank" href="https://www.paypal.com/donate?hosted_button_id=FTP9DXUR7LA7Q" title="Help cover the server costs!" rel="noreferrer">-->
<!-- <svg class="icon">-->
<!-- <use xlink:href="#monetarization" />-->
<!-- </svg>-->
<!--</a>-->
<!--<a class="icon-button" target="_blank" href="https://twitter.com/intent/tweet?text=https://snapdrop.net%20by%20@robin_linus%20&" title="Tweet about Snapdrop" rel="noreferrer">-->
<!-- <svg class="icon">-->
<!-- <use xlink:href="#twitter" />-->
<!-- </svg>-->
<!--</a>-->
<!--<a class="icon-button" target="_blank" href="https://github.com/RobinLinus/snapdrop/blob/master/docs/faq.md" title="Frequently asked questions" rel="noreferrer">-->
<!-- <svg class="icon">-->
<!-- <use xlink:href="#help-outline" />-->
<!-- </svg>-->
<!--</a>-->
</div>
</section>
<x-background></x-background>
Expand Down Expand Up @@ -215,8 +215,8 @@ <h1>Snapdrop</h1>
<!-- no script -->
<noscript>
<x-noscript class="full center column">
<h1>Enable JavaScript</h1>
<h3>Snapdrop works only with JavaScript</h3>
<h1>启用 JS</h1>
<h3>Snardrep 只能使用 JavaScript</h3>
</x-noscript>
<style>
x-noscript {
Expand Down
6 changes: 6 additions & 0 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 18 additions & 8 deletions client/scripts/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ window.isRtcSupported = !!(window.RTCPeerConnection || window.mozRTCPeerConnecti
class ServerConnection {

constructor() {
// 添加:从 localStorage 获取自定义服务器地址和端口
this.serverHost = localStorage.getItem('serverHost') || 'localhost';
this.serverPort = localStorage.getItem('serverPort') || '1234';


this._connect();
Events.on('beforeunload', e => this._disconnect());
Events.on('pagehide', e => this._disconnect());
Expand Down Expand Up @@ -54,12 +59,17 @@ class ServerConnection {
this._socket.send(JSON.stringify(message));
}

//_endpoint() {
// // hack to detect if deployment or development environment
// const protocol = location.protocol.startsWith('https') ? 'wss' : 'ws';
// const webrtc = window.isRtcSupported ? '/webrtc' : '/fallback';
// const url = protocol + '://' + location.host + location.pathname + 'server' + webrtc;
// return url;
//}
_endpoint() {
// hack to detect if deployment or development environment
const protocol = location.protocol.startsWith('https') ? 'wss' : 'ws';
const webrtc = window.isRtcSupported ? '/webrtc' : '/fallback';
const url = protocol + '://' + location.host + location.pathname + 'server' + webrtc;
return url;
return `${protocol}://${this.serverHost}:${this.serverPort}${webrtc}`;
}

_disconnect() {
Expand All @@ -70,7 +80,7 @@ class ServerConnection {

_onDisconnect() {
console.log('WS: server disconnected');
Events.fire('notify-user', 'Connection lost. Retry in 5 seconds...');
Events.fire('notify-user', '连接丢失! 5 秒后重试...');
clearTimeout(this._reconnectTimer);
this._reconnectTimer = setTimeout(_ => this._connect(), 5000);
}
Expand Down Expand Up @@ -187,12 +197,12 @@ class Peer {

_onChunkReceived(chunk) {
if(!chunk.byteLength) return;

this._digester.unchunk(chunk);
const progress = this._digester.progress;
this._onDownloadProgress(progress);

// occasionally notify sender about our progress
// occasionally notify sender about our progress
if (progress - this._lastProgress < 0.01) return;
this._lastProgress = progress;
this._sendProgress(progress);
Expand All @@ -212,7 +222,7 @@ class Peer {
this._reader = null;
this._busy = false;
this._dequeueFile();
Events.fire('notify-user', 'File transfer completed.');
Events.fire('notify-user', '文件传输已完成。');
}

sendText(text) {
Expand Down Expand Up @@ -254,7 +264,7 @@ class RTCPeer extends Peer {
}

_openChannel() {
const channel = this._conn.createDataChannel('data-channel', {
const channel = this._conn.createDataChannel('data-channel', {
ordered: true,
reliable: true // Obsolete. See https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel/reliable
});
Expand Down
34 changes: 16 additions & 18 deletions client/scripts/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ window.iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
Events.on('display-name', e => {
const me = e.detail.message;
const $displayName = $('displayName')
$displayName.textContent = 'You are known as ' + me.displayName;
$displayName.textContent = '你的设备名称为: ' + me.displayName;
$displayName.title = me.deviceName;
});

Expand Down Expand Up @@ -74,7 +74,7 @@ class PeerUI {

html() {
return `
<label class="column center" title="Click to send files or right click to send a text">
<label class="column center" title="单击发送文件或右键单击发送文本">
<input type="file" multiple>
<x-icon shadow="1">
<svg class="icon"><use xlink:href="#"/></svg>
Expand Down Expand Up @@ -375,7 +375,7 @@ class ReceiveTextDialog extends Dialog {

async _onCopy() {
await navigator.clipboard.writeText(this.$text.textContent);
Events.fire('notify-user', 'Copied to clipboard');
Events.fire('notify-user', '复制到剪贴板!');
}
}

Expand Down Expand Up @@ -415,7 +415,7 @@ class Notifications {
Events.fire('notify-user', Notifications.PERMISSION_ERROR || 'Error');
return;
}
this._notify('Even more snappy sharing!');
this._notify('更快速的分享!');
this.$button.setAttribute('hidden', 1);
});
}
Expand All @@ -435,12 +435,12 @@ class Notifications {
}

// Notification is persistent on Android. We have to close it manually
const visibilitychangeHandler = () => {
if (document.visibilityState === 'visible') {
const visibilitychangeHandler = () => {
if (document.visibilityState === 'visible') {
notification.close();
Events.off('visibilitychange', visibilitychangeHandler);
}
};
}
};
Events.on('visibilitychange', visibilitychangeHandler);

return notification;
Expand All @@ -449,18 +449,18 @@ class Notifications {
_messageNotification(message) {
if (document.visibilityState !== 'visible') {
if (isURL(message)) {
const notification = this._notify(message, 'Click to open link');
const notification = this._notify(message, '点击打开链接');
this._bind(notification, e => window.open(message, '_blank', null, true));
} else {
const notification = this._notify(message, 'Click to copy text');
const notification = this._notify(message, '点击复制文本');
this._bind(notification, e => this._copyText(message, notification));
}
}
}

_downloadNotification(message) {
if (document.visibilityState !== 'visible') {
const notification = this._notify(message, 'Click to download');
const notification = this._notify(message, '点击下载');
if (!window.isDownloadSupported) return;
this._bind(notification, e => this._download(notification));
}
Expand Down Expand Up @@ -498,11 +498,11 @@ class NetworkStatusUI {
}

_showOfflineMessage() {
Events.fire('notify-user', 'You are offline');
Events.fire('notify-user', '您掉线了');
}

_showOnlineMessage() {
Events.fire('notify-user', 'You are back online');
Events.fire('notify-user', '您已重新连接');
}
}

Expand Down Expand Up @@ -550,7 +550,7 @@ const snapdrop = new Snapdrop();
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('service-worker.js')
.then(serviceWorker => {
console.log('Service Worker registered');
console.log('服务人员已注册');
window.serviceWorker = serviceWorker
});
}
Expand Down Expand Up @@ -632,10 +632,8 @@ Events.on('load', () => {
});

Notifications.PERMISSION_ERROR = `
Notifications permission has been blocked
as the user has dismissed the permission prompt several times.
This can be reset in Page Info
which can be accessed by clicking the lock icon next to the URL.`;
由于用户多次忽略权限提示,通知权限已被阻止。
您可以在页面信息中重置此权限,点击 URL 旁边的锁形图标即可访问。`;

document.body.onclick = e => { // safari hack to fix audio
document.body.onclick = null;
Expand Down
Loading