3

I am currently working with Ember.js using the Ember-CLI. The application uses ES6 modules to import the required functions to each "module".

I am going to use web sockets to connect to the API and I would like to find some examples of how to import socket.io as a ES6 module.

JonathanBristow
  • 1,066
  • 2
  • 13
  • 36

3 Answers3

0

Try to app.import it in your Brocfile, then export default window.socketio

John
  • 706
  • 2
  • 10
  • 16
  • 2
    Would you mind elaborating? Where does one put the "export default window.socketio"? – Timm Feb 16 '15 at 12:16
  • I am assuming that this is intended to be done using Ember.js' 'app.import' function. If you do this inside a js file in your source that represents the 'socket.io-client' module, then you would 'export default' from that. This would give you a nice interface for socket.io-client where you can import it as through it were of your files. ** Assume ** – Lawrence_NT Jun 23 '19 at 01:37
0
  1. Get socket.io-client by bower

    bower install socket.io-client

  2. import the library as 'io':

Example:

import * as io from 'socket.io-client';

const socket = io.connect('http://localhost');
socket.on('connect', function (data) {
  console.log('Connected!');
  socket.emit('message', {message:"Hello!"});
});
Oleg Imanilov
  • 2,591
  • 1
  • 13
  • 26
0

I found a solution here: How to use Socket.io with Next.js, Express...

import * as socketio from 'socket.io';
const io = new socketio.Server();
io.attach(server);
Hendrik Jan
  • 4,396
  • 8
  • 39
  • 75