套接字。io客户端库吗?

时间:2021-10-04 15:49:50

As far as I have seen, there is no explanation as to where we are to locate the client side script for socket.io if node.js is not used as the web server. I've found a whole directory of client side files, but I need them in a combined version (like it's served when using node.js webs servers). Any ideas?

就我所见,对于我们在何处定位套接字的客户端脚本没有任何解释。如果节点io。不使用js作为web服务器。我已经找到了整个客户端文件目录,但是我需要在一个合并的版本中使用它们(就像使用node时使用它一样)。js网服务器)。什么好主意吗?

8 个解决方案

#1


66  

socket.io.js is what you're going to put into your client-side html. Something like:

socket . io。js就是要放到客户端html中的东西。喜欢的东西:

<script type="text/javascript" src="socket.io.js"></script>

my script is located:

我的脚本位于:

/usr/local/lib/node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.js

copy that file to where you want your server to serve it.

将该文件复制到您希望服务器为其提供服务的位置。

#2


170  

The best way I have found to do this is to use bower.

我发现最好的办法就是使用凉亭。

bower install socket.io-client --save

and include the following in your app's HTML:

并在应用程序的HTML中包含以下内容:

<script src="/bower_components/socket.io-client/socket.io.js"></script>

That way you can treat the socket.io part of your client the same way you treat any other managed package.

这样你就可以处理插座了。您的客户机的io部分与您对待其他托管包的方式相同。

#3


25  

I think that better and proper way is to load it from this url

我认为更好和正确的方法是从这个url加载它。

src="/socket.io/socket.io.js" 

on the domain where socket.io runs. What is positive on this solution is that if you update your socket.io npm module, your client file gets updated too and you don't have to copy it every time manually.

在套接字所在的域中。io。这个解决方案的优点是如果您更新了套接字。io npm模块,你的客户端文件也会被更新,你不必每次都手动复制它。

#4


8  

I used bower as suggested in Matt Way's answer, and that worked great, but then the library itself didn't have its own bower.json file.

我按照马特·韦的回答使用了鲍尔,效果很好,但是图书馆本身并没有自己的鲍尔。json文件。

This meant that the bower-main-files Gulp plugin that I'm using to find my dependencies' JS files did not pull in socket.io, and I was getting an error on page load. Adding an override to my project's bower.json worked around the issue.

这意味着我用来查找依赖项的JS文件的bower-main-files Gulp插件没有拉入套接字。io,我在页面加载上出错了。为我的项目添加一个覆盖。json解决了这个问题。

First install the library with bower:

首先安装有凉亭的图书馆:

bower install socket.io-client --save

Then add the override to your project's bower.json:

然后将覆盖添加到项目的bower.json:

"overrides": {
  "socket.io-client": {
    "main": ["socket.io.js"]
  }
}

#5


6  

For everyone who runs wiredep and gets the "socket.io-client was not injected in your file." error:

对于每个运行wiredep并获得“socket”的人。您的文件中没有注入io-client。

Modify your wiredep task like this:

修改您的wiredep任务如下:

wiredep: {
  ..
  main: {
    ..
    overrides: {
      'socket.io-client': {
        main: 'socket.io.js'
      }
    }
  }

#6


2  

If you are using bower.json, add the socket.io-client dependency.

如果你用的是凉亭。json,添加插座。io-client依赖。

"socket.io-client": "0.9.x"

Then run bower install to download socket.io-client.

然后运行bower安装来下载socket.io-client。

Then add the script tag in your HTML.

然后在HTML中添加脚本标记。

<script src="bower_components/socket.io-client/dist/socket.io.min.js"></script>

#7


2  

I have created a bower compatible socket.io-client that can be install like this :

我已经创建了一个与鲍尔兼容的插座。可以这样安装的io-client:

bower install sio-client --save

or for development usage :

或用于开发用途:

bower install sio-client --save-dev

link to repo

链接到回购

#8


0  

if you use https://github.com/btford/angular-socket-io make sure to have your index.html like this:

如果您使用https://github.com/btford/angular-socket-io,请确保您的索引。html是这样的:

<!-- https://raw.githubusercontent.com/socketio/socket.io-client/master/socket.io.js -->
<script src="socket.io.js"></script>

<!-- build:js({client,node_modules}) app/vendor.js -->
<!-- bower:js -->
<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="bower_components/angular/angular.js"></script>
<!-- ...... -->
<script src="bower_components/angular-socket-io/socket.js"></script>
<!-- endbower -->
<!-- endbuild -->



<script type="text/javascript" charset="utf-8">
   angular.module('myapp', [
// ...    
'btford.socket-io'
]);

// do your angular/socket stuff
</script>

#1


66  

socket.io.js is what you're going to put into your client-side html. Something like:

socket . io。js就是要放到客户端html中的东西。喜欢的东西:

<script type="text/javascript" src="socket.io.js"></script>

my script is located:

我的脚本位于:

/usr/local/lib/node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.js

copy that file to where you want your server to serve it.

将该文件复制到您希望服务器为其提供服务的位置。

#2


170  

The best way I have found to do this is to use bower.

我发现最好的办法就是使用凉亭。

bower install socket.io-client --save

and include the following in your app's HTML:

并在应用程序的HTML中包含以下内容:

<script src="/bower_components/socket.io-client/socket.io.js"></script>

That way you can treat the socket.io part of your client the same way you treat any other managed package.

这样你就可以处理插座了。您的客户机的io部分与您对待其他托管包的方式相同。

#3


25  

I think that better and proper way is to load it from this url

我认为更好和正确的方法是从这个url加载它。

src="/socket.io/socket.io.js" 

on the domain where socket.io runs. What is positive on this solution is that if you update your socket.io npm module, your client file gets updated too and you don't have to copy it every time manually.

在套接字所在的域中。io。这个解决方案的优点是如果您更新了套接字。io npm模块,你的客户端文件也会被更新,你不必每次都手动复制它。

#4


8  

I used bower as suggested in Matt Way's answer, and that worked great, but then the library itself didn't have its own bower.json file.

我按照马特·韦的回答使用了鲍尔,效果很好,但是图书馆本身并没有自己的鲍尔。json文件。

This meant that the bower-main-files Gulp plugin that I'm using to find my dependencies' JS files did not pull in socket.io, and I was getting an error on page load. Adding an override to my project's bower.json worked around the issue.

这意味着我用来查找依赖项的JS文件的bower-main-files Gulp插件没有拉入套接字。io,我在页面加载上出错了。为我的项目添加一个覆盖。json解决了这个问题。

First install the library with bower:

首先安装有凉亭的图书馆:

bower install socket.io-client --save

Then add the override to your project's bower.json:

然后将覆盖添加到项目的bower.json:

"overrides": {
  "socket.io-client": {
    "main": ["socket.io.js"]
  }
}

#5


6  

For everyone who runs wiredep and gets the "socket.io-client was not injected in your file." error:

对于每个运行wiredep并获得“socket”的人。您的文件中没有注入io-client。

Modify your wiredep task like this:

修改您的wiredep任务如下:

wiredep: {
  ..
  main: {
    ..
    overrides: {
      'socket.io-client': {
        main: 'socket.io.js'
      }
    }
  }

#6


2  

If you are using bower.json, add the socket.io-client dependency.

如果你用的是凉亭。json,添加插座。io-client依赖。

"socket.io-client": "0.9.x"

Then run bower install to download socket.io-client.

然后运行bower安装来下载socket.io-client。

Then add the script tag in your HTML.

然后在HTML中添加脚本标记。

<script src="bower_components/socket.io-client/dist/socket.io.min.js"></script>

#7


2  

I have created a bower compatible socket.io-client that can be install like this :

我已经创建了一个与鲍尔兼容的插座。可以这样安装的io-client:

bower install sio-client --save

or for development usage :

或用于开发用途:

bower install sio-client --save-dev

link to repo

链接到回购

#8


0  

if you use https://github.com/btford/angular-socket-io make sure to have your index.html like this:

如果您使用https://github.com/btford/angular-socket-io,请确保您的索引。html是这样的:

<!-- https://raw.githubusercontent.com/socketio/socket.io-client/master/socket.io.js -->
<script src="socket.io.js"></script>

<!-- build:js({client,node_modules}) app/vendor.js -->
<!-- bower:js -->
<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="bower_components/angular/angular.js"></script>
<!-- ...... -->
<script src="bower_components/angular-socket-io/socket.js"></script>
<!-- endbower -->
<!-- endbuild -->



<script type="text/javascript" charset="utf-8">
   angular.module('myapp', [
// ...    
'btford.socket-io'
]);

// do your angular/socket stuff
</script>